Why does my scene run even when the Lua result is false?

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

I’m it that familiar with luup but have you tried not comparing them as strings ( “1” and “0” ) and instead comparing them as integers ( 1 and 2 ) ?

Sent from my Nexus 7 using Tapatalk

try

local virtualstatus = luup.variable_get(“urn:upnp-org:serviceId:VSwitch1”,“Status”, 64)
if(virtualstatus==“1”)then
return false
if(virtualstatus==“0”)then
return true
end

you had both conditions returning false

If luup cancels false, the scene is stopped.

OR try

local virtualstatus = luup.variable_get(“urn:upnp-org:serviceId:VSwitch1”,“Status”, 64)
if(virtualstatus==“1”)then
return false
else
return true

because switch status can only have “0” or “1”

@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.

Sent from my Nexus 7 using Tapatalk

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.

Sent from my Nexus 7 using Tapatalk

Here is my recommendation for lua code that will always return false:

get ready…

return false
end – to simplify this, you could remove this line ;D

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.

Sent from my Nexus 7 using Tapatalk

well, i’m sure he can tell us if this worked, and he’s so inclined.

finally, if the scene he wants to cancel, is triggered on this switch (his device 64) that will be problematic as well.

let’s see what he’s doing, yeah?

So I set up a test, using the suggested script

return false

And??. the scene still runs.

well then, we need a little more information.

What is the trigger of the scene? Does it happen to be device 64?

I am manually triggering the scene in order to remove any other factors

If you want your code to prevent manual execution of the scene, place it on the scene’s Luup tab rather than in the trigger’s Luup event.

Code in Luup event only affects that trigger. Code in the Luup tab affects all triggers and manual execution.

The code is in the scene’s LUUP tab, there is no trigger for the scene other than clicking “run.”

[quote=“clawmd, post:1, topic:179651”]status = luup.variable_get(“urn:upnp-org:serviceId:VSwitch1”,“Status”, 64)
if(status==“1”)then
return false
if(status==“0”)then
return false
end[/quote]

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.

[quote=“clawmd, post:10, topic:179651”]So I set up a test, using the suggested script

return false

And??. the scene still runs.[/quote]

clawmd,

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?