The Vera Community forums have moved!

Advanced => Programming => Scene Scripting => Topic started by: col8eral on May 25, 2018, 01:29:50 pm

Title: Help with my luup IF syntax
Post by: col8eral on May 25, 2018, 01:29:50 pm
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
Title: Re: Help with my luup IF syntax
Post by: rigpapa on May 25, 2018, 02:20:11 pm
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:
Code: [Select]
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:

Code: [Select]
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. WaterStatus=tonumber(WaterStatus) will work the same).

Title: Re: Help with my luup IF syntax
Post by: col8eral on May 25, 2018, 04:43:13 pm
Thank you so much.

I had no idea that the variable was a text string.

The code works perfectly now.