Hi everyone, I have a zwave wall switch that turns on a light. I also have a D/W sensor on a door nearby. I have created an scene that; when the D/W sensor is tripped (not in armed state) it triggers the wall switch to turn the light on; after 2 min., the light automatically turns off. The problem is: if the switch was manually turned on via the wall switch and I want the light to stay on, if someone trips the D/W sensor, the light turns off after 2 min.
Is there a way to have the scene look at the state of the light switch (if turned on manually). If it sees that the switch was turned on manually, it ignores the action of tripping the D/W sensor so it will not turn off after 2 min.?
Is it possible to do this in one scene? If so, how? Would I be able to insert Luua code…if so, how would I do this.
The easiest way is to use PLEG, but since you asked for lua code… before I became a PLEG fan I wrote the following script for controlling three outside lights when I open my back door and pasted it into a scene that gets triggered every time the door opens. There is a little extra code because it is is written for three lights that should only be turned on at night, but the basic premise is only execute the routine if the light started in the off state. For tips on using luup in scenes, see [url=http://wiki.micasaverde.com/index.php/Luup_Scenes_Events]http://wiki.micasaverde.com/index.php/Luup_Scenes_Events[/url]
-- This provides automatic control for the back deck lights
-- and landscape lights when someone opens the back door
-- variables for the lights to be controlled
local lightID1 = 22
local lightID2 = 41
local lightID3 = 42
-- variables to record the initial state of the lights
local L1start = "0"
local L2start = "0"
local L3start = "0"
local doorID = 5
local DELAY = 300
-- note that these variables can be accessed within functions defined
-- in the same routine, so the functions below can use these variables
-- define the initial state of the lights so that they
-- can be returned to the same state in the end
L1start = luup.variable_get("urn:upnp-org:serviceId:SwitchPower1", "Status", lightID1)
L2start = luup.variable_get("urn:upnp-org:serviceId:SwitchPower1", "Status", lightID2)
L3start = luup.variable_get("urn:upnp-org:serviceId:SwitchPower1", "Status", lightID3)
-- only execute at night
if (luup.is_night()) then
-- for each light, only turn it on and off if it started off
-- if it was already on, leave it on and don't turn it off at the end
if (L1start == "0") then
luup.call_action("urn:upnp-org:serviceId:SwitchPower1","SetTarget",{ newTargetValue="1" },lightID1)
luup.call_delay( "lightOFF", DELAY, lightID1)
end
if (L2start == "0") then
luup.call_action("urn:upnp-org:serviceId:SwitchPower1","SetTarget",{ newTargetValue="1" },lightID2)
luup.call_delay( "lightOFF", DELAY, lightID2)
end
if (L3start == "0") then
luup.call_action("urn:upnp-org:serviceId:SwitchPower1","SetTarget",{ newTargetValue="1" },lightID3)
luup.call_delay( "lightOFF", DELAY, lightID3)
end
end
function lightOFF(lightID)
if (luup.variable_get("urn:micasaverde-com:serviceId:SecuritySensor1", "Tripped", doorID) == "1") then
-- wait another delay cycle if the door is still open
luup.call_delay("lightOFF", DELAY, lightID)
else
luup.call_action("urn:upnp-org:serviceId:SwitchPower1","SetTarget",{ newTargetValue = "0" },tonumber(lightID))
end
end
Best Home Automation shopping experience. Shop at Ezlo!