I have a problem and if there is someone to help.
I want to control the temperature in a refrigerator and if it exceeds 5 degrees for more than 5 minutes to send a notification.
The script below works well only before the first minute because tempsensor_1 refreshes every 1 minute and if I put more time on "difference" it does not work.
It would be possible to measure for example after the last 10 updates of tempsensor_1 and then triggered the script ?? Or some other way ?
Thank you in advance..
Code: Select all
t1 = os.time()
s = otherdevices_lastupdate['tempsensor_1']
-- 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['tempsensor_1'] > '4' and difference > 56 and difference < 70) then
commandArray['SendNotification']='Tempsensor_1 is above 4 degrees for more than 5 minutes!'
end
return commandArray