I have a couple of scenes that use LUUP code to light up all of the buttons on my 4-button scene controllers. I want all 4 buttons lit at all times. And this worked great for a while.
A couple days ago I noticed that one of the controllers had no lights on. Then another went dark. They still work, but the button lights are no longer on.
Today I notice that the controller that formerly had ID 14 is now 15, and the one that was 29 is now 30. So, no wonder the LUUP scripts stopped working…
But, WTF? Does this happen often?
I had a bad feeling about hard-coding the device numbers in the scripts… It would be great to have symbolic constants instead, e.g. have “HallwayControllerDeviceId = 22” be automatically generated so that scripts could use the symbolic name rather than hard-coding numbers that change at random.
I’m hoping this doesn’t happen often, but you suggest a great solution (I think.)
Very easy, surely, to put a bit of code in Luup startup which generates all the symbolic names you need. Along the lines of:
for i,d in pairs(luup.devices) do
ID[d.description] = i
end
Then use ID[“symbolic name”] in your scripts for the device number.
You can probably evolve this to be more elegant, but it’s a start.
Interesting idea. But it occurs to me that if I change the name of a switch, any code that uses it will break - that was one of the advantages of the numeric IDs… I think what’s really needed is an immutable name that survives changes to the display-name or to the numeric ID. Or maybe, use the approach that you described, and also make Vera smart enough to rename any references in the code when you rename the device (like software refactoring tools).
All of which sounds like a lot of work for the MCV people. The solution with the most bang-of-the-buck would probably just be to make the device ID numbers immutable. If my devices hadn’t gotten renumbered, the numeric IDs wouldn’t really be all that much of a problem.
Also, after updating the device IDs, the LEDs in the scene controllers still do not respond to the LUUP scripts. Does anyone have any theories about what’s gone wrong there?
I have never had any devices have they ID changed!
In UI4, it used to happen a lot with Lua-based plugins… basically anything that had “concurrency” in the callers.
eg. A timer method invocation, at the same time as a block, for example could corrupt internal state
… which is especially bad during startup processing when the DeviceId’s are decided, and they’d often get “reallocated”… with all sorts of ensuing fun for Scene processing. This problem is better in UI5, not eliminated, but definitely better.
In this case though, it sounds like the [Vera] Device Id’s for Z-Wave Devices getting mangled… which I’ve never seen.
So, I found the problem… maybe nothing actually changed.
But I would love to see this bit of UI changed in the future because it makes no sense.
[quote=“MiPolloMole, post:7, topic:175286”]So, I found the problem… maybe nothing actually changed.
But I would love to see this bit of UI changed in the future because it makes no sense.[/quote]
these 2 values are totally different. The upper value is the device ID in Vera. The lower one is the Z-Wave node ID; so typically they are different for Z-Wave devices.
Oh right. How obviously self-evident.
How could I be so silly as to overlook that distinction, when the answer was staring me in the face all along.