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

You can leave that field blank.

You can leave that field blank.[/quote]
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.

:slight_smile: For completeness, the link to the prior discussion.

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

Enable verbose logging and look in the logs for messages starting with 01.

Check the syntax (SciTE, …):

  While WDsensortripped = 0 do

 '=' expected near 'WDsensortripped'

->

While (WDsensortripped == 0 ) do


time (string), days (string), data (string)]]
luup.call_timer("find_tripped_sensor", 1, "5m", "", "")

unexpected symbol near ','

so as to avoid turning thermostats on that had been turned off to begin with!]]

'=' expected near 'as'

Check the semantic:

if (WDsensortripped == "1") then
or
if (WDsensortripped == 1) then
?

Use an interval timer ([tt]http://wiki.micasaverde.com/index.php/Luup_Lua_extensions#function:_call_timer[/tt] instead of [tt]while … do[/tt].

I’d also like to do this and have tried different scripts in this thread and nothing works properly. Im baffled on how hard this is. I’d really like to get this working with one of my Aeon Labs D/W sensors and a Z-Wave Thermostat by Trane. If the A/C is on, and the door is open for 5 min, set the Trane to OFF. Im also not worried about turning it back on, the renter can do that.

Hopefully one of the code wizards can help us…

Ok Turning on verbose logging is simple but then examining the logs is NOT.
I found the following wiki page with an outdated link to download puTTY, a program that allows you to connect by SSH to your vera:
http://wiki.micasaverde.com/index.php/Logs
Here is a correct link to download puTTY:
http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html
I downloaded and ran puTTY.exe. I entered the IP address that appears when I get my cp.mios.com dashboard (with default port 22). I pressed the open button and a blank window appears with the IP address that I had entered on the top margin. However, when I try to type “cd /var/log/cmh” to get to the directory with logs, nothing happens. No characters that I type appear in this ssh window??
What am I doing wrong here?
Thus I was unable to view the logs.

Addendum: It appears that I can’t connect to SSH remotely unless I had enabled SSH on my router in my home where vera is connected, which is a long way from my regular home.

Here is my latest draft. I think that some of the syntax was incorrect and I modified it to resemble some vera scripts that I had found on the wiki. Again I entered it into my Mios Developers/Test Luup code window and ran it. Again I got “code failed”. Any other suggestions?
BTW I added a section (after the 3 min wait) which reset the global variable for a tripped sensor to “0” then queried the sensors for another tripped sensor. If one is still found, then the thermostats would be turned off. It would be great if we could get this working!!

– 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

– Begin user input variables

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”}

– End user input variables

– Assume that no sensors are tripped.
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
– [[function: call_timer; parameters: function_name (string), type (number),
time (string), days (string), data (string)]]
luup.call_timer(“find_tripped_sensor”, 1, “3m”, “”, “”)

– Assume that no sensors are still tripped.
WDsensortripped == “0”

– Check if any sensor is STILL 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

– [[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

Updated Wiki page is here.

[...]nothing happens. No characters that I type appear in this ssh window??
You should have gotten a login prompt. Double check the IP address? And is Vera on your LAN?

I think that I should change my ID to Clueless!
Someone suggested using a function as a timer:
“function: call_timer
parameters: function_name (string), type (number), time (string), days (string), data (string)
returns: result (number)
The function ‘function_name’, which must be passed as a string, will be called when the timer is triggered, and will be passed the string ‘data’. The function returns 0 if successful.”
I read this but don’t understand it. What exactly happens after the specified time expires? It indicates to me that, after the specified time interval, this function passes the “data” to the specified function name. Does that function run again? If the global variable was “1”, wouldn’t this go to the call_time function again and begin an endless loop?
What does, “The function returns 0 if successful” mean?
Thanks
Clueless

The call_timer function schedules function_name to run when the specified time expires, passing the data to it.

If the call_timer function successfully schedules the function_name function to run, it returns 0.

aecchalet - did you ever get your code polished and working properly? I’d really like to get mine working but every snippet of code I have won’t work properly - and I only have one sliding door and one trane T-stat

Thanks for any help and code you can post…

Sorry to say but no.
I hope to work on it some more next week.
Any Luup programmer’s efforts that figure out why it won’t won would be greatly appreciated.
Thanks

Anyone? I’ve tried this code and it’s not working. I would like to have my A/C turn off (I have a schlage Z-Wave t-stat) when the aeon D/W sensor detects that the door has been open for more than 5 min. How hard can this really be?

MCV, can you provide some code snippets for us to try? This thread has gone on and on and nobody seems to get it to work…

Try one of the first scripts from here:
[url=http://wiki.micasaverde.com/index.php/Scripts_for_scenes]http://wiki.micasaverde.com/index.php/Scripts_for_scenes[/url]

I modified and got the following script to run in the MIOS Developer’s/Test Luup Code window successfully without syntax erros:
– Create scene that runs every 5 minutes
– Create Command in scene to “arm” each sensor
– Table of window/door Sensor Devices ID#
– k is ID# and V is descriptor

– Begin user input variables

WDSensorIDPair = {[42]=“UPHall_W”, [31]=“GRFrnt_D”, [41]=“GRLanai_D”, [38]=“UPLBckBR_W”,
[39]=“UPRBckBR_W”, [36]=“MastBR_D”, [32]=“LFrtBR_D”, [34]=“LBkBR_D”, [35]=“LwHall_D”,
[40]=“LwHall_W”}

– Table of thermostats ID# with descriptor
thermostats = {[4]=“GRThermostat”, [20]=“LHThermostat”}

– End user input variables

– Assume that no sensors are tripped.
WDsensortripped = “0”

– If any sensor is tripped, set the global variable for tripped status.
function find_tripped_sensor1()
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 1 min
–[[function: call_timer; parameters: function_name (string), type (number),
time (string), days (string), data (string)]]
luup.call_timer(“find_tripped_sensor2”, 1, “1m”, “”, “”)

– Assume that no sensors are still tripped.
WDsensortripped = “0”

– Check if any sensor is STILL tripped, if so set the global variable for tripped status.
function find_tripped_sensor2()
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

–[[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

However, when I created the scene and ran it, it didn’t turn off the thermostat!
I am trying to do this remotely and am unable to view my logs. Can anyone see any error in this script?

Thanks

On this line while is written with capital W, so it is treated as a variable:
[tt]While (WDsensortripped == “0”) do[/tt]

I have two sensors and only one thermostat, but made the edits and also fixed the capital W as MCVFlorin pointed out. I made a scene and put the edited code in the luup tab, saved it, then set my commands to arm both sensors. I set a timer for every 5 min and saved

Turned on the T-Stat, ran the scene, waited a few min, then opened a door and waited another 15 min and nothing…It never turned off the T-Stat.

I modified @aecchalet’s code. Here are the instructions:

  1. Create a scene and set it to run every 5 minutes.
  2. Add this code in that scene.
  3. Modify the variables marked for user input.
-- Begin user input variables

local wdSensorIdPair = {
    [42]="UPHall_W", [31]="GRFrnt_D", [41]="GRLanai_D", [38]="UPLBckBR_W", [39]="UPRBckBR_W",
    [36]="MastBR_D", [32]="LFrtBR_D", [34]="LBkBR_D", [35]="LwHall_D", [40]="LwHall_W"
}

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

-- End user input variables


-- Check if there are tripped sensors. If there are, then turn the thermostats off.
function checkForTrippedSensors()
    -- Assume that no sensors are still tripped.
    wdSensorTripped = false

    for k, v in pairs(wdSensorIdPair) do
        local tripped = luup.variable_get ("urn:micasaverde-com:serviceId:SecuritySensor1", "Tripped", k) or "0"
        if (tripped == "0") then
            luup.log("Sensor '" .. v .. "' is not tripped.")
        else
            luup.log("Sensor '" .. v .. "' IS TRIPPED!")
            wdSensorTripped = true
            break
        end
    end

    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)
        end
    end
end


-- Assume that no sensors are tripped.
local wdSensorTripped = false

-- If any sensor is tripped, set the global variable for tripped status.
for k, v in pairs (wdSensorIdPair) do
    local tripped = luup.variable_get ("urn:micasaverde-com:serviceId:SecuritySensor1", "Tripped", k) or "0"
    if (tripped == "0") then
        luup.log ("Sensor '" .. v .. "' is not tripped.")
    else
        luup.log ("Sensor '" .. v .. "' IS TRIPPED!")
        wdSensorTripped = true
        break
    end
end

-- If there was any tripped sensor, check again in 1 minute if there still are tripped sensors.
if (wdSensorTripped) then
    luup.call_delay ("checkForTrippedSensors", 60, "")
end