I’ve created a scene to turn on the space heater for my bedroom when its cold out.
The below code checks to see that the temperature is below 45 degrees otherwise it won’t run the scene (using the Weather Plugin). I’ve tested the code and scene works perfectly, but I wanted to add in one additional piece of functionality. Since I do a lot of traveling, I wanted to be able to set a variable to either 1 or 0 to indicate if I was home or not so when I was away I wouldn’t have to worry about the space heater running all night.
I added a variable “Home” to a light module using the add new value feature.
New service: Home1
New variable: Home
New value: 0
The issue that I’m having is that when I try and test the scene and I put a 0 for the “Home” variable, it still activates the scene even though the logic below should stop it. I’m looking for any help around the code highlighted below to see if it is correct and I’m missing one small item or if I’ve made a big mistake somewhere, being new to Luup. I appreciate any help
Pavs
local cur_tmp = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1","CurrentTemperature",27)
local cur_home = luup.variable_get("urn:upnp-org:serviceId:Dimming1","Home",14)
if(( tonumber(cur_tmp)> 45) [glow=red,2,300]or tonumber(cur_home) == 0)[/glow] then
return false
end
I apologize for putting it in quotes, but it wouldn’t let me post using the CODE tags.
[quote=“bpavlica, post:1, topic:169817”]I added a variable “Home” to a light module using the add new value feature. New service: Home1
New variable: Home
New value: 0
local cur_tmp = luup.variable_get(“urn:upnp-org:serviceId:TemperatureSensor1”,“CurrentTemperature”,27)
local cur_home = luup.variable_get(“urn:upnp-org:serviceId:Dimming1”,“Home”,14)
if(( tonumber(cur_tmp)> 45) [glow=red,2,300]or tonumber(cur_home) == 0)[/glow] then
return false
end[/quote]
When you created the new service, did you really named it Home1? Or that’s just a placeholder? I am asking this because when you get the Home variable with variable_get you use the urn:upnp-org:serviceId:Dimming1 service, which will always return nil.
Try this code instead:
local cur_tmp = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1","CurrentTemperature",27)
local cur_home = luup.variable_get([b]"Home1"[/b], "Home", 14) or 0
if(( tonumber(cur_tmp)> 45) or tonumber(cur_home, 10) == 0) then
return false
end
I recommend to always specify the base of the number you’re converting, it could save you some ambiguity errors.
Be very careful when running a space heater with a ZWave switch.
I do use zwave to trigger the heater a half hour before I get up, but I always turn off the heater at its own switch when I am done using it (I “arm” the heater by turning it on just before going to bed).
The reason for caution: ZWave has been known to fail occasionally. This could lead to the heater being left on unattended, which can cause a fire. I suppose you could use multiple scenes that attempt to turn off the heater for a little more safety, but if the ZWave controller itself is failing, even multiple scenes would not work.
Another caution: Do not use an auto-sensing Zwave electrical plug on a space heater with a mechanical thermostat. If the mechanical thermostat cycles, the auto-sensing will trigger and turn that heater on.
[quote=“mcvflorin, post:2, topic:169817”]Try this code instead:
local cur_tmp = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1","CurrentTemperature",27)
local cur_home = luup.variable_get("Home1", "Home", 14) or 0
if(( tonumber(cur_tmp)> 45) or tonumber(cur_home, 10) == 0) then
return false
end
[/quote]
Worked like a charm.
Thanks mcvflorin!
Best Home Automation shopping experience. Shop at Ezlo!