We have moved at community.getvera.com

Author Topic: If door is opened for 5 minutes...turn off air  (Read 50348 times)

Offline aecchalet

  • Sr. Member
  • ****
  • Posts: 254
  • Karma: +1/-1
Re: If door is opened for 5 minutes...turn off air
« Reply #90 on: December 15, 2012, 05:15:22 pm »
My electric bill have been running $650-750, down from my highest of $1150/mo.  That was before I implemented the additional Luup code to shut off the AC if none of the 5 motion detectors (2 bedrooms, 1 great room, 1 upper hall, 1 lower hall) trip for more than 20 minutes.  I hope that this will lower my electric bills even more now.  (I have also set my minimum temp to 74F.)

I had to implement this code when I was not staying at the house so can't be sure how it is working.   I have had 2 groups of guests there so far and neither has complained about the AC shutting off.

When I look at "My Alerts", I see that once or twice per day, both of my thermostats turn off at the same time.  That indicates that they are being shut off by my scene with the above code.  Is there some additional code that we can add to inform me why the thermostat was shut off, i.e. window/door sensor tripped > 1 min or no motion for > 20 min?

Also, is there a way to generate a report showing how much time my AC is on during a day? 
Vera Plus 1.7.2138; 12xHRDS1, 2xTrane SCHTZMT400 Tstats; 5xZIR00, 4xCA9000 PIRs; 2xHA01C Recept; 2x2wy ZDW120W switch; 1xAppl (ACT, GE/Jasco), 1xLite Dim Mod (GE/Jasco, Evolve);  2xDead Bolts Schlage

Offline aecchalet

  • Sr. Member
  • ****
  • Posts: 254
  • Karma: +1/-1
Re: If door is opened for 5 minutes...turn off air
« Reply #91 on: December 15, 2012, 05:17:42 pm »
BTW
It would be nice if someone could make a plugin for the market place with this luup code.  I am sure that many other rental home owners would like to implement this type of scene to save them money.
Vera Plus 1.7.2138; 12xHRDS1, 2xTrane SCHTZMT400 Tstats; 5xZIR00, 4xCA9000 PIRs; 2xHA01C Recept; 2x2wy ZDW120W switch; 1xAppl (ACT, GE/Jasco), 1xLite Dim Mod (GE/Jasco, Evolve);  2xDead Bolts Schlage

Offline RichardTSchaefer

  • Community Beta
  • Master Member
  • ******
  • Posts: 10091
  • Karma: +764/-143
Re: If door is opened for 5 minutes...turn off air
« Reply #92 on: December 15, 2012, 06:08:38 pm »
Note: This and your current strategy will turn off the AC at 9:00 if people sleep in (no motion)
You could do this with the Program Logic Event Generator (PLEG) plugin and a scene that only turns off the thermostats.

For each Motion Sensor create a trigger for the PLEG using the Triggers tab.

Then in the PLEG Settings tab create a condition expression:
AutoOff = (Motion1; NOW > 30:00) and (Motion2; NOW > 30:00)  ...  and (MotionN;Now) > 30:00) and (09:00:00 < NOW < 17:00:00)

Then trigger your thermostat off scene when the PLEG device satisfies condition AutoOff

No LUUP code!


Offline aecchalet

  • Sr. Member
  • ****
  • Posts: 254
  • Karma: +1/-1
Re: If door is opened for 5 minutes...turn off air
« Reply #93 on: December 17, 2012, 04:57:01 pm »
I just learned that one can add luup code to send an alert to "Vera Alerts".
I modified the following section:

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)
            luup.call_action("urn:richardgreen:serviceId:VeraAlert1", "SendAlert",
                  {Message = "Wind/Door Tripped AC Off {tone:1}", Recipients = "3vp209j1sjz"}, 67)
        end

It worked very well and told me that the AC was shut off because a window or door was open for more than 1 minute.  I was able to view my devices on the vera desktop and watched it work perfectly.  Unfortunately, I now have to remove that line of code because every 5 minutes when this scene is run, it again tries to turn off the AC and notifies me of such, if a door or window is still open.  At least it helped me confirm that that portion of the code works!
I also inserted the  same line of code in the loop that shuts off the AC if a motion detector hasn't been tripped for more than 20 min between 9 AM and 7 PM.  I will have to remove that extra line of code to avoid repetitive notices but it can help me to confirm that the luup program code is working.

Addendum
I added vera alert message to the luup code segment that turns off the AC if there is no motion for 20 min about 3 days ago.  Today was the first day that I started to receive the messages that the luup code was attempting to turn off my AC.  The house was occupied until yesterday afternoon.  I am surprised that it didn't start messaging me yesterday afternoon or earlier today until it finally started around 5 pm.  Can shadows from clouds trip ZIR000 motion detectors?  Without the vera alert messaging I couldn't tell if it was working because I can't read my logs remotely.  I had to remove the vera alert code because it was messaging me every 5 minutes!
« Last Edit: December 21, 2012, 10:42:28 pm by aecchalet »
Vera Plus 1.7.2138; 12xHRDS1, 2xTrane SCHTZMT400 Tstats; 5xZIR00, 4xCA9000 PIRs; 2xHA01C Recept; 2x2wy ZDW120W switch; 1xAppl (ACT, GE/Jasco), 1xLite Dim Mod (GE/Jasco, Evolve);  2xDead Bolts Schlage

Offline aecchalet

  • Sr. Member
  • ****
  • Posts: 254
  • Karma: +1/-1
