Scene to contral Nest operation with conditions-HELP

First or all, I am a NOVICE at programming. I am trying to modify code to support my scene but clearly need some help.

I have found out A/C running with doors wide open at times and could see the same thing happen with heat. All of my doors and windows have sensors that are tied to DSC alarm with EV-3 and the plug-in which is all working perfectly.

I would like to only run Nest when the doors and windows are closed and have been tinkering with the code below. I started with two scenes (one heat and one cool) but would prefer to have only one scene. So please check over my code and let me know what I need to do. Eventually, when I add more light controls, it would be nice to flash one of the lights in the house to alert but for now just would like to NOT throw money out the window-Literally!

Thanks for your assistance.

local SENSOR = 29 – The door/window sensor device number
local SENSOR = 30 – The door/window sensor device number
local SENSOR = 31 – The door/window sensor device number
local SENSOR = 32 – The door/window sensor device number
local SENSOR = 32 – The door/window sensor device number
local SENSOR = 33 – The door/window sensor device number
local SENSOR = 34 – The door/window sensor device numb

local THERMOSTAT = 26 – The thermostat device number
local DELAY = 300 – Seconds

local SES_SID = “urn:schemas-micasaverde-com:device:DoorSensor:1”
local SES_SID = “urn:schemas-micasaverde-com:device:DoorSensor:1”
local SES_SID = “urn:schemas-micasaverde-com:device:MotionSensor:1”
local SES_SID = “urn:schemas-micasaverde-com:device:MotionSensor:1”
local SES_SID = “urn:schemas-micasaverde-com:device:MotionSensor:1”
local SES_SID = “urn:schemas-micasaverde-com:device:MotionSensor:1”

local HVACO_SID = “urn:schemas-watou-com:device:HVAC_ZoneThermostat:1”

luup.call_delay( “turnOffAc”, DELAY)

– Turn off the thermostat if the sensor has been tripped for at least 5 minutes.
function turnOffAc()
local tripped = luup.variable_get( SES_SID, “Tripped”, SENSOR) or “0”
local lastTrip = luup.variable_get( SES_SID, “LastTrip”, SENSOR) or os.time()
if (tripped == “1” and (os.time() - lastTrip >= DELAY)) then
local modeStatus = luup.variable_get( HVACO_SID, “ModeStatus”, THERMOSTAT) or “Off”
luup.variable_set( HVACO_SID, “LastModeStatus”, modeStatus, THERMOSTAT)
luup.call_action( HVACO_SID, “SetModeTarget”, {NewModeTarget = “Off”}, THERMOSTAT)
end
end

There are a lot of issue with your code. Here are some things that stand out:

You are creating multiple variables with the same name for SENSOR. Your SENSOR will be overridden with the last SENSOR value. The same goes for SES_SIS. You are specifying multiple values for the same variable which will be over ridden by the last SES_SID. There is no need to have duplicates. You are also using the device type and not the service id for the SES_SID variable. You are also not defining the HVACO_SID.

[code]local SENSOR = 29 – The door/window sensor device number
local SENSOR = 30 – The door/window sensor device number
local SENSOR = 31 – The door/window sensor device number
local SENSOR = 32 – The door/window sensor device number
local SENSOR = 32 – The door/window sensor device number
local SENSOR = 33 – The door/window sensor device number
local SENSOR = 34 – The door/window sensor device numb

local THERMOSTAT = 26 – The thermostat device number
local DELAY = 300 – Seconds

local SES_SID = “urn:schemas-micasaverde-com:device:DoorSensor:1”
local SES_SID = “urn:schemas-micasaverde-com:device:DoorSensor:1”
local SES_SID = “urn:schemas-micasaverde-com:device:MotionSensor:1”
local SES_SID = “urn:schemas-micasaverde-com:device:MotionSensor:1”
local SES_SID = “urn:schemas-micasaverde-com:device:MotionSensor:1”
local SES_SID = “urn:schemas-micasaverde-com:device:MotionSensor:1”[/code]

should be:

local SENSOR1 = 29    -- The door/window sensor device number
local SENSOR2 = 30    -- The door/window sensor device number
local SENSOR3 = 31    -- The door/window sensor device number
local SENSOR4 = 32    -- The door/window sensor device number
local SENSOR5 = 32    -- The door/window sensor device number
local SENSOR6 = 33    -- The door/window sensor device number
local SENSOR7 = 34    -- The door/window sensor device numb

local THERMOSTAT = 26 -- The thermostat device number
local DELAY = 300    -- Seconds
 
local SES_SID = "urn:micasaverde-com:serviceId:SecuritySensor1"
local HVACO_SID = "urn:upnp-org:serviceId:HVAC_UserOperatingMode1"

You might want to look at the PLEG plugin. It will make your logic much easier to implement and you will not need to know how to program in lua / luup. I have not completed fixing your code as it would require a complete rewrite.

Some threads to look at:

If door is opened for 5 minutes…turn off air
Turn Thermostat off with Door Sensor- Please Help

  • Garrett