zinen / node-red-contrib-dirigera

A Node-Red Node for controlling Ikea Dirigera hub
MIT License
5 stars 0 forks source link

Receive events from devices #7

Open xtvdata opened 6 months ago

xtvdata commented 6 months ago

Hello, would it be possible to also receive the events from the devices (e.g. light was turned on/off) without having to check the status? Like the "observe device" in the old Tradfri implementation.

This would allow to create useful automation rules in NodeRed, or translate events into MQTT message for monitoring/tracking.

P.S.: thanks for the awesome work so far.

zinen commented 6 months ago

I never found the observe choice useful myself.

The reversed engineered API did not reveal a listen method. So only way is to keep requesting new data, filter the data and only return payload on changes. Does this sound like the feature you need?

I'll check how the tradfri module did this and look into it.

xtvdata commented 6 months ago

I used NodeRed's connection to Tradfri to receive events/info from the devices and route them via local MQTT as JSON objects.

From there I fed events/info into an InfluxDB instance to store them and allow a nice access to historical data via Grafana.

I also pulled some details and route them to a Zabbix instance, to monitor stuff such as battery level of remotes, or firmware upgrade events (I know Grafana has alarms, but a Zabbix Templates are much more convenient...). Monitoring is quite useful in case of issues with the devices.

P.S.: not used yet, but "observe" mode could also be useful to setup an extra Ikea remote to trigger complex routines in Node-Red.

xtvdata commented 6 months ago

An extra bit of information is available here: https://github.com/lpgera/dirigera

It looks like the "gateway publishes events via a WebSocket", and using the library above you can receive update events with:

client.startListeningForUpdates(async (updateEvent) => {
  console.log(JSON.stringify(updateEvent))
})
zinen commented 6 months ago

Im already subscribing to a PR that makes it possible to include that lib in this node

https://github.com/lpgera/dirigera/pull/1#issuecomment-1742170205

leifnel commented 2 months ago

Listening on events would be mandatory to get data from switches and motion sensors into node-red, right?

xtvdata commented 1 month ago

Is there any news concerning the feature to receive events?