Re: If door is opened for 5 minutes...turn off air
« Reply #94 on: December 17, 2012, 05:02:12 pm »
RTS noted that my AC will shut off at 9 AM if someone is sleeping.  That is probably true though I have a motion sensor facing the bed in both master bedrooms.  In Hawaii, most guests are up very early because they are from West Coast or further East time zones so guests rarely sleep past 9 AM.
Thanks for the suggestion and thanks for your modifications to Vera Alerts!
Vera Plus 1.7.2138; 12xHRDS1, 2xTrane SCHTZMT400 Tstats; 5xZIR00, 4xCA9000 PIRs; 2xHA01C Recept; 2x2wy ZDW120W switch; 1xAppl (ACT, GE/Jasco), 1xLite Dim Mod (GE/Jasco, Evolve);  2xDead Bolts Schlage

Offline aecchalet

  • Sr. Member
  • ****
  • Posts: 254
  • Karma: +1/-1
Re: If door is opened for 5 minutes...turn off air
« Reply #95 on: December 17, 2012, 05:06:54 pm »
I also learned about the DataMine plugin.  Once I get back to my vacation home and plug a USB drive into Vera, I hope to use that plugin to track/graph both of my thermostat's ON and OFF modes and average temperatures.  I will also try the google weather plugin to include outside temp for comparison purposes.
Vera Plus 1.7.2138; 12xHRDS1, 2xTrane SCHTZMT400 Tstats; 5xZIR00, 4xCA9000 PIRs; 2xHA01C Recept; 2x2wy ZDW120W switch; 1xAppl (ACT, GE/Jasco), 1xLite Dim Mod (GE/Jasco, Evolve);  2xDead Bolts Schlage

Offline Radjin

  • Full Member
  • ***
  • Posts: 136
  • Karma: +0/-0
Re: If door is opened for 5 minutes...turn off air
« Reply #96 on: December 22, 2012, 03:57:44 pm »
I get "ERROR : Error in lua for scenes and events"  I pasted the code and changed the device numbers into the LUUP of several doors/window triggers i have set up in the GUI. Do I need to do anything to the lua below, beyond change the device ID if I paste it into each of the triggers luup events?

---------------------------
os.execute("sleep 300")

if( luup.variable_get("urn:micasaverde-com:serviceId:SecuritySensor1", "Tripped",33)=="0" ) then   
   luup.log("Sensor Not Tripped, ending scene")   
    return false
end
---------------------------



Offline RichardTSchaefer

  • Community Beta
  • Master Member
  • ******
  • Posts: 10091
  • Karma: +764/-143
Re: If door is opened for 5 minutes...turn off air
« Reply #97 on: December 23, 2012, 12:30:40 pm »
Quote
os.execute("sleep 300")

This should NOT be called in your code. You are basically telling ALL of VERA to shut down for 5 minutes and do NOTHING!!!!!

It might be timing out and reporting this as an error.


Offline Radjin

  • Full Member
  • ***
  • Posts: 136
  • Karma: +0/-0
Re: If door is opened for 5 minutes...turn off air
« Reply #98 on: December 23, 2012, 02:08:39 pm »
Thanks for the info. What should I use to get the results I need?

Offline RichardTSchaefer

  • Community Beta
  • Master Member
  • ******
  • Posts: 10091
  • Karma: +764/-143
Re: If door is opened for 5 minutes...turn off air
« Reply #99 on: December 23, 2012, 05:00:30 pm »
What is the purpose of the SLEEP ?

There are options for delayed actions:
  • Countdown Plugin
  • Program Logic Timer Switch Plugin
  • Program Logic Event Generator Plugin (Generating a delayed event)

These all use safe mechanisms in Vera (luup.call_delay and luup.call_timer) to have an action completed at a later point in time.   
In general your lua code should execute in it's entirety in a few seconds ... for most plugins execution is usually a small fraction of a second.


Offline Radjin

  • Full Member
  • ***
  • Posts: 136
  • Karma: +0/-0
Re: If door is opened for 5 minutes...turn off air
« Reply #100 on: December 24, 2012, 12:20:46 am »
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.

Offline RichardTSchaefer

  • Community Beta
  • Master Member
  • ******
  • Posts: 10091
  • Karma: +764/-143
Re: If door is opened for 5 minutes...turn off air
« Reply #101 on: December 24, 2012, 10:32:26 am »
For Vera to work properly this has to be broken into two steps.

  • Detect Door or Window Opened ... Initiate Timer
  • When the timer expires do some additional work
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.

Offline Radjin

  • Full Member
  • ***
  • Posts: 136
  • Karma: +0/-0
Re: If door is opened for 5 minutes...turn off air
« Reply #102 on: January 18, 2013, 11:47:21 am »
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
« Last Edit: January 20, 2013, 09:39:27 am by Radjin »

Offline Fred S

  • Sr. Newbie
  • *
  • Posts: 48
  • Karma: +0/-0
Re: If door is opened for 5 minutes...turn off air
« Reply #103 on: April 08, 2013, 07:24:19 pm »
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

Offline RichardTSchaefer

  • Community Beta
  • Master Member
  • ******
  • Posts: 10091
  • Karma: +764/-143
Re: If door is opened for 5 minutes...turn off air
« Reply #104 on: April 08, 2013, 08:28:03 pm »
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.

   
« Last Edit: April 08, 2013, 08:29:45 pm by RichardTSchaefer »