The Vera Community forums have moved!

Advanced => Programming => Scene Scripting => Topic started by: melsman on October 20, 2018, 02:31:50 am

Title: HELP!!! I can't figure out why this doesn't work
Post by: melsman 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
Title: Re: HELP!!! I can't figure out why this doesn't work
Post by: akbooer 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.
Title: Re: HELP!!! I can't figure out why this doesn't work
Post by: melsman on October 20, 2018, 02:54:35 am
Thanks, AKBooer!

Melsman
Title: Re: HELP!!! I can't figure out why this doesn't work
Post by: melsman 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