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

Offline fall-line

  • Beta Testers
  • Full Member
  • *****
  • Posts: 248
  • Karma: +1/-0
Re: If door is opened for 5 minutes...turn off air
« Reply #30 on: April 06, 2011, 11:54:27 am »
@Ape15e right you are! Sorry, I had that in while testing and didn't remove it. Thanks for reviewing.

I've removed the offending line. The above script should now work as expected.



Offline Grain

  • Sr. Newbie
  • *
  • Posts: 41
  • Karma: +0/-0
Re: If door is opened for 5 minutes...turn off air
« Reply #31 on: April 09, 2011, 09:10:01 am »
Code: [Select]

function checkdoorstatus()
  if( luup.variable_get("urn:micasaverde-com:serviceId:SecuritySensor1", "Tripped",38)=="0" ) then
luup.log("Sensor Not Tripped, ending scene")
   stilltripped = "0"
  else
luup.log("Sensor is still tripped!")
   stilltripped = "1"
  end
end

luup.call_timer("checkdoorstatus", 1, "5m", "", "")

if (stilltripped == "0") then
   return false
end


If you want to build the command right into the code, just replace the last bit with something like this:
Code: [Select]
if (stilltripped == "1") then
   luup.call_action("urn:upnp-org:serviceId:SwitchPower1","SetTarget",{ newTargetValue="0" },37)
end    

thanks a lot for this code fall-line
it's great to start experimenting with this, it opens up a lot of possibilities of customisation for Vera!

Offline JOD

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 1978
  • Karma: +4/-0
Re: If door is opened for 5 minutes...turn off air
« Reply #32 on: April 09, 2011, 02:51:33 pm »
@fall-line,

Just a thought.
Do you think this could be better implemented if instead of running the scene every N minutes, to where as you said:
Quote
Since this will run periodically, the amount of time from the window/door being opened until the A/C being turned off will vary (anywhere between 1 second and N minutes)
That the scene is run as an event of the D/W sensors and a countdown timer started that IF the door is left open for N minutes the scene is executed else end.
In my situation with kids, the exterior doors are opened and closed over and over, I wouldnt want the A/C units turning off & on each time the door was opened but only rather if the door was left open for N minutes.

JOD.

I'm sorry, my responses are limited. You must ask the right questions.

Offline aecchalet

  • Full Member
  • ***
  • Posts: 221
  • Karma: +1/-1
Re: If door is opened for 5 minutes...turn off air
« Reply #33 on: May 20, 2011, 11:03:39 am »
I haven't tried this script yet because I knew nothing about Lau code.  However, I found a good introduction to it and will soon start experimenting with a script like this.

One problem that I see with this script is that when the AC has been turned OFF by the resident, this script will actually turn the AC back ON if none of the sensors are tripped!  That is counter productive.  If I first look to see if the AC is OFF before running this script, how will I know if the AC is OFF because the resident turned it OFF or because the previous run of the script turned it OFF?

Maybe the previous idea was better.  That was when a door or window sensor is tripped for more than 5 min, turn AC OFF and leave it OFF until the resident turns it back on.  With this approach, I could first determine if the thermostat is OFF and if so, stop the script before it checks all of the sensors.
Vera Plus 1.7.2138; 12xHRDS1, 2xTrane SCHTZMT400 Tstats; 5xZIR00, 4xCA9000 PIRs; 2xHA01C Recept; 2x2wy ZDW120W switch; 2xAppl (ACT, GE/Jasco), 6xLite Dim Mod (GE/Jasco, Evolve);  2xDead Bolt Schlage

Offline JOD

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 1978
  • Karma: +4/-0
Re: If door is opened for 5 minutes...turn off air
« Reply #34 on: May 20, 2011, 11:31:46 am »
Here's something that is more in line to the original idea.

Scene that runs only if a security sensor has been tripped for a set period of time.

1. Create a new scene. In that scene:

2. Create a timer and set it to run every minute.

3. In the Luup Code section put the following code:

Code: [Select]
local deviceNo = 22
local period = 15
 
local SS_SID = "urn:micasaverde-com:serviceId:SecuritySensor1"
 
local armed = luup.variable_get(SS_SID, "Armed", deviceNo) or "0"
if armed == "1" then
    local tripped = luup.variable_get(SS_SID, "Tripped", deviceNo) or "0"
    if tripped == "0" then
        luup.variable_set(SS_SID, "TripPeriod", "0", deviceNo)
    else
        local tripPeriod = luup.variable_get(SS_SID, "TripPeriod", deviceNo) or 0
        tripPeriod = tonumber(tripPeriod)
        tripPeriod = tripPeriod + 1
        luup.variable_set(SS_SID, "TripPeriod", tripPeriod, deviceNo)
        if tripPeriod == period then
            return true
        end
    end
