I am creating a very basic scenario to turn of lights based on a virtual switch. i.e. if switch is off, turn all the lights off. While trying to trouble shoot, I modified my code to give a false result regardless of the status of the virtual switch. To my surprise, the scene does not abort despite the false result; it still turns the lights off!!. Here is the code
status = luup.variable_get(“urn:upnp-org:serviceId:VSwitch1”,“Status”, 64)
if(status==“1”)then
return false
if(status==“0”)then
return false
end
The ID for the switch is 64
Any help is greatly appreciated. Thanks
@Bulldoglowell, I think the issue is that even though both have false, it never cancels the scene. I think putting false for both was just a test to make sure the logic was working. That is unless you are saying that luup notices that both are false and ignores them both.
Lua is seeing that no matter what, the code returns false.
If a Lua routine returns false, the scene will not be run.
The other problem may be his use of variable name. I created a “local” variable that is only used within the routine. I also used a name that is not likely to have been used in other coding. That is why I made the other changes.
i am sure if he tries it, he can tell us if it is working to his expectations
– this script cancels the change of the thermostat to the morning temperature if Vacation Mode is on
local VacationStatus = luup.variable_get(“urn:upnp-org:serviceId:VSwitch1”, “Status”, 66)
if (VacationStatus == “1”) then
return false
end
– any scene that has this in its lua panel (in my machine because I have a VSwitch for Vacation Mode) will not be run if my Vacation Mode switch is ON.
I see the point about the local variable. Perhaps that is his problem, but note that he currently wants the scene to cancel no matter what (as a test) and it is not canceling.
He should try localizing the variable though and changing the name. Perhaps status is a reserved word.
To be fair his intention is to only return false when it is 1 (I think) It wasn’t working so he set both to false to see if it would cancel and it didn’t.
His intention is not to always cancel the scene. I’m with you original suggestion of localizing the variable and perhaps naming it something else.
It seems to me that if this code is not returning false, then its because the status variable does not contain “1” nor “0”. It contains something else (perhaps integer 1 or 0, as suggested by another poster?)
There are ways of dumping the “status” variable to the log, so that you could see what it contained.
The fact the status is global or local should not be an issue here.
edit: Just noticed something. No “end” statement after the first IF. Try putting “end” just before the second IF.
forgive me if this is basic, but after you add the Luup, you are selecting “Save Lua” the blue button, then “Confirm Changes” the green and then “Save” the red button to save the scene, correct?
Can you tell us what your scene is doing?
Best Home Automation shopping experience. Shop at Ezlo!