Pullin' my hair out!...

Ok - I’ve been doing a good deal of basic LUUP programming and I don’t really consider myself a true newbie anymore, but this one has me going crazy!

So what’s wrong with this code?

local dID1 = 66 – Window sensor

local winstatus = luup.variable_get(“urn:micasaverde-com:service ID:SecuritySensor1”,“Tripped”,dID1)

if winstatus == “1” then
return true
return false
end [/code]

Now, I can verify that “Trigger” has a “1” value (the window is open and I can see the variable value in the device advanced table), but no matter what I do, this simple little line of code always returns FALSE.

I’ve used this same code to check status of all of my sensors/swiches without a problem, and I can script this in a scene (using the trigger tab drop-downs) and it works just fine. But for some reason, I can’t get this logic to evaluate to “true” using LUUP.

Any ideas?


The service ID is invalid. Try this:

local winstatus = luup.variable_get("urn:micasaverde-com:serviceId:SecuritySensor1","Tripped",dID1)

Thanks, Rex! That was it.

Between a cut-and-paste error and a text-wrap line break, I completely missed that simple syntax mistake. I knew an extra set of eyes would help!

I’m a little surprised that such a syntax mistake did not flag a LUUP error.


I'm a little surprised that such a syntax mistake did not flag a LUUP error.

As far as Lua is concerned, it is just a string and perfectly valid. The luup.variable_get(…) also didn’t see it as an error - it just couldn’t find a matching service ID so it returned nil (which you didn’t check for so didn’t notice).

Thanks for the hint about testing for “nil”, Rex. That helped with the second part of the problem I was having. I was trying to determine the status of a countdown timer, but was again having logic errors, i.e. was always false. (I’m using my variable container to see what values are being generated by my luup.variable_get(…) commands). But once I tested for nil, I found that the command was returning a nil value, though I couldn’t see anything wrong with the command syntax. So, I just decided to erase and retype the luup.variable_get(…) statement and… viola! Worked properly. Must have had a ghost character or something in there.

Below is the luup I used to test for nil or working command syntax in case anyone is wondering… It’s written in the LUUP tab of a scene named “Step Test” that sits on the UI5 screen next to the countdown timer and the variable container, so that I can see the results in real time. It tells me the variable value (in this case, whether the countdown timer is counting or not) and whether or not the luup.variable_get(…) statement is working, or if it generated a nil value. The variable container allows me to see the information without having to check log files.

[code]local dID1 = 54 – Variable Container 1
local dID3 = 69 – Countdown Timer


local counterstatus = luup.variable_get(“urn:futzle-com:serviceId:CountdownTimer1”,“Counting”,dID3)


if counterstatus == nil then

That’s good. If you just want a quick sitrep, though, you could use the task message area:

local dID = 69 -- Countdown Timer local counterstatus = luup.variable_get("urn:futzle-com:serviceId:CountdownTimer1","Counting",dID) or "nil" local handle = luup.task(counterstatus,1,"Countdown Timer "..dID,-1) luup.call_delay("clrTaskMsg",5,handle) function clrTaskMsg(handle) luup.task("",4,"",tonumber(handle)) end