Period of time between LUA script executions Topic is solved

Moderator: leecollings

Post Reply
mackowiakp
Posts: 18
Joined: Friday 21 July 2017 19:26
Target OS: Linux
Domoticz version:
Contact:

Period of time between LUA script executions

Post 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
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Period of time between LUA script executions

Post 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.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
mackowiakp
Posts: 18
Joined: Friday 21 July 2017 19:26
Target OS: Linux
Domoticz version:
Contact:

Re: Period of time between LUA script executions

Post 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"
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Period of time between LUA script executions

Post 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.




Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
mackowiakp
Posts: 18
Joined: Friday 21 July 2017 19:26
Target OS: Linux
Domoticz version:
Contact:

Re: Period of time between LUA script executions

Post by mackowiakp »

THX !
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest