using lua to get the temp setting on thermostat

Hello,

I don’t have central air, but am working on an automatic thermostat program for my upstairs and downstairs. Basically I envision someone setting the cool setting on the thermostat to the desired temp and it triggers the necessary appliance switches to turn on my window AC units. Once cool enough, it shuts off.

I created a virtual button to enable this “auto pilot” feature. If enabled, it’ll check an upstairs temp sensor, and the downstairs thermostat. The program runs every 15 minutes checking. I have the program working great with setting the manual upper and lower temperatures within Lua, but would like to retrieve the “cool” setpoint on my thermostat and emulate how a central AC would work. Once set–it’ll trigger the necessary appliance modules and start up. My window AC’s remember their powersetting and if power is cut when on, they’ll resume once restored.

I looked through the XML file for the D_TemperatureSetpoint1_Cool which references S_TemperatureSetpoint1.xml for the actual variables. When looking, I can use variable_get to get the current temp, but i’m interested in getting the Cool setting temp, not the real temp. This is within the Action section.

Am I correct in using a call_action method to get variable? I’m lost on the specific syntax needed if so.

Code samples below. Thanks.

Working Manual setting (currently set for a temp that triggers the AC’s if above 75 and turns off below 72

[code]local AC_Run = luup.variable_get(“urn:upnp-org:serviceId:VSwitch1”,“Status”,87)
local upstairs_temp = luup.variable_get(“urn:upnp-org:serviceId:TemperatureSensor1”,“CurrentTemperature”, 84)
local downstairs_temp = luup.variable_get(“urn:upnp-org:serviceId:TemperatureSensor1”,“CurrentTemperature”, 11)

if(AC_Run==“1”) then
if (tonumber(upstairs_temp) >= 75) then
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”, “SetTarget”, {newTargetValue = “1”}, 49)
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”, “SetTarget”, {newTargetValue = “1”}, 50)
elseif (tonumber(upstairs_temp) < 72) then
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”, “SetTarget”, {newTargetValue = “0”}, 49)
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”, “SetTarget”, {newTargetValue = “0”}, 50)
end

if (tonumber(downstairs_temp) >= 75) then
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”, “SetTarget”, {newTargetValue = “1”}, 51)
elseif (tonumber(downstairs_temp) < 72) then
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”, “SetTarget”, {newTargetValue = “0”}, 51)
end
end
[/code]

Proposed code change that isn’t working.

[code]local AC_Run = luup.variable_get(“urn:upnp-org:serviceId:VSwitch1”,“Status”,87)
local upstairs_temp = luup.variable_get(“urn:upnp-org:serviceId:TemperatureSensor1”,“CurrentTemperature”, 84)
local downstairs_temp = luup.variable_get(“urn:upnp-org:serviceId:TemperatureSensor1”,“CurrentTemperature”, 11)

local tempSetpoint = luup.get_action(“urn:upnp-org:serviceId:TemperatureSetpoint1_Cool”, “GetCurrentSetpoint”, 11)

upperLimit = tempSetpoint + 2
lowerLimit = tempSetpoint - 2

if(AC_Run==“1”) then
if (tonumber(upstairs_temp) >= upperLimit) then
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”, “SetTarget”, {newTargetValue = “1”}, 49)
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”, “SetTarget”, {newTargetValue = “1”}, 50)
elseif (tonumber(upstairs_temp) < lowerLimit) then
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”, “SetTarget”, {newTargetValue = “0”}, 49)
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”, “SetTarget”, {newTargetValue = “0”}, 50)
end

if (tonumber(downstairs_temp) >= UpperLimit) then
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”, “SetTarget”, {newTargetValue = “1”}, 51)
elseif (tonumber(downstairs_temp) < lowerLimit) then
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”, “SetTarget”, {newTargetValue = “0”}, 51)
end
end

[/code]

In this line of code:

local tempSetpoint = luup.get_action("urn:upnp-org:serviceId:TemperatureSetpoint1_Cool", "GetCurrentSetpoint", 11)

your offending command is “luup.get_action”, which is not a valid command.

Instead try one (or more) of the following:

local tempSetpoint = luup.variable_get("urn:upnp-org:serviceId:TemperatureSetpoint1_Cool", "CurrentSetpointCool", 11) -- cool setpoint
local tempSetpointAll = luup.variable_get("urn:upnp-org:serviceId:TemperatureSetpoint1", "AllSetpoints", 11) -- all setpoints (comma seperated list)
local tempSetpointCurrent = luup.variable_get("urn:upnp-org:serviceId:TemperatureSetpoint1", "CurrentSetpoint", 11) -- setpoint of the current thermostat mode

If you REALLY want to use a UPnP action… replace the “luup.get_action” with “luup.call_action”… but you shouldn’t need the extra overhead imposed by processing an action…

Wrong serviceId… should be “urn:upnp-org:serviceId:TemperatureSetpoint1”… A temperature sensor does not have a setpoint…

Wrong variable… Should be “CurrentSetpoint”… “GetCurrentSetpoint” is a UPnP action not a variable…

Depending upon the thermostat and how it reports its status, the other variables (AllSetpoints, etc) may not be populated… (although they are populated by me CT30)

If variables are not updated … then the Vera UI will not be updated.

Your code has bit’s and pieces from various places. To me it almost looks like it was randomly generated …
It has LOTS of mistakes … you can’t just mix and match functions, variable names, and serviceIDs.

Throw it out and start over. Use the right functions, serviceIds and Variablenames!

You get variables with luup.variable_get

You find Variables names from the ADVANCED Tab of a device (lower part on UI5).
NOTE: The advanced tab does not have the latest value of a variable. It’s the value from the last time you refreshed the browser.

You find the serviceId for THAT variable on THAT device by letting the mouse hover over the variable name (UI5 and UI7)

Case is important!

[quote=“RichardTSchaefer, post:5, topic:187899”]You get variables with luup.variable_get

You find Variables names from the ADVANCED Tab of a device (lower part on UI5).
NOTE: The advanced tab does not have the latest value of a variable. It’s the value from the last time you refreshed the browser.

You find the serviceId for THAT variable on THAT device by letting the mouse hover over the variable name (UI5 and UI7)

Case is important![/quote]

Richard

Thanks. I haven’t seen that information anywhere…

Don