is there a way to check if a switch has been on for over 30 seconds and after that send a message? Sounds pretty simple but I can't figure it out

Moderator: leecollings
Code: Select all
-- script_time_dooropen.lua
t1 = os.time()
s = otherdevices_lastupdate['Sensor - Voordeur']
-- returns a date time like 2013-07-11 17:23:12
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))
if (otherdevices['Sensor - Voordeur'] == 'Open' and difference > 300 and difference < 600) then
commandArray['SendNotification']='Voordeur melding#Voordeur staat langer dan 5 minuten open!'
print("Voordeur open")
end
return commandArray
Users browsing this forum: No registered users and 1 guest