[quote=“mcvflorin, post:12, topic:169228”]Here is the modified code to update an Armed flag (virtual switch) if all the sensors are armed.
[code]
– Device number - device name pairs.
local SECURITY_SENSORS = {
[12] = “Hall Motion Sensor”,
[23] = “Front Window Sensor”,
[34] = “Stairs Motion Sensor”
}
– Door lock device number.
local DOOR_LOCK = 45
– The delay in minutes.
local DELAY = 5
– The virtual switch (Armed flag) device number.
local VIRTUAL_SWITCH = 32
– Update the Armed flag. If all the sensors are armed, the flag is “1”, otherwise the flag is “0”.
function updateArmedFlag()
– Assume that all the sensors are armed.
local armedFlag = “1”
for k, v in pairs (SECURITY_SENSORS) do
local armed = luup.variable_get ("urn:micasaverde-com:serviceId:SecuritySensor1", "Armed", k) or "0"
if (armed == "0") then
armedFlag = "0"
break
end
end
luup.variable_set ("urn:upnp-org:serviceId:SwitchPower1", "Status", armedFlag, VIRTUAL_SWITCH)
end
– Arm all the security sensors only if the door is locked.
function armMotionSensor()
local status = luup.variable_get (“urn:micasaverde-com:serviceId:DoorLock1”, “Status”, DOOR_LOCK) or “0”
if (status == “1”) then
for k, v in pairs (SECURITY_SENSORS) do
luup.call_action (“urn:micasaverde-com:serviceId:SecuritySensor1”, “SetArmed”, {newArmedValue = “1”}, k)
end
– Update the Armed flag in 3 seconds, to be sure that all the sensors are armed.
luup.call_delay (“updateArmedFlag”, 3, “”)
end
end
– Compute the number of seconds for the delay.
local delaySec = DELAY * 60
– Arm the security sensors in ‘delaySec’ seconds.
luup.call_delay (“armMotionSensor”, delaySec, “”)
[/code][/quote]
Thanks!