If door is opened for 5 minutes...turn off air

It was simply to monitor a door or window and if it was left open for five minuets it would turn off the AC unit.

For Vera to work properly this has to be broken into two steps.

[ol][li]Detect Door or Window Opened … Initiate Timer[/li]
[li]When the timer expires do some additional work[/li][/ol]

The plugins I have listed will do this for you.
If you call Sleep … it causes ALL of VERA to sleep. It will not respond to any other inputs during that period … If it’s long enough it will restart it self … because it’s not responding.

Below are two code snippets I copied from the wiki that work like a charm if placed in two separate scenes. They each only look at one sensor and do not detect the status of the ac unit before firing to avoid turning on a unit that was manually turned off.

How would one combine them to:

  • work within one scene
  • Check the status of the ac unit and if off leave off
  • check multiple sensors (doors & windows) closed or not tripped
  • Return it to the mode it was in when the scene was triggered. (for those units without AUTO)

I can configure the scene with triggers for the doors/windows opening and closing, so triggers are not a problem.

I use the following two lines to check the status of a light to not run the scene if the light is already on manually. Will this work for the thermostat as well?

light = luup.variable_get(“urn:upnp-org:serviceId:SwitchPower1”,“Status”,3)
return (light == “1”)

If so, I am not sure how to incorporate that into what I want to happen.

– Turn AC off when Doors/windows opened for 5 minuets

local SENSOR = 17 – The door/window sensor device number
local THERMOSTAT = 3 – 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”

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


– Turn on when doors/windows closed for 10 minuets

local SENSOR = 17 – The door/window sensor device number
local THERMOSTAT = 3 – The thermostat device number
local DELAY = 600 – Seconds

local SES_SID = “urn:micasaverde-com:serviceId:SecuritySensor1”
local HVACO_SID = “urn:upnp-org:serviceId:HVAC_UserOperatingMode1”

luup.call_delay( “turnOnAc”, DELAY)

– Turn on the thermostat if the sensor hasn’t been tripped in the past 10 minutes.
function turnOnAc()
local tripped = luup.variable_get( SES_SID, “Tripped”, DOOR_SENSOR) or “0”
local lastTrip = luup.variable_get( SES_SID, “LastTrip”, DOOR_SENSOR) or os.time()
if (tripped == “0” and (os.time() - lastTrip >= DELAY)) then
local lastModeStatus = luup.variable_get( HVACO_SID, “LastModeStatus”, THERMOSTAT) or “Off”
luup.call_action( HVACO_SID, “SetModeTarget”, {NewModeTarget = lastModeStatus}, THERMOSTAT)
end
end

Hey everybody. I’m trying to do the same thing… If door or windows are opened for 30 seconds …turn off air but I’m not sure if I got the syntax right. What I have so far is a trigger to turn off the air and then a condition called DoHAVACAutoOff with the following syntax: (EntryDoorsOpen;NOW > 00:30) or (KitchenWindowOpen;NOW > 00:30) or (GuestBedroomWindowOpen;NOW > 00:30) or (MasterBedroomWindowOpen;NOW > 00:30). What happens is that it triggers the event right away. Not after 30 seconds. Conversely I have condition to turn the AC back on when the doors are closed which works but I didn’t know if I could combine them or not. The syntax to turn it on is DoHAVACAutoOn (EntryDoorsClosed;NOW > 00:10) or (KitchenWindowClosed;NOW > 00:10) or (GuestBedroomWindowClosed;NOW > 00:10) or
(MasterBedroomWindowClosed;NOW > 00:10)
Any help would be greatly appreciated. Thanks

Yep when you do something like:

 (DoorOpen; Now > 00:30)

It will ALWAYS be true 30 seconds after the event happened … Even if the door was opened two weeks ago!

You want:
(DoorOpen and (DoorOpen;Now > 00:30))

Also note the resolution of events is every minute using NOW as a trigger.
So there is not much difference from 00:10 or 00:30 or 1:00.

OK I think I get it. So basically it?s an expression within an expression. (I applied it BTW and it worked flawlessly… thank you.)

Could I apply that to another scenario I have? Essentially I?d like my front lights to turn on at night but only if my alarm is armed. I?m thinking I need to create a trigger for AlarmArmed as well as either a schedule for sunset or use the night or day plugin.

You can use Day or Night.
You do not need a Schedule …
You could do the following:

LightOn: ALARM and (NOT (7:00:00; NOW; 19:00:00))

With Day or Night:

LigtOn: ALARM and NIGHT

Hi Richard. OK so what I’m understanding is that LightOn: ALARM and (NOT (7:00:00; NOW; 19:00:00)) would essentially be referencing an absolute value. Basically if the alarm is set between 7 pm and 7 am the lights would be on. the same with Day or night except day or night app would automatically adjust for sunrise and sunset.

I did the latter code LightOn: ALARM and NIGHT but it didn’t turn on via a schedule automatically however it did turn on and off when I armed and disarmed my alarm at night. I think I’m half way there. My scenario would be I set me alarm during the day so the lights would be off but nightfall comes before I disarm my alarm. I’d want the lights to turn on at night but only if my alarm was armed. I hope that makes sense. Thanks again for helping me with this fantastic app!!

That should work … And you can test this all day or night … Just toggle your Alarm and/or the Day Or Night switch.

Make sure you have setup your TimeZone AND Location properly in the Vera Setup tab. Otherwise it will not compute the Day and Night time properly.

