With the help of many in this forum, I created a scene which shuts off my AC if any of my doors or windows (with armed sensor) is open for more than 60 seconds or if non of my motion detectors detect motion for more than 20 min between hours of 9 AM and 5 PM. I run this scene every 5 minutes. See below:
_________________________________________________________________________________________________________-
– Begin user input variables
– Table of window and door sensors ID# with descriptor
local wdSensorIdPair = {
[35]=“LwHall_D”,[38]=“UpBed_W”, [41]=“GR_Lanai_D”, [49]=“GRFrnt_D”, [51]=“LwHall_W”, [60]=“LwFrtBRDr”, [61]=“LwBkBR_D”, [81]=“LW_MastBR_D”, [75]=“LwFtBR W”, [80]=“UPHall_W”
}
– Table of motion sensors ID# with descriptor
local motionSensors = {
[58]=“GR_Foyer_MD”, [59]=“LH_MD”, [63]=“GR_TV_MD”, [64]=“Up_Mstr_BR_MD”,
[65]=“Lw_Mstr_BR_MD”
}
– Table of thermostats ID# with descriptor
local thermostats = {[4]=“GRThermostat”, [20]=“LHThermostat”}
– End user input variables
– Check if there are tripped sensors. If there are, then turn the thermostats off.
function checkForTrippedSensors()
– Assume that no sensors are still tripped.
local wdSensorTripped = false
for k, v in pairs(wdSensorIdPair) do
local tripped = luup.variable_get("urn:micasaverde-com:serviceId:SecuritySensor1", "Tripped", k) or "0"
if (tripped == "0") then
luup.log("Sensor '" .. v .. "' is not tripped.")
else
luup.log("Sensor '" .. v .. "' IS TRIPPED!")
wdSensorTripped = true
break
end
end
if (wdSensorTripped) then
for k, v in pairs(thermostats) do
luup.log("Turning thermostat '" .. v .. "' OFF.")
luup.call_action("urn:upnp-org:serviceId:HVAC_UserOperatingMode1", "SetModeTarget", {NewModeTarget = "Off"}, k)
end
end
end
local now = os.date(“*t”)
– If it’s between 9 AM and 7 PM then check the motion sensors.
if (now.hour >= 9 and now.hour <= 19) then
-- Assume that no motion sensor has been tripped in the last 20 minutes.
local motionSensorTripped = false
-- Check when was the last time each motion sensor was tripped.
for k, v in pairs(motionSensors) do
local lastTrip = luup.variable_get("urn:micasaverde-com:serviceId:SecuritySensor1", "LastTrip", k)
lastTrip = tonumber(lastTrip, 10) or os.time()
if (((os.time() - lastTrip) / 60) < 1200) then
motionSensorTripped = true
break
end
end
-- If no motion sensor has been tripped in the last 20 minutes (1200 seconds), then turn off the AC.
if (not motionSensorTripped) then
for k, v in pairs(thermostats) do
luup.log("Turning thermostat '" .. v .. "' OFF.")
luup.call_action("urn:upnp-org:serviceId:HVAC_UserOperatingMode1", "SetModeTarget", {NewModeTarget = "Off"}, k)
end
return -- AC has been turned off: don't check motion sensors anymore.
end
end
– Assume that no sensors are tripped.
local wdSensorTripped = false
– If any sensor is tripped, set the global variable for tripped status.
for k, v in pairs(wdSensorIdPair) do
local tripped = luup.variable_get(“urn:micasaverde-com:serviceId:SecuritySensor1”, “Tripped”, k) or “0”
if (tripped == “0”) then
luup.log(“Sensor '” … v … “’ is not tripped.”)
else
luup.log(“Sensor '” … v … “’ IS TRIPPED!”)
wdSensorTripped = true
break
end
end
– If there was any tripped sensor, check again in 1 minute if there still are tripped sensors.
if (wdSensorTripped) then
luup.call_delay(“checkForTrippedSensors”, 90, “”)
end
______________________________________________________________________________________________________________-