Below is a simple script i have created to detect if my garage door is open. It only progresses to the 'if' statements when the time is after 20:00 every 15 minutes.
this bit works fine..
I would now like to track how many times it is continuously open, then if it is open for lets say 4 times (ie an hour) then send a different notification.
I have set the variable 'timesopen' to "0" and then I increment this by 1 each time it detects it is open.
the problem is... if i leave it open it always prints the value 1 to my logs... is there a way to stop it from re-setting the value to 0 at the start of the script?
Code: Select all
time = os.date("*t") -- put the time/date table in variable time
timesopen = 0
commandArray = {}
if (time.hour >=20) and (time.min==0 or time.min==15 or time.min==30 or time.min==45) then
if (otherdevices['ZB-Garage Sensor'] == 'Open')
commandArray['SendNotification']='Garage Door#Close Garage Door#0#sound#extradata#telegram'
timesopen = timesopen+1
print ('Door has been open: ' .. timesopen ..' times')
end
if (otherdevices['ZB-Garage Sensor'] == 'Closed') then
count = timesopen=0
end
end
return commandArray
Many thanks in advance
Andy