end
return false
deviceNo is the sensor's device number, which you can get by going into its Toolbox, in the Advanced tab.

period is the time (in minutes) the sensor has been tripped before running the scene.

Note: The sensor must be armed for this to work, but this can be easily changed

Code taken from here: http://wiki.micasaverde.com/index.php/Scripts_for_scenes

JOD.
I'm sorry, my responses are limited. You must ask the right questions.

Offline MNB

  • Hero Member
  • *****
  • Posts: 692
  • Karma: +4/-9
Re: If door is opened for 5 minutes...turn off air
« Reply #35 on: May 20, 2011, 01:57:19 pm »
@JOD, thanxs for the LUA code. Question in the "Note: The sensor must be armed for this to work, but this can be easily changed" How? is via a scene or some other means?
Edge-1.7.2607, VRI06-1LX Dimr (6), VS05-1LX Sw (4), GE ZW3002 Dimr (1), HA01C Outlet (12), HA02C Sw (6), HA04C Sw (4), GE Sw (2), HA05 Sw (3), MiniMote Contr (5), HSM200/100 Sensor (2), ZW100A Sensor (8), Nest thermostat (1) & Protect Fire/CO (6) Kwikset Locks (3), F18918W (1) & IP3M-9 (6) Cam's

Offline JOD

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 1978
  • Karma: +4/-0
Re: If door is opened for 5 minutes...turn off air
« Reply #36 on: May 20, 2011, 03:07:54 pm »
You’re asking the wrong person. All I did was find it and I’m quite sure this came from @mcvflorin and when someone says “this can be easily changed” it’s because they know how to change it.  :P
For the majority of us it's not easy AT ALL.
I’m not a coder and not using this code so would only be able to venture a guess.
This is what I would try. Hopefully someone chimes in with a legitimate “How To” to answer your question and points out my errors as I would hate to be a contributor of inaccurate garbage.

Remove this part?
Code: [Select]
local armed = luup.variable_get(SS_SID, "Armed", deviceNo) or "0"
if armed == "1" then
or change this.
Code: [Select]
if armed == "1" thento this for not armed.
Code: [Select]
if armed ~= "1" thenor
Code: [Select]
if armed == "0" thenPossibly changing this
Code: [Select]
(SS_SID, "Armed", deviceNo)To this for in Bypass
Code: [Select]
(SS_SID, "Bypass", deviceNo)
* Caveat. Don’t take any of the above as working examples.

JOD.
I'm sorry, my responses are limited. You must ask the right questions.

Offline aecchalet

  • Full Member
  • ***
  • Posts: 221
  • Karma: +1/-1
Re: If door is opened for 5 minutes...turn off air
« Reply #37 on: August 12, 2011, 06:13:40 pm »
I am not a programmer and it took a while to learn enough to give this a try.
I have multiple sensors (more than what is currently listed) that I want to see if tripped and if so to turn off AC.
Can some of you with more programming expertise look at this for any obvious mistakes?
I wanted to test it but in IU4, it requires a device# and rejected several that I tried??
Any advice would be appreciated. My renters are killing me leaving doors and windows open with AC on!
Thanks!
_______________________________________________________________
 -- Use this Luup code in a scene that runs every 5 minutes
-- Table of window/door Sensor Devices ID#
-- k is ID# and V is descriptor

WDSensorIDPair = {[25]="GRHall_W", [22]="GRFrnt_D", [23]="GRLanai_D", [28]="MastBR_D",
[21]="LFrtBR_D", [24]="LBkBR_D"}

-- Table of thermostats ID# with descriptor
thermostats = {[4]="GRThermostat", [20]="LHThermostat"}

-- Assume that no sensors are tripped to begin the script.
WDsensortripped = 0

-- Check if any sensor is tripped, if so set the global variable for tripped status.
function find_tripped_sensor()
  While WDsensortripped = 0 do
    for k,v in pairs(WDSensorIDPair)
    do
   if( luup.variable_get("urn:micasaverde-com:serviceId:SecuritySensor1", "Tripped",k)=="0" ) 
     then   
      luup.log("Sensor "..v.." Not Tripped")   
     else
      luup.log("Sensor "..v.." is tripped!")
      WDsensortripped = 1
     end
     end
  end
end

-- Wait 3 min to see if any door/window is still open
-- [[function: call_timer; parameters: function_name (string), type (number),
time (string), days (string), data (string)]]
luup.call_timer("find_tripped_sensor", 1, "5m", "", "")

-- [[If the global variable tripped status is =1, turn the thermostat OFF, else don't change setting
so as to avoid turning thermostats on that had been turned off to begin with!]]

