Author Topic: Help with my luup IF syntax  (Read 225 times)

Offline col8eral

  • Sr. Member
  • ****
  • Posts: 351
  • Karma: +3/-2
Help with my luup IF syntax
« 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

Offline rigpapa

  • Hero Member
  • *****
  • Posts: 638
  • Karma: +93/-1
Re: Help with my luup IF syntax
« Reply #1 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).

Author of Reactor, DelayLight, SiteSensor, Rachio, Deus Ex Machina II, Intesis WMP Gateway, Auto Virtual Thermostat and VirtualSensor plugins. Vera Plus w/100+ Z-wave devices. Vera3 sandbox.

Offline col8eral

  • Sr. Member
  • ****
  • Posts: 351
  • Karma: +3/-2
Re: Help with my luup IF syntax
« Reply #2 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.