The Vera Community forums have moved!

Advanced => Plugins & Plugin Development => Programming => openLuup => Topic started by: rafale77 on February 04, 2019, 09:27:32 pm

Title: How to watch an attribute
Post by: rafale77 on February 04, 2019, 09:27:32 pm
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?
Title: Re: How to watch an attribute
Post by: akbooer on February 05, 2019, 02:49:28 am
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 CommFailure will work?
Title: Re: How to watch an attribute
Post by: rafale77 on February 05, 2019, 03:00:52 am
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.
Title: Re: How to watch an attribute
Post by: rafale77 on February 05, 2019, 11:20:21 am
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.
Title: Re: How to watch an attribute
Post by: akbooer on February 05, 2019, 01:20:58 pm
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.
Title: Re: How to watch an attribute
Post by: rafale77 on February 05, 2019, 01:57:20 pm
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.
Title: Re: How to watch an attribute
Post by: akbooer on February 05, 2019, 02:24:55 pm
OK, I?ll take a look.
Title: Re: How to watch an attribute
Post by: rafale77 on February 06, 2019, 02:58:00 am
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.
Title: Re: How to watch an attribute
Post by: rafale77 on February 08, 2019, 09:19:51 pm
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
Title: Re: How to watch an attribute
Post by: akbooer on February 09, 2019, 02:16:52 am
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!
Title: Re: How to watch an attribute
Post by: rafale77 on February 09, 2019, 02:28:53 am
Thank you for this... I would not have guessed. I ended up testing the existence of the CommFailure variable instead.