We have moved at community.getvera.com

Author Topic: HELP!!! I can't figure out why this doesn't work  (Read 393 times)

Offline melsman

  • Jr. Member
  • **
  • Posts: 50
  • Karma: +2/-0
HELP!!! I can't figure out why this doesn't work
« on: October 20, 2018, 02:31:50 am »
OK -

So I'm not new to programming LUUP, but I'm not an expert either.  But this one has me pulling my hair out! 

This following code works properly:

if (lowtemp > coldlow) then
  return true 
else
  luup.variable_set("urn:upnp-org:serviceId:VContainer1","Variable1","HeatOn",dID3)
  local modestat = "HeatOn"
  luup.call_action("urn:upnp-org:serviceId:HVAC_UserOperatingMode1","SetModeTarget",{NewModeTarget=modestat},dID5)   
  return true
end


But this code does not:

if (lowtemp > coldlow) then
  return true 
else
  luup.variable_set("urn:upnp-org:serviceId:VContainer1","Variable1","HeatOn",dID3)
  local modestat = "HeatOn"
end
luup.call_action("urn:upnp-org:serviceId:HVAC_UserOperatingMode1","SetModeTarget",{NewModeTarget=modestat},dID5)   
return true


Both routines should give the exact same results, but they don't.  In the first example, the variable container and the thermostat both change values - as they are supposed to.  But in the second example, only the variable container changes values; the thermostat does not.  It's as if the routine quits when it finishes the if-then-else condition, but it shouldn't.  It should go to the next statement.

Any ideas? What am I missing?

Melsman
« Last Edit: October 20, 2018, 02:35:59 am by melsman »

Offline akbooer

  • Beta Testers
  • Master Member
  • *****
  • Posts: 6387
  • Karma: +292/-70
  • "Less is more"
Re: HELP!!! I can't figure out why this doesn't work
« Reply #1 on: October 20, 2018, 02:44:51 am »
Your modestat variable is not in scope for the luup call, since it is only defined in the else block.
3x Vera Lite-UI5/Edge-UI7, 25x Fibaro, 23x TKB, 9x MiniMote, 2x NorthQ Power, 2x Netatmo, 1x Foscam FI9831P, 9x Philips Hue,
Razberry, MySensors Arduino, HomeWave, AltUI, AltHue, DataYours, Grafana, openLuup, ZWay, ZeroBrane Studio.

Offline melsman

  • Jr. Member
  • **
  • Posts: 50
  • Karma: +2/-0
Re: HELP!!! I can't figure out why this doesn't work
« Reply #2 on: October 20, 2018, 02:54:35 am »
Thanks, AKBooer!

Melsman

Offline melsman

  • Jr. Member
  • **
  • Posts: 50
  • Karma: +2/-0
Re: HELP!!! I can't figure out why this doesn't work
« Reply #3 on: October 20, 2018, 03:01:04 am »
... and that did it!

local modestat

if (lowtemp > coldlow) then
  return true 
else
  luup.variable_set("urn:upnp-org:serviceId:VContainer1","Variable1","HeatOn",dID3)
  modestat = "HeatOn"
end
luup.call_action("urn:upnp-org:serviceId:HVAC_UserOperatingMode1","SetModeTarget",{NewModeTarget=modestat},dID5)   
return true


I would have never figured that out...

Melsman