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 -
I placed code in the MIOS developers plugin under test Lua code and
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 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.
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.
[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.
[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