Help with Luup code and syntax

I need help with the syntax for the following:

local helenabsent = luup.variable_get(“urn:micasaverde.com:serviceId:SecuritySensor1”,“Tripped”, 36)
local richabsent = luup.variable_get(“urn:micasaverde.com:serviceId:SecuritySensor1”,“Tripped”, 35)
if (helenabsent == “0”) or
(richabsent == “0”) then
return false
end
return true

Basically if the “Tripped” variable for either sensor is 0 I don’t want the scene to run. What am I doing wrong as the scene runs regardless? Many thanks.

Try:

urn:micasaverde-com:serviceId:SecuritySensor1

Thanks for your reply. I just tried that but it produces the “code failed” message… any thoughts?

I hope you did not take the quotes out …

You need to change a decimal to a hyphen in your original code in two places.

I left the quotes in.

I get message sent successful with a .com but code failed with a -com. But this code is not stopping the scene from running when it should…

If you are testing this in Test Luup code (Lua), you will get code failed whenever your code returns false. This is an interesting foible of the test feature. ::slight_smile:

OK. Thanks both. I managed to get it working with the change above. But now I have further complicated it. Can anyone see what is wrong with the following:

local helenabsent = luup.variable_get(“urn:micasaverde-com:serviceId:SecuritySensor1”,“Tripped”, 33)
local richabsent = luup.variable_get(“urn:micasaverde-com:serviceId:SecuritySensor1”,“Tripped”, 34)
if (helenabsent == “0”) or
(richabsent == “0”) then
return false
else
return true
luup.inet.wget( ‘http://192.168.1.126:81/set_alarm.cgi?motion_armed=1&user=xxx&pwd=xxx’)
end

It was the introduction of the else statement that is now causing errors. I need to introduce the luup.init.wget command to activate the motion sensor of my camera if the statement generates a “true” response. The http address works on its own so I know its the syntax with the command that is incorrect from the first “else”. I cannot set the motion armed piece from the scene itself. Many thanks.

Do you want to activate the URL first or return from the code first?

Try putting the return true after the luup.inet.wget…

I want the URL to activate if the statement returns true. Is there any way of inserting a time delay (3 seconds) before the URL runs?

Cool. That seems one step closer. I tried putting an “and” after “return true” and that also seemed to work… will try both.

Thanks both for your input.

Semantically the two options provide two totally different results.
However since the wget function always returns a number and, the statement true AND AnyNumber is true … you will get the right result. But the fact that you even tried this tells me you will not even understand my answer.

Please follow @RexBeckett advise … and try to understand what/why people are telling you what to do … People on this forum are here to help you learn.

Fair comment. I had tried putting the “and” in whilst waiting for a reply to my post, I was not intentionally ignoring peoples advice. It just so happened that by experimenting I had managed to produce an output even if the logic was wrong. The fact that the test Lua code section of the Vera will show “code failed” if it produces a false response is certainly a “lesson learnt”

And I do understand your answer completely, I’m not an idiot. Just someone who’s gone from very little Luup code knowledge to this in a couple of days.

Anyway, I appreciate everyone help!