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

@bennynations,

I tried my original code at home last night and got mixed results. After reviewing it more carefully, I think the logic is sound, but I made some poor choices in code when trying to write something off the cuff for you. With that in mind, I’d like to submit another attempt. This works much more reliably for me, and I believe it will for you as well. You can either use this to setup your scene to execute the commands as you already have them, or you can build the commands right into the code if you prefer. Here is the new code:


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

Note: This code uses the call_timer function to implement a cleaner/friendlier 5 minute delay (see the 5m designation in there). You can change “5m” to just “2” if you want to go back to a 2 second delay for testing.

If you want to build the command right into the code, just replace the last bit with something like this:

if (stilltripped == "1") then
   luup.call_action("urn:upnp-org:serviceId:SwitchPower1","SetTarget",{ newTargetValue="0" },37)
end    

This would turn off a switch with the device # 37 if the sensor is still tripped.

@bennynations:

Which device are you using to turn on/off your AC? I have a few 220-240v ACs that could benefit from such a device and would definitely be something worth adding to my Zwave network.

I am also very interested in this application. I wrote to micasaverde to see if their support would help me implement it. They said that for $300, they would write a plug in that they would also make available for all vera users. However have one of you already developed the plug in to do this? If so, is this plug in currently located in the MIOS Market? If it is, what is the name? If the plug in is not located there, is there another way that I can obtain it?
Thanks
(As you can tell, I am a beginning user.)

Don’t they (MCV) get it? Instead of charging someone $300 for this, it could be a STRONG selling point for rental owners. Did MCV forget whats on the front page… “Cut your energy bill” . This is something that everyday people as well as rental owners could use to actually cut their energy bill.

I have had other rental owners ask me how I am able to remotely set the thermostat etc… They think thats cool. (no pun intended). However if I told them they could shut down A/C automatically on a door staying open they would probably be a lot more inclined to try it out for their own property. (Yeah they are capable of dealing with the tech side of vera when she gets cranky)

I have 2 trane thermostats and 6 Hawking HRDS1 sensors on windows and doors installed. Is there anyone that can help me write and install a program to shut off the AC if the door or window is open for 5 min? I saw that some code has been suggested but I am uncertain how to modify it and how to apply it.
I have a Vera2 and I think that I just updated the latest firmware although I am having to have someone power cycle it for me.
Thanks
Tom

Hi aecchalet,

if you can let us know the device IDs for the door senors, as well as the thermostat, I bet we can come up with something useful for you.

You can find the device IDs by clicking the wrench icon, and clicking the Advanced Tab. The device ID will be listed at the top (e.g. Device #37).

My functioning HRDS1 window/door sensor device#s are 9, 10, 12. I have 3-4 more sensors that are not functioning properly yet but I am working on them! My trane thermostat device#s are 4, 16.
Thanks!!

Has anyone gotten the script to work? Can someone help me write a script for my installation?
Thanks

Here is something you can try. This script is intended to be run periodically. It is a little more simplified than the original request, but this is probably the way I would accomplish what you are trying to do if it were me. Especially for a vacation home with needy guests, simple is always better.

Use this code in a scene that runs every N minutes (perhaps 5?). Each time it runs, it will check to see if ANY of the defined sensors are tripped. If so, it will turn the operating mode on ALL defined thermostats to OFF. Otherwise (if none of the sensors are tripped), it will turn the operating mode on ALL the defined thermostats to AUTO (auto switches between heat/cool as required by the set point).

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), but it accomplishes the shutoff and turn (back) on functionality all in one scene. When someone opens a door and leaves it open, the thermostat will be shut off on the next run of this scene. When they close the door (and no other sensors are tripped) the thermostat will go back to auto on the next pass.

I hope this helps you see how this can be accomplished. I would personally strongly recommend that you become familiar with the code and how to read and modify it however before implementing this in a home that you are renting to guests. You don’t want to have goofy things happening to your paying customers.

-- user configurable values ------------------------------------------------------------
--
--

-- List of all of your Sensor Devices that you would like to be included in the checks. 
sensors = {9, 10, 12}

-- List all thermostats that you would like controlled as a result
thermostats = {4, 16}


--
--
-- end of user configurable values -----------------------------------------------------



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

-- Check each sensor defined above. If it is tripped, set the global tripped status.
for  k, v in pairs(sensors) 
do

  if( luup.variable_get("urn:micasaverde-com:serviceId:SecuritySensor1", "Tripped",v)=="0" )  
  then	
	luup.log("Sensor "..v.." Not Tripped")	
	
  else
	luup.log("Sensor "..v.." is tripped!")
	anytripped = 1
  end
end


-- Configure each thermostat defined above. If the global tripped status is set, turn the
-- thermostat OFF, otherwise, turn it to AUTO.

for  k, v in pairs(thermostats) 
       do



	if (anytripped == 1) then

	        luup.log("Setting Mode on Thermostat "..v.." to OFF")
		luup.variable_set("urn:upnp-org:serviceId:HVAC_UserOperatingMode1", "ModeStatus",  "Off", v)
	else
	        luup.log("Setting Mode on Thermostat "..v.." to AutoChangeOver")
		luup.variable_set("urn:upnp-org:serviceId:HVAC_UserOperatingMode1", "ModeStatus",  "AutoChangeOver", v)
	end
end


Good luck!

@fall-line

If the last sensor isn’t tripped, anytripped is 0 - regardless of the state of the other sensors. Is this working as intended?

@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.

[quote=“fall-line, post:21, topic:166538”][code]

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

[/code]

If you want to build the command right into the code, just replace the last bit with something like this:

if (stilltripped == "1") then luup.call_action("urn:upnp-org:serviceId:SwitchPower1","SetTarget",{ newTargetValue="0" },37) end [/quote]

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!

@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:

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 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.

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:

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.

@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?

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. :stuck_out_tongue:
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?

local armed = luup.variable_get(SS_SID, "Armed", deviceNo) or "0" if armed == "1" then
or change this.

if armed == "1" then

to this for not armed.

if armed ~= "1" then

or

if armed == "0" then

Possibly changing this

(SS_SID, "Armed", deviceNo)

To this for in Bypass

(SS_SID, "Bypass", deviceNo)
  • Caveat. Don’t take any of the above as working examples.

JOD.

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

@aecchalet did you perchance get anywhere with your code? Mike

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?