Delayed Notification Script
Posted: Thursday 11 January 2018 19:10
Hi,
I've used the script on the wiki and adjusted it slightly with the aim of sending a notification if the fridge door is open for two minutes.
The fridge door is connected via a Fibaro Universal Sensor to my z-wave network. Whilst the switch status changed the last seen time doesn't.
Because of this I am using variables in the script - Log is showing no errors but the script isn't doing anything that I can see, no variable updates or notifications.
I'm open to using dzVents rather than old Lua if it would be simpler.
Any help would be appreciated
Thanks
I've used the script on the wiki and adjusted it slightly with the aim of sending a notification if the fridge door is open for two minutes.
The fridge door is connected via a Fibaro Universal Sensor to my z-wave network. Whilst the switch status changed the last seen time doesn't.
Because of this I am using variables in the script - Log is showing no errors but the script isn't doing anything that I can see, no variable updates or notifications.
I'm open to using dzVents rather than old Lua if it would be simpler.
Any help would be appreciated
Code: Select all
function timedifference(s)
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)
t1 = os.time()
t2 = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
difference = os.difftime (t1, t2)
return difference
end
commandArray = {}
if (otherdevices['Fridge Door'] == 'Open' and uservariables['fridgedooropen']) == '0' then
commandArray['Variable:fridgedooropen'] = '1'
elseif (otherdevices['Fridge Door']) == 'Closed' then
commandArray['Variable:fridgedooropen'] = '0'
end
if (uservariables['fridgedooropen'] == '1' and uservariables['fridgedooralert'] == '0' and timedifference(uservariables_lastupdate['fridgedooropen']) > 120) then
commandArray['SendNotification']='Fridge Open for more than 2 minutes'
commandArray['Variable:fridgedooralert'] = '1'
elseif (uservariables['fridgedooropen'] == '0' and uservariables['fridgedooralert']) == '1' then
commandArray['Variable:fridgedooralert'] = '0'
end
return commandArray