I’m trying to setup a luup scene or the like to send out an email if the door stays unlocked for X minutes. I then want to send another email if the door get’s relocked only after the unlock email is sent out. So it would look something like this:
-
Unlock door
Wait 30 seconds
Lock door
------ No Message ----- -
Unlock door
wait 2 minutes
------- Message ------
wait 2 minutes
lock door
------- Message ------
Here’s what I have for the code, but it seems to be hit and miss. I get random unlock messages durring the day, and the relocks only sometimes work. I have two locks, and a virtual switch that I use as the “I’ve sent a message” variable, and the trigger to do the notificaiton, so I don’t have to do that in code. I’m thinking part of my problem is that when the X minutes is up, the device may have been relocked, but not polled yet…
BTW, I’m also turning on a light if any of the doors are unlocked, so I can easily see if I’m all locked up.
[code]local FRONT_DOOR = luup.variable_get(“urn:micasaverde-com:serviceId:DoorLock1”, “Status”, 31)
local BACK_DOOR = luup.variable_get(“urn:micasaverde-com:serviceId:DoorLock1”, “Status”, 101)
local LIGHT_STATUS = 100
luup.log("Front Door " … FRONT_DOOR … " Back Door " … BACK_DOOR)
if ((FRONT_DOOR == “1”) and (BACK_DOOR == “1”)) then
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”, “SetTarget”, {newTargetValue = “0”}, LIGHT_STATUS )
else
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”, “SetTarget”, {newTargetValue = “1”}, LIGHT_STATUS )
luup.call_delay(“SendUnlockMessage”, 90, “”)
end
function SendUnlockMessage()
local DOOR_EMAIL = luup.variable_get(“urn:upnp-org:serviceId:SwitchPower1”, “Status”, 102)
local FRONT_DOOR_POLL = luup.call_action(“urn:micasaverde-com:serviceId:HaDevice1”, “Poll”, {}, 31)
local BACK_DOOR_POLL = luup.call_action(“urn:micasaverde-com:serviceId:HaDevice1”, “Poll”, {}, 101)
local VIRTUAL_SWITCH = 102
if ((FRONT_DOOR == "1") and (BACK_DOOR == "1")) then
luup.call_action("urn:upnp-org:serviceId:SwitchPower1", "SetTarget", {newTargetValue = "1"}, VIRTUAL_SWITCH)
else
luup.call_action("urn:upnp-org:serviceId:SwitchPower1", "SetTarget", {newTargetValue = "0"}, VIRTUAL_SWITCH)
end
end[/code]