Page 1 of 1

Period of time between LUA script executions

Posted: Saturday 24 August 2019 17:56
by mackowiakp
I am new in LUA programming, so my question. Below is a little script to light LED on if entrace gate are open and tun it off when closed. As I understand, Domoticz runs such script every minute. That is what I want. Its because it sends WGET command each minute, it restore status of LED in case of power failure or other problems. RPi on which Domoticz is installed has UPS but remote unis (easyESP) where I send WGET - no.
I am right or not?

Code: Select all

local sensor = 'Brama - status'
t1 = os.time()
s = otherdevices_lastupdate[sensor]

year = string.sub(s, 1, 4)
month = string.sub(s, 6, 7)
day = string.sub(s, 9, 10)
hour = string.sub(s, 12, 13)
minutes = string.sub(s, 15, 16)
seconds = string.sub(s, 18, 19)

commandArray = {}

t2 = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
difference = (os.difftime (t1, t2))
--
-- wlaczenie LED jezeli brama otwarta dluzej niz 25 min
if (otherdevices[sensor] == 'Open' and difference > 1500 and difference < 99999) then
os.execute ("/usr/bin/wget -q -O - http://192.168.0.29/control?cmd=event,LED_on")
-- elseif (devicechanged[sensor] == 'Closed') then
elseif (otherdevices[sensor] == 'Closed' and difference > 1 and difference < 99999) then
os.execute ("/usr/bin/wget -q -O - http://192.168.0.29/control?cmd=event,LED_off")
end

return commandArray

Re: Period of time between LUA script executions

Posted: Saturday 24 August 2019 23:08
by waaren
mackowiakp wrote: Saturday 24 August 2019 17:56 As I understand, Domoticz runs such script every minute. That is what I want.
I am right or not?
If you have saved your Lua script as time based, it will be executed every minute.

Re: Period of time between LUA script executions

Posted: Sunday 25 August 2019 10:02
by mackowiakp
If you have saved your Lua script as time based, it will be executed every minute.
As I wrote, I am new in LUA. Be so kind to explain what does it mean "save LUA script as time based"

Re: Period of time between LUA script executions

Posted: Sunday 25 August 2019 10:21
by waaren

mackowiakp wrote:
As I wrote, I am new in LUA. Be so kind to explain what does it mean "save LUA script as time based"
If you use the domoticz internal event editor and choose Lua, you are offered options on how to open/save the script. One of the options is time.





Re: Period of time between LUA script executions

Posted: Sunday 25 August 2019 10:30
by mackowiakp
THX !