Could someone advise where I’m going wrong. All the code works when used separately but with the addition of the IF statement it fails. Could someone please tell me where im going wrong.
–set device to ping
local device = 82
–Get device status
local WaterStatus = luup.variable_get(“urn:upnp-org:serviceId:VSwitch1”, “Status”, device)
If (WaterStatus) == 1 then
luup.call_action(“urn:upnp-org:serviceId:HVAC_UserOperatingMode1”, “SetModeTarget”, {NewModeTarget = “HeatOn” }, 59)
else
– something else
end
Many thanks
variable_get is setting WaterStatus to a string containing the character “1” not the numeric value 1. Write your comparison like this and it should work:
if WaterStatus == "1" then
OR, you could leave your test as-is and instead convert WaterStatus to numeric by adding this before your IF statement:
WaterStatus = tonumber(WaterStatus, 10)
I put the base (10) parameter in the call because it’s my habit, but 10 is the default, so you don’t have to pass it (e.g. [tt]WaterStatus=tonumber(WaterStatus)[/tt] will work the same).
Thank you so much.
I had no idea that the variable was a text string.
The code works perfectly now.