After throwing out a lot of food when the freezer in my garage got left open by a child helping himself to an Otter Pop, I decided I needed an automated solution and purchased a door sensor for the freezer.
I wanted to get an alert on my mobile phone when the door had been left open for 5 minutes. Importantly, I did not want to be notified everytime the door opened - only when left open for 5 minutes. I use Vera Alert for my notifications due to the speed, but I have also used SMTP code to send SMS messages to my phone.
I had tried following the examples used in the thread about turning an AC system off after a door had been open 5 minutes. But I found that having everything in one scene didn’t work - alerts were sent instantaneously. It appears that when you use luup.call_timer it returns a 0 for success after it has SCHEDULED the function to run, not after the function has actually run. Other approaches use a function that always runs every 5 minutes - I wanted a test running only after the door had been opened.
After some experimentation, I settled on an approach that uses two scenes.
The first scene is triggered when the door is opened (called Freezer Door Opened). I used the standard event and I added this luup code for the command:
[i]function callscene()
luup.call_action(“urn:micasaverde-com:serviceId:HomeAutomationGateway1”, “RunScene”, { SceneNum=“21” }, 0)
end
luup.call_timer(“callscene”, 1, “5m”, “”, “”)[/i]
This tells Vera to run scene 21 in 5 minutes. Scene 21 is called Freezer Door Left Open. It checks to see if the door is still open, and if so, sends an alert via Vera Alert using a standard command structure. Here is the luup code that checks if the door is still open:
if (luup.variable_get(“urn:micasaverde-com:serviceId:SecuritySensor1”, “Tripped”, 34) == “1” ) then
return true
else
return false
end
If you wanted to send an email instead, you would just add the SMTP code where “return true” is.
Now technically, this doesn’t check to see if the door has remained open continuously for 5 minutes. If someone opened and closed the door, and then 5 minutes later opened it again, I could get a false positive if the timing was just right. But it was good enough for me.
I have used this same structure to check my garage door. When I lock the deadbolt on the door from the garage to the house, it triggers my “Leave Home” script that turns off all the lights and locks all the other doors. I added a 2 minute delay to check if the garage door was still open. If it’s still open 2 minutes after I locked the deadbolt, it means I drove off without closing the garage door and my phone will alert me before I get too far away. (My next project will to be allow me to remotely close my garage door so I don’t have to drive back).