How to watch an attribute

AK, I am thinking about getting the device failure notification out of openLuup in a similar way vera sends notifications when a device is failed.
In order to do this, I think I need to set a watch the status attribute of the device. Unfortunately “luup.attr_watch” does not exist.
I can certainly run a scene at regular intervals to copy this attribute into a device variable and then watch that device variable but is there a better way?

There’s no way to do this within the Luup API. More fundamentally, though, this is the essential difference between device attributes and device variables. There is a whole infrastructure simply for variables to do what they do, including being watched. Attributes, on the other hand, are very lightweight placeholders.

Of course, almost anything is possible with openLuup, but your most compatible way is to do what you describe. However, for your needs it may just be that watching the device variable [tt]CommFailure[/tt] will work?

I haven’t looked at the CommFailure one as closely. I seem to remember it being not empty even for non failed devices but I may be wrong.

Well I tested the CommFailure variable and it seems to be be constantly triggering on openluup even if the variable does not change. I may need to try this back on the vera.

You mean that you have a variable watch callback which is constantly called …?!

That’s not right.

Yes, it seems odd. The function is called constantly at every verabridge poll it seems. It is as if every refresh of the variable triggers the watch regardless of the new or old value being the same.

OK, I?ll take a look.

Well I seem to have made it work now and it was likely a typo on my part on the watch definition… remotely typing lua code from my phone without copy paste was not ideal. Sorry. Didn’t meant to send you on a goose chase. I will test the failure notifications but at least it isn’t triggering like crazy.

AK,

I found an oddity with openluup.
When I poll the parent_id of any device in openLuup using luup code
“for k an v in pairs(luup.devices),
v.id_parent”

fail as it does not seem to return the correct id_parent

It would not work on Vera either…

…you need to use v.device_num_parent not v.id_parent.

Just another one of those MiOS/Vera naming inconsistencies!

Thank you for this… I would not have guessed. I ended up testing the existence of the CommFailure variable instead.