Hi Richard. I didn’t want you to think I left you hanging there. I needed to apply what you wrote. I did finally get the (AlarmArmed and Night) expression to work. The problem was that I had two different triggers. (AlarmArmed and Night) which would turn my front lights on if it was armed and night. I also had a counter trigger and expression (AlarmDisarmed and Night) which would turn my front lights off. The problem so it would seem is that only the counter trigger was working so essentially my front light would turn off when night came. I’m not understanding why this would happen though as I was using two different triggers and expressions. The only common factor was “night.”

EMAIL me your PLEG report.

Richard, I emailed you the report as per your request. Please let me know if you have any questions and thanks.

When you get the bugs out, please post the full setup, I can use this at my cabin… people always leaving the doors open and A/C on!

I also would like this, I do not want the A/C shutoff just a notification of hey idiot someone probably left the door open… I seem to often not fully shut my (inside) garage door…

[quote=“SOlivas”]See at the end of this for a list of updates/fixed to this code

Ok, I got bored and wanted to try my hand at making the initial code that mcvflorin posted into a plugin, with a few additional features. I know that there is a SmartVirtualThermostat Plugin already in the apps store (I have not tried it), and because of this, I will only post the code here (for now). This plugin does not implement the later modification posted to accommodate motion sensors, but I may try this in a future version.

I call this plugin: Window, Door, and Sensor Control HVAC (WDSC HVAC) plugin v1.0[/quote]

I moved the files for this plugin here:

http://forum.micasaverde.com/index.php/topic,15982.msg121764.html#msg121764

This should make it easier to find, instead of having to dig several pages into this topic to find the code/files.

Interesting… I never got around to implementing anything in ref to this, but will play around this weekend.
Thanks for posting!

I just posted an update that lets you use temperature sensors as well as door/window sensors to control your thermostat.

[quote=“RichardTSchaefer, post:102, topic:166538”]For Vera to work properly this has to be broken into two steps.

[ol][li]Detect Door or Window Opened … Initiate Timer[/li]
[li]When the timer expires do some additional work[/li][/ol]

The plugins I have listed will do this for you.
If you call Sleep … it causes ALL of VERA to sleep. It will not respond to any other inputs during that period … If it’s long enough it will restart it self … because it’s not responding.[/quote]

I would like to disable all three of my nest thermostats if any door or window is left open for more than 5 minutes. I can’t figure out how to setup PLEG or PLET to do this. Are you able to provide details as to how I can set this up.

Thanks

@ryandidur,
There is a plugin version of this that should do what you want - no coding with PLEG is needed.

Take a look at:

[url=http://forum.micasaverde.com/index.php/topic,15982.msg121764.html#msg121764]http://forum.micasaverde.com/index.php/topic,15982.msg121764.html#msg121764[/url]

You can define multiple thermostats that you want to have controlled.

For PLEG, I would recommend you take a look at the information about this plugin elsewhere on this forum. There are a lot of really good examples of how to do things with it.

[quote=“Radjin, post:103, topic:166538”]Below are two code snippets I copied from the wiki that work like a charm if placed in two separate scenes. They each only look at one sensor and do not detect the status of the ac unit before firing to avoid turning on a unit that was manually turned off.

How would one combine them to:

  • work within one scene
  • Check the status of the ac unit and if off leave off
  • check multiple sensors (doors & windows) closed or not tripped
  • Return it to the mode it was in when the scene was triggered. (for those units without AUTO)

I can configure the scene with triggers for the doors/windows opening and closing, so triggers are not a problem.

I use the following two lines to check the status of a light to not run the scene if the light is already on manually. Will this work for the thermostat as well?

light = luup.variable_get(“urn:upnp-org:serviceId:SwitchPower1”,“Status”,3)
return (light == “1”)

If so, I am not sure how to incorporate that into what I want to happen.

– Turn AC off when Doors/windows opened for 5 minuets

local SENSOR = 17 – The door/window sensor device number
local THERMOSTAT = 3 – 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”

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


– Turn on when doors/windows closed for 10 minuets

local SENSOR = 17 – The door/window sensor device number
local THERMOSTAT = 3 – The thermostat device number
local DELAY = 600 – Seconds

local SES_SID = “urn:micasaverde-com:serviceId:SecuritySensor1”
local HVACO_SID = “urn:upnp-org:serviceId:HVAC_UserOperatingMode1”

luup.call_delay( “turnOnAc”, DELAY)

– Turn on the thermostat if the sensor hasn’t been tripped in the past 10 minutes.
function turnOnAc()
local tripped = luup.variable_get( SES_SID, “Tripped”, DOOR_SENSOR) or “0”
local lastTrip = luup.variable_get( SES_SID, “LastTrip”, DOOR_SENSOR) or os.time()
if (tripped == “0” and (os.time() - lastTrip >= DELAY)) then
local lastModeStatus = luup.variable_get( HVACO_SID, “LastModeStatus”, THERMOSTAT) or “Off”
luup.call_action( HVACO_SID, “SetModeTarget”, {NewModeTarget = lastModeStatus}, THERMOSTAT)
end
end[/quote]

I use this code and after figuring out my triggers to get the scene to turn back on it works great. One question, I am using this with one sensor, is there a way to list a number of sensors in the code? My alarm has a wireless sensor on each window and door and would to have this condition for more than one sensor w/o having a scene per sensor.
Thinking like local SENSOR = 17, 18, 19 – The door/window sensor device number

Thanks