My first code.Please help

Hello this is my first code ever.
I have only a srt321 thermostat, 3 stellaz and 1 Vera Lite with multiswitch plug in installed.
Since my only input point is the SRT321, i’ve created a scene called whosathome that run every minute. Using special temperature setpoint on the srt321 i’d like to switch on/off the various multiswitch and so trigger some scenes.
For examples
if i put 13degrees it means that we are all at home and the stellaz will change their setpoint while the scenes linked to my boiler will return true.
On the contrary if we are away i put an other setpoint and all goes off. Of course after the input automatically i would like to return to the previous temperature.

(here is the post where i explain it better: http://forum.micasaverde.com/index.php/topic,23900.0.html )

So i wrote this code that works most of the time but…not always.
Can i ask your help to fix it ?

[code]currentset=luup.variable_get(“urn:upnp-org:serviceId:TemperatureSetpoint1_Heat”,“CurrentSetpoint”, 4) --READ THE ACTUAL HEAT SET POINT AND CALL IT “CURRENTSET”

if (tonumber(currentset) > 18) then – IF CURRENTSET IS HIGHER THEN 18 THEN DONT DO ANYTHING (RETURN FALSE)
setpoint = luup.variable_get(“urn:upnp-org:serviceId:TemperatureSetpoint1_Heat”,“CurrentSetpoint”, 4) – CREATE/UPDATE THE VARIABLE “SETPOINT” AND REMEMBER THE TEMP VALUE
return false
else

if (tonumber(currentset) == 15) then – IF CURRENTSET = 15 THEN MY WIFE IS @HOME SO SWITCH THE FIRST MULTISWITCH (STATUS1) AND SWITCH OFF THE AWAY MULTISWITCH SWITCH(STATUS4)
luup.call_action(“urn:dcineco-com:serviceId:MSwitch1”,“SetStatus1”,{ newStatus1=“1” },12)
luup.call_action(“urn:dcineco-com:serviceId:MSwitch1”,“SetStatus4”,{ newStatus4=“0” },12)

elseif (tonumber(currentset) == 16) then --SETPOINT=16 MEANS WIFE+KIDS(SWITCH 1 & 2) AT HOME
luup.call_action(“urn:dcineco-com:serviceId:MSwitch1”,“SetStatus1”,{ newStatus1=“1” },12)
luup.call_action(“urn:dcineco-com:serviceId:MSwitch1”,“SetStatus2”,{ newStatus2=“1” },12)
luup.call_action(“urn:dcineco-com:serviceId:MSwitch1”,“SetStatus4”,{ newStatus4=“0” },12)

elseif (tonumber(currentset) == 17) then – SETPOINT=16 HUSBAND (SWITCH 3) AT HOME
luup.call_action(“urn:dcineco-com:serviceId:MSwitch1”,“SetStatus3”,{ newStatus3=“1” },12)
luup.call_action(“urn:dcineco-com:serviceId:MSwitch1”,“SetStatus4”,{ newStatus4=“0” },12)

elseif (tonumber(currentset) == 14) then – SETPOINT 14 MEANS AWAY
luup.call_action(“urn:dcineco-com:serviceId:MSwitch1”,“SetStatus1”,{ newStatus1=“0” },12)
luup.call_action(“urn:dcineco-com:serviceId:MSwitch1”,“SetStatus2”,{ newStatus2=“0” },12)
luup.call_action(“urn:dcineco-com:serviceId:MSwitch1”,“SetStatus3”,{ newStatus3=“0” },12)
luup.call_action(“urn:dcineco-com:serviceId:MSwitch1”,“SetStatus4”,{ newStatus4=“1” },12)

elseif (tonumber(currentset) == 13) then --SETPOINT = 13 ALL AT HOME (SHORT CUT TO AVOID TO INPUT ALL THE SETPOINT FOR EACH ONE)
luup.call_action(“urn:dcineco-com:serviceId:MSwitch1”,“SetStatus1”,{ newStatus1=“1” },12)
luup.call_action(“urn:dcineco-com:serviceId:MSwitch1”,“SetStatus2”,{ newStatus2=“1” },12)
luup.call_action(“urn:dcineco-com:serviceId:MSwitch1”,“SetStatus3”,{ newStatus3=“1” },12)
luup.call_action(“urn:dcineco-com:serviceId:MSwitch1”,“SetStatus4”,{ newStatus4=“0” },12)

elseif (tonumber(currentset) == 12) then – SETPOINT=12 MEANS HOLIDAY YES/NO(SWITCH 5) SO SOME SCENES WILL NOT BE RUN AND OTHER YES
luup.call_action(“urn:dcineco-com:serviceId:MSwitch1”,“SetStatus1”,{ newStatus1=“1” },12)
luup.call_action(“urn:dcineco-com:serviceId:MSwitch1”,“SetStatus2”,{ newStatus2=“1” },12)
luup.call_action(“urn:dcineco-com:serviceId:MSwitch1”,“SetStatus3”,{ newStatus3=“1” },12)
luup.call_action(“urn:dcineco-com:serviceId:MSwitch1”,“SetStatus4”,{ newStatus4=“0” },12)
luup.call_action(“urn:dcineco-com:serviceId:MSwitch1”,“SetStatus5”,{ newStatus5="-1" },12)

else
setpoint = luup.variable_get(“urn:upnp-org:serviceId:TemperatureSetpoint1_Heat”,“CurrentSetpoint”, 4) --RELATED TO THE FIRST “IF” SO THE HEAT SETPOINT IS READED

end

end

luup.call_action(“urn:upnp-org:serviceId:TemperatureSetpoint1_Heat”, “SetCurrentSetpoint”, {NewCurrentSetpoint = setpoint}, 4) – CHANGE BACK THE TEMPERATURE ACCORDING TO THE VARIABLE"SETPOINT" VALUE[/code]

For me reading your code I find the variable setpoint is poorly defined/used.

One code path sets it, but never uses it.
Only one other code path sets the value.
Many code paths use a previously value.

“It doesn’t always work” is not very helpful.

What do you expect to happen? What does happen? Is it random or is it repeatable? What experiments have you tried to pinpoint the problem? Can you break the problem down into a smaller one that exhibits the same symptoms?

You also have not specified when/how this code is triggered.

Thanks to all for the reply and for your time reading this.
I try to explain it a bit more.

I dont have a pc running all day long nor my wife knows how to operate a computer (unfortunately)or can manage setpoint and scenes. So i would like to give her the opportunity to easily control vera and since i only have the thermostat SRT321 i would like to use it as an input device for my vera lite.

So this is the code for a scene that is run every minute.

I try to explain the situation:

i want to associate to some unused setpoint of the SRT321 (below 18 degrees)the switches of multiswitch so:
15degrees the switch “wife” will turn on meaning she is at home
16 wife+kids at home
17 toggle me at home
14 we are away
13 is a short cut for all at home
12 it’s holiday

After the setting of this unused temperature i would like that automatically the code turn back my thermostat to its previous setpoint.

the switches will trigger the stellaz setpoint. For example if the kids are not at home their room will not be heated.
Some scenes are also run depending on the switches for example if it is holiday the scene “heatOn@6am” will not run, while the “heatOn@9” yes.

PROBLEM: the code works most of the time but in some situation the SRT321 has not turn back to the original temperature remaining for example at 13 degrees (BRRRR).

Sorry for my english and if it looks too complicate.

So. When this problem happens, what do you see in the web interface for Vera? Does the Vera dashboard show the setpoint at 13? Where I’m headed with this is to see if the thermostat is always reporting its status properly to Vera, or if there is a lag, or if some statuses are being entirely dropped.

I question the wisdom of having a feedback loop where changes in the setpoint affect scenes which change the setpoint. That’s open to undefined behaviour when you are modifying the setpoint at the same time as a scene is trying to run.