if (WDsensortripped == "1") then
  for  k,v in pairs(thermostats)
  do
    if (WDsensortripped == 1) then
   luup.variable_set("urn:upnp-org:serviceId:HVAC_UserOperatingMode1", "ModeStatus",  "Off", k)
   luup.log("Setting Mode on Thermostat "..v.." to OFF")
    end
  end
end
Vera Plus 1.7.2138; 12xHRDS1, 2xTrane SCHTZMT400 Tstats; 5xZIR00, 4xCA9000 PIRs; 2xHA01C Recept; 2x2wy ZDW120W switch; 2xAppl (ACT, GE/Jasco), 6xLite Dim Mod (GE/Jasco, Evolve);  2xDead Bolt Schlage

Offline MNB

  • Hero Member
  • *****
  • Posts: 692
  • Karma: +4/-9
Re: If door is opened for 5 minutes...turn off air
« Reply #38 on: August 16, 2011, 04:36:18 pm »
@aecchalet did you perchance get anywhere with your code? Mike
Edge-1.7.2607, VRI06-1LX Dimr (6), VS05-1LX Sw (4), GE ZW3002 Dimr (1), HA01C Outlet (12), HA02C Sw (6), HA04C Sw (4), GE Sw (2), HA05 Sw (3), MiniMote Contr (5), HSM200/100 Sensor (2), ZW100A Sensor (8), Nest thermostat (1) & Protect Fire/CO (6) Kwikset Locks (3), F18918W (1) & IP3M-9 (6) Cam's

Offline aecchalet

  • Full Member
  • ***
  • Posts: 221
  • Karma: +1/-1
Re: If door is opened for 5 minutes...turn off air
« Reply #39 on: August 16, 2011, 05:57:16 pm »
I tried testing it in the mios developer's section but in UI4 that seems to want a device #. I tried several device numbers but it wouldn't accept them. Any suggestions for testing the code?
Vera Plus 1.7.2138; 12xHRDS1, 2xTrane SCHTZMT400 Tstats; 5xZIR00, 4xCA9000 PIRs; 2xHA01C Recept; 2x2wy ZDW120W switch; 2xAppl (ACT, GE/Jasco), 6xLite Dim Mod (GE/Jasco, Evolve);  2xDead Bolt Schlage

Offline oTi@

  • Beta Testers
  • Master Member
  • *****
  • Posts: 4045
  • Karma: +30/-6
  • UI what ?!
Re: If door is opened for 5 minutes...turn off air
« Reply #40 on: August 16, 2011, 10:02:51 pm »
[...] mios developer's section [...] seems to want a device #.
You can leave that field blank.
Dezwaved at the moment...

Offline mcvflorin

  • Administrator
  • Hero Member
  • *****
  • Posts: 1759
  • Karma: +11/-3
Re: If door is opened for 5 minutes...turn off air
« Reply #41 on: August 17, 2011, 09:22:37 am »
[...] mios developer's section [...] seems to want a device #.
You can leave that field blank.
You MUST leave that field blank!  ;D Otherwise it won't work. I remember that I removed that asterisk once, but probably I forgot to commit the changes.

Offline oTi@

  • Beta Testers
  • Master Member
  • *****
  • Posts: 4045
  • Karma: +30/-6
  • UI what ?!
Re: If door is opened for 5 minutes...turn off air
« Reply #42 on: August 17, 2011, 01:51:23 pm »
You MUST leave that field blank!  ;D Otherwise it won't work. I remember that I removed that asterisk once, but probably I forgot to commit the changes.
:) For completeness, the link to the prior discussion.
Dezwaved at the moment...

Offline aecchalet

  • Full Member
  • ***
  • Posts: 221
  • Karma: +1/-1
Re: If door is opened for 5 minutes...turn off air
« Reply #43 on: August 25, 2011, 09:20:13 am »
I tried running it in the MIOS Developers/Test Luup code and got "code failed" with no other indication of why it failed. Anyone have a clue?
Thanks
Vera Plus 1.7.2138; 12xHRDS1, 2xTrane SCHTZMT400 Tstats; 5xZIR00, 4xCA9000 PIRs; 2xHA01C Recept; 2x2wy ZDW120W switch; 2xAppl (ACT, GE/Jasco), 6xLite Dim Mod (GE/Jasco, Evolve);  2xDead Bolt Schlage

Offline mcvflorin

  • Administrator
  • Hero Member
  • *****
  • Posts: 1759
  • Karma: +11/-3
Re: If door is opened for 5 minutes...turn off air
« Reply #44 on: August 25, 2011, 10:34:55 am »
Enable verbose logging and look in the logs for messages starting with 01.