adujsting thermostat based on google weather plugin

I have a house that I spend a lot of time away from. I don’t want to pay to heat the house when the danger of freezing doesn’t exist. I have the google weather plugin working and am trying to use it adjust the thermostat. This is my first piece of Lua code, and can’t figure out why my syntax isn’t working. Help?
To test -

  1. I placed code in the MIOS developers plugin under test Lua code and
  2. Placed in a scene that only has this in the Luup code field and ran scene.

Both tests failed.
Thanks for help to this newbie.

I am trying to post my code, but I get an error about not being allowed to post external links.

I hope you find the code that works. But I don’t know that I would trust Google weather with my pipes. Hehe

Good luck!

Can you explain how you planned on using the GW app?
Are you trying to use a trigger word? If so which one?

JOD.

Here it is…

local OUTSIDE_TEMP1 = 32  -- Degrees Fahrenheit
local OUTSIDE_TEMP2 = 10  -- Degrees Fahrenheit
local MINUTES = 60        -- Time between setpoint increments
local TARGET_TEMP1 = 45   -- Degrees Fahrenheit
local TARGET_TEMP2 = 50   -- Degrees Fahrenheit


function avoidFrozenPipe()
    local OutsideTemp = luup.variable_get("urn:micasaverde-com:serviceId:TemperatureSensor1", "CurrentTemperature", 5)
	OutsideTemp = tonumber(OutsideTemp)	
    if (OutsideTemp < OUTSIDE_TEMP1) then
	    if (OutsideTemp > OUTSIDE_TEMP2) then
			luup.call_action("urn:upnp-org:serviceId:HVAC_UserOperatingMode1", "SetModeTarget", {NewModeTarget = "HeatOn"}, 2)
			luup.call_action("urn:upnp-org:serviceId:HVAC_UserOperatingMode1", "SetCurrentSetpoint", {NewCurrentSetpoint = tostring(TARGET_TEMP1)}, 2)
		else
			luup.call_action("urn:upnp-org:serviceId:HVAC_UserOperatingMode1", "SetModeTarget", {NewModeTarget = "HeatOn"}, 2)
			luup.call_action("urn:upnp-org:serviceId:HVAC_UserOperatingMode1", "SetCurrentSetpoint", {NewCurrentSetpoint = tostring(TARGET_TEMP2)}, 2)
		end	
	else
		luup.call_action("urn:upnp-org:serviceId:HVAC_UserOperatingMode1", "SetModeTarget", {NewModeTarget = "HeatOff"}, 2)     
    end
	luup.call_timer("avoidFrozenPipe", 1, MINUTES.."m")
end

avoidFrozenPipe()

It might be necessary to add two empty arguments to [tt]luup.call_timer[/tt], see [tt]http://wiki.micasaverde.com/index.php/Luup_Lua_extensions#function:_call_timer[/tt].

I pulled the whole call_timer line of code out to narrow that down and am still getting “Code failed” in MiOS developer test code as well as nothing happening if code added to a blank scene and scene run.

Thanks for any help.

[tt]micasaverde-com[/tt] > [tt]upnp-org[/tt]

I don’t understand the post from oti@.

He’s underlined the piece that needs to be changed, what it is now, and what it needs to be. The ServiceId needs to be changed, since MCV doesn’t define the one for Temperature Sensors, upnp-org does…

Thanks for the help Oti@ and for the clarification “guessed”. I was just going by the “device type” under the advanced tab of the device (and removing the “schemas”). Your help allowed me to get rid of the “failed code” errors when testing. Now I just have to figure out why it isn’t working. Is there a debugger or way I can insert a line of code that i.e. brings up a message box with a variables value in it when it reaches a certain place in the code?
Thanks,
Rick

There’s no real debugger for this stuff. If you’re comfortable with SSH, you can login to the Box and “view” the log file using:
[tt]tail -f /var/log/cmh/LuaUPnP.log[/tt]

it’ll spit out log output for everything going on with Vera. From there, you can use the luup call:
[tt]luup.log(“Stuff”)[/tt]

liberally scattered throughout your scene code to see how things are going. These will all be logged.

I think “urn:schemas-micasaverde-com:device:TemperatureSensor1” is correct. My code fails in the tester if the condition returns “false”.

This rule of thumb might help:

[ul][li][tt]:device:[/tt] is part of a deviceId string, you probably won’t ever see that in Scene code, in practice[/li]
[li][tt]:service:[/tt] is part of a serviceId string, you’ll see that used all the time in Scene code in [tt]variable_get[/tt], and [tt]variable_set[/tt] calls (these still need the correct bit’s around that string)[/li][/ul]

I think I am pretty much there. I will test the code more when I am in a position to be in the house. I think I am going to want to add code for polling the therm and Google Weather before each run, now I need to figure out how to do that. :slight_smile:

[code]local OUTSIDE_TEMP1 = 32 – Degrees Fahrenheit
local OUTSIDE_TEMP2 = 9 – Degrees Fahrenheit
local MINUTES = 60 – Time between setpoint increments
local TARGET_TEMP1 = 45 – Degrees Fahrenheit
local TARGET_TEMP2 = 48 – Degrees Fahrenheit
local TS_DEVICE_NUM = 3 – Thermostat Device Number
local TSH_SID = “urn:upnp-org:serviceId:TemperatureSetpoint1_Heat”

function avoidFrozenPipe()
local OutsideTemp = luup.variable_get(“urn:upnp-org:serviceId:TemperatureSensor1”, “CurrentTemperature”, 5)
OutsideTemp = tonumber(OutsideTemp)
if (OutsideTemp < OUTSIDE_TEMP1) then
if (OutsideTemp > OUTSIDE_TEMP2) then
luup.call_action (“urn:upnp-org:serviceId:HVAC_UserOperatingMode1”, “SetModeTarget”, {NewModeTarget = “HeatOn”}, TS_DEVICE_NUM)
luup.call_action (TSH_SID, “SetCurrentSetpoint”, {NewCurrentSetpoint = tostring(TARGET_TEMP1)}, TS_DEVICE_NUM)
else
luup.call_action (“urn:upnp-org:serviceId:HVAC_UserOperatingMode1”, “SetModeTarget”, {NewModeTarget = “HeatOn”}, TS_DEVICE_NUM)
luup.call_action (TSH_SID, “SetCurrentSetpoint”, {NewCurrentSetpoint = tostring(TARGET_TEMP2)}, TS_DEVICE_NUM)
end
else
luup.call_action (“urn:upnp-org:serviceId:HVAC_UserOperatingMode1”, “SetModeTarget”, {NewModeTarget = “Off”}, TS_DEVICE_NUM)
end
luup.call_timer (“avoidFrozenPipe”, 1, MINUTES…“m”, nil, nil)
end

avoidFrozenPipe()

[/code]

Never mind. took two seconds to find a post.

luup.call_action("urn:micasaverde-com:serviceId:HaDevice1","Poll",{},39)