Page 1 of 1
Lua script to run a php page
Posted: Friday 13 November 2015 10:49
by miel
Ok, i am trying to run a Lua script which runs a certain php page as soon as a switch is marked as "on"
I have written this code:
Code: Select all
--[[
This script runs a php page when a certain switch is "on"
--]]
commandArray = {}
-- declare some constants
-- adjust to your specific situation
SENSOR_NAME = 'Beweging badkamer' -- exact device name of the motion sensor
if (otherdevices[SENSOR_NAME]=='On' ) then
http.request_batch({
{"GET", "http://192.168.1.82/~Miel/HWtemp.php"}
})
end
return commandArray
What i see in my log is that this script is not run...... I don't see the mistake.... Any clues?
(Reason for using this script is that i would like my temperature sensors from Homewizard to send updates to Domoticz... if i do that every minute, it will lead to slow performance of my Homewizard..... I run Domoticz on a Synology Nas).
Re: Lua script to run a php page
Posted: Friday 13 November 2015 10:57
by Egregius
Why not run the PHP script by cron every x minutes?
Re: Lua script to run a php page
Posted: Friday 13 November 2015 11:01
by miel
Egregius wrote:Why not run the PHP script by cron every x minutes?
Because of performance.....
My Homewizard gets really slow when i run that php job every minute.......
Re: Lua script to run a php page
Posted: Friday 13 November 2015 13:38
by jvdz
What is the name of this script to determine on which event is should fire?
Do you really want to run the PHP page each time the script gets fired and the switch is on or only when it changes to on?
Jos
Re: Lua script to run a php page
Posted: Friday 13 November 2015 13:41
by miel
jvdz wrote:What is the name of this script to determine on which event is should fire?
Do you really want to run the PHP page each time the script gets fired and the switch is on or only when it changes to on?
Jos
Jos, the script is named script_run_php.lua
And yes, i really want to run this script every minute, so that every minute the PHP file gets called as long as the motion sensor is "on"... If the sensor is "Off", it should just do nothing...
(so that i can do humidity control in my bathroom).
Re: Lua script to run a php page
Posted: Friday 13 November 2015 13:57
by pj-r
miel wrote:Jos, the script is named script_run_php.lua
The lua scripts folder has two demo scripts that can serve as a starting point. The script filename has 3 components each sub-divided by an underscore : script_trigger_name.lua Trigger can be 'time', 'device', 'variable' or 'security', name can be any string for your reference, script_device_MyOtherDeviceNameOnWhenMyDeviceNameOn.lua for instance.
https://www.domoticz.com/wiki/Events#2. ... on_folder.
Re: Lua script to run a php page
Posted: Friday 13 November 2015 14:02
by jvdz
so, just rename it to " script_time_run_php.lua" and you are all set.
Jos
Re: Lua script to run a php page
Posted: Friday 13 November 2015 15:13
by miel
Ok script runs now, but i get the following error:
Error: /usr/local/domoticz/scripts/lua/script_time_run_php.lua:19: attempt to index global 'http' (a nil value)
That is the http request line..... Weird...
Re: Lua script to run a php page
Posted: Friday 13 November 2015 15:19
by jvdz
Do you have the HTTP addon loaded somewhere in your script with something like this:?
Jos
Re: Lua script to run a php page
Posted: Friday 13 November 2015 17:32
by miel
jvdz wrote:Do you have the HTTP addon loaded somewhere in your script with something like this:?
Jos
No,
The entire script i have copied/paste is in my opening message... So i should enter these lines in as well??
Re: Lua script to run a php page
Posted: Friday 13 November 2015 17:59
by jvdz
You will need something to define the http.xxxx function as that is not a standard available LUA command/
Where did you find this command?
I am using http.request(url) myself which is part of the library I refereed to in my previous post. This one is an add on which is made available in the DTGBOT project. (
https://www.domoticz.com/wiki/Remote_Co ... _Libraries )
Jos
Re: Lua script to run a php page
Posted: Friday 13 November 2015 18:18
by miel
jvdz wrote:You will need something to define the http.xxxx function as that is not a standard available LUA command/
Where did you find this command?
I am using http.request(url) myself which is part of the library I refereed to in my previous post. This one is an add on which is made available in the DTGBOT project. (
https://www.domoticz.com/wiki/Remote_Co ... _Libraries )
Jos
i found it in a wiki.....
DTGBOT, should i install that on my synology as well?
Re: Lua script to run a php page
Posted: Friday 13 November 2015 18:21
by jvdz
I am just talking about the linked support libraries, not the whole DTGBOT.
Doesn't the Wiki page tell you the prerequisites that needs to be installed?
Jos
Re: Lua script to run a php page
Posted: Friday 13 November 2015 18:33
by miel
jvdz wrote:I am just talking about the linked support libraries, not the whole DTGBOT.
Doesn't the Wiki page tell you the prerequisites that needs to be installed?
Jos
unfortunately not...
Is there no standard HTTP command in Lua? (Without having to load libraries?)
Re: Lua script to run a php page
Posted: Friday 13 November 2015 19:38
by G3rard
I use the following command in LUA to run a PHP page.
Code: Select all
os.execute('curl --url "http://ip/page.php"')
Re: Lua script to run a php page
Posted: Friday 13 November 2015 23:18
by miel
It is working!
Thanks!!!
Re: Lua script to run a php page
Posted: Saturday 14 November 2015 5:54
by Egregius
Great, I was just about to write you a php script that would only query the HW when the switch was on in domoticz.
Anyway, I am wondering what you ask the HW to get him really slow. I used to query him every 15sec.
Re: Lua script to run a php page
Posted: Saturday 14 November 2015 9:48
by miel
Every 15 seconds??? I just used a simple php to get the status of 5 thermometers..
I noticed the homewizard was often "not available" after i ran the php..
Which php script do you use?
Re: Lua script to run a php page
Posted: Saturday 14 November 2015 9:58
by Egregius
PHP Floorplan

There's also a part to import data from homewizard into Domoticz in secure/hw2domoticz.php
The every 15 sec was before I had domoticz and 'everything' was controlled by HW.
Even on the very last use of my HW I often get not available messages, even with only one thermometer and a reading every 2 minutes to domoticz.