Tips and Tricks working with variables in luup code?

I have been doing some basic scripting; if then statements in luup in vera scenes;
One thing that I find incredibly difficult is working and debugging with variables.
Sometimes I will have the code fail due to various different issues; and there is no way to know why things failed (at least I don’t know). I can search the /var/log/cmh/LuaUPnP.log file and get a little bit more information; but if I am writing code that calls a variable; something like:

status5 = luup.variable_get("urn:micasaverde-com:serviceId:Doorlock1", "Status", 59)

I have no way of knowing what the variable “status5” that the system wrote back was… If this was a batch file; I could do something like “echo status5” and have it display the variables so I could know what I was working with… but I can’t seem to find a way to get this information. I’ve tried the “Develop app” section; where it says test luup code; but it just tells me if it failed or not… no details. (perhaps I am using this section wrong?)
How do you guys work with variables and debug? I’m starting to get into some more complex "if elseif else " statements with a lot more variables and it is becoming impossible to know which variable is coming back “nil” or otherwise different than expected.

Any tips for working through this?

Have you tried the print() function, as laid out in the Lua Programming Manual? Seems like it’s intended to send arguments directly to STD_IO, which in Vera’s case, I suspect is the log file. I don’t know how to view variables directly using luup, though. (For stuff like that, I strictly use Expressions in the Reactor plug-in, and let it handle everything.)


Altui and i beleive LuaView have the prin() function.
Else you can write to log or a state variable.

1 Like

I indeed think that either ALTUI, Luaview or the old luatest plugin would help you a lot. I personally moved to ALTUI and used the code test feature extensively.

It is rather weird that UI7 offered a test lua code feature with no output or return fields.

I second LuaTest. Easy to invoke and use! Brilliant little utility!!

AltUI also has the facility to pretty-print structured data, which can be incredibly useful…

For example:

print (luup.devices[1])


table: 0xb7db20


print (pretty(luup.devices[1]))

shows so much more

	 category_num = 19,
	 description = "ZWave",
	 device_num_parent = 0,
	 device_type = "urn:schemas-micasaverde-com:device:ZWaveNetwork:1",
	 embedded = false,
	 hidden = false,
	 id = "",
	 invisible = true,
	 ip = "",
	 mac = "",
	 pass = "",
	 room_num = 0,
	 subcategory_num = 0,
	 udn = "uuid:4d494342-5342-5645-0001-000002b03069",
	 user = ""

Thank you everyone for the tips; Many of these suggestions have advanced me much further along than I was before!

1 Like

Best Home Automation shopping experience. Shop at getvera!

© 2020 Vera Control Ltd., All Rights Reserved. Terms of Use | Privacy Policy