We have moved at community.getvera.com

Author Topic: How to watch an attribute  (Read 341 times)

Offline rafale77

  • Community Beta
  • Hero Member
  • ******
  • Posts: 1749
  • Karma: +101/-27
  • HA ≠ IoT as a blue sky is cloudless.
How to watch an attribute
« 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?
openLuup (79 devices, 141 scenes, 19 apps) master to VeraPlus (142 zwave nodes, 8 Zigbee nodes, 221 devices,  20 scenes , 2 apps) +  Hubitat (15 Zigbee nodes) + Home-Assistant (API Integrations). Bridged to Siri and Alexa. Homewave. VeraPlus ExtRooted and mios server independent.

Offline akbooer

  • Moderator
  • Master Member
  • *****
  • Posts: 6387
  • Karma: +291/-70
  • "Less is more"
Re: How to watch an attribute
« Reply #1 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?
3x Vera Lite-UI5/Edge-UI7, 25x Fibaro, 23x TKB, 9x MiniMote, 2x NorthQ Power, 2x Netatmo, 1x Foscam FI9831P, 9x Philips Hue,
Razberry, MySensors Arduino, HomeWave, AltUI, AltHue, DataYours, Grafana, openLuup, ZWay, ZeroBrane Studio.

Offline rafale77

  • Community Beta
  • Hero Member
  • ******
  • Posts: 1749
  • Karma: +101/-27
  • HA ≠ IoT as a blue sky is cloudless.
Re: How to watch an attribute
« Reply #2 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.
openLuup (79 devices, 141 scenes, 19 apps) master to VeraPlus (142 zwave nodes, 8 Zigbee nodes, 221 devices,  20 scenes , 2 apps) +  Hubitat (15 Zigbee nodes) + Home-Assistant (API Integrations). Bridged to Siri and Alexa. Homewave. VeraPlus ExtRooted and mios server independent.

Offline rafale77

  • Community Beta
  • Hero Member
  • ******
  • Posts: 1749
  • Karma: +101/-27
  • HA ≠ IoT as a blue sky is cloudless.
Re: How to watch an attribute
« Reply #3 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.
openLuup (79 devices, 141 scenes, 19 apps) master to VeraPlus (142 zwave nodes, 8 Zigbee nodes, 221 devices,  20 scenes , 2 apps) +  Hubitat (15 Zigbee nodes) + Home-Assistant (API Integrations). Bridged to Siri and Alexa. Homewave. VeraPlus ExtRooted and mios server independent.

Offline akbooer

  • Moderator
  • Master Member
  • *****
  • Posts: 6387
  • Karma: +291/-70
  • "Less is more"
Re: How to watch an attribute
« Reply #4 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.
3x Vera Lite-UI5/Edge-UI7, 25x Fibaro, 23x TKB, 9x MiniMote, 2x NorthQ Power, 2x Netatmo, 1x Foscam FI9831P, 9x Philips Hue,
Razberry, MySensors Arduino, HomeWave, AltUI, AltHue, DataYours, Grafana, openLuup, ZWay, ZeroBrane Studio.

Offline rafale77

  • Community Beta
  • Hero Member
  • ******
  • Posts: 1749
  • Karma: +101/-27
  • HA ≠ IoT as a blue sky is cloudless.
Re: How to watch an attribute
« Reply #5 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.
openLuup (79 devices, 141 scenes, 19 apps) master to VeraPlus (142 zwave nodes, 8 Zigbee nodes, 221 devices,  20 scenes , 2 apps) +  Hubitat (15 Zigbee nodes) + Home-Assistant (API Integrations). Bridged to Siri and Alexa. Homewave. VeraPlus ExtRooted and mios server independent.

Offline akbooer

  • Moderator
  • Master Member
  • *****
  • Posts: 6387
  • Karma: +291/-70
  • "Less is more"
Re: How to watch an attribute
« Reply #6 on: February 05, 2019, 02:24:55 pm »
OK, I?ll take a look.
3x Vera Lite-UI5/Edge-UI7, 25x Fibaro, 23x TKB, 9x MiniMote, 2x NorthQ Power, 2x Netatmo, 1x Foscam FI9831P, 9x Philips Hue,
Razberry, MySensors Arduino, HomeWave, AltUI, AltHue, DataYours, Grafana, openLuup, ZWay, ZeroBrane Studio.

Offline rafale77

  • Community Beta
  • Hero Member
  • ******
  • Posts: 1749
  • Karma: +101/-27
  • HA ≠ IoT as a blue sky is cloudless.
Re: How to watch an attribute
« Reply #7 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.
openLuup (79 devices, 141 scenes, 19 apps) master to VeraPlus (142 zwave nodes, 8 Zigbee nodes, 221 devices,  20 scenes , 2 apps) +  Hubitat (15 Zigbee nodes) + Home-Assistant (API Integrations). Bridged to Siri and Alexa. Homewave. VeraPlus ExtRooted and mios server independent.

Offline rafale77

  • Community Beta
  • Hero Member
  • ******
  • Posts: 1749
  • Karma: +101/-27
  • HA ≠ IoT as a blue sky is cloudless.
Re: How to watch an attribute
« Reply #8 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
« Last Edit: February 08, 2019, 09:34:59 pm by rafale77 »
openLuup (79 devices, 141 scenes, 19 apps) master to VeraPlus (142 zwave nodes, 8 Zigbee nodes, 221 devices,  20 scenes , 2 apps) +  Hubitat (15 Zigbee nodes) + Home-Assistant (API Integrations). Bridged to Siri and Alexa. Homewave. VeraPlus ExtRooted and mios server independent.

Offline akbooer

  • Moderator
  • Master Member
  • *****
  • Posts: 6387
  • Karma: +291/-70
  • "Less is more"
Re: How to watch an attribute
« Reply #9 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!
« Last Edit: February 09, 2019, 02:19:34 am by akbooer »
3x Vera Lite-UI5/Edge-UI7, 25x Fibaro, 23x TKB, 9x MiniMote, 2x NorthQ Power, 2x Netatmo, 1x Foscam FI9831P, 9x Philips Hue,
Razberry, MySensors Arduino, HomeWave, AltUI, AltHue, DataYours, Grafana, openLuup, ZWay, ZeroBrane Studio.

Offline rafale77

  • Community Beta
  • Hero Member
  • ******
  • Posts: 1749
  • Karma: +101/-27
  • HA ≠ IoT as a blue sky is cloudless.
Re: How to watch an attribute
« Reply #10 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.
openLuup (79 devices, 141 scenes, 19 apps) master to VeraPlus (142 zwave nodes, 8 Zigbee nodes, 221 devices,  20 scenes , 2 apps) +  Hubitat (15 Zigbee nodes) + Home-Assistant (API Integrations). Bridged to Siri and Alexa. Homewave. VeraPlus ExtRooted and mios server independent.