Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generic MQTT integration #434

Closed
mKeRix opened this issue Jan 7, 2021 · 9 comments
Closed

Generic MQTT integration #434

mKeRix opened this issue Jan 7, 2021 · 9 comments

Comments

@mKeRix
Copy link
Owner

mKeRix commented Jan 7, 2021

Is your feature request related to a problem? Please describe.
Using room-assistant directly with NodeRED (or a different tool that goes directly to MQTT) is cumbersome, as the Home Assistant integration splits the information across multiple topics. There is no easy way to have all relevant information in a single message.

Describe the solution you'd like
A separate integration that offers a more plain and generic MQTT integration than the Home Assistant one. This integration should emit a new message as soon as something changed in the entity (state, attribute, other property...). The message should include the complete new state, and optionally the old state as well.

Describe alternatives you've considered

Additional context
This requires a bit of reworking of the entity registry.

@mKeRix mKeRix closed this as completed in 848a25b Feb 28, 2021
github-actions bot pushed a commit that referenced this issue Feb 28, 2021
# [2.14.0](v2.13.1...v2.14.0) (2021-02-28)

### Bug Fixes

* **bluetooth:** respect connecting state during retry ([8f36d87](8f36d87))
* **entities:** prevent dates from being proxied ([d861486](d861486))

### Features

* add generic MQTT integration ([848a25b](848a25b)), closes [#434](#434)
* **bluetooth-classic:** allow id overrides ([f5fc88d](f5fc88d))
* **bluetooth-low-energy:** allow id overrides ([e41034e](e41034e)), closes [#433](#433)
* **entities:** bunch entity updates together ([52f0197](52f0197))
* **home-assistant:** add discoveryPrefix option ([#546](#546)) ([1056bb5](1056bb5))
@github-actions
Copy link

🎉 This issue has been resolved in version 2.14.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@dflvunoooooo
Copy link

dflvunoooooo commented Mar 4, 2021

Great, thank you for the update and your work!
Now I can see the MQTT-messages in Node-Red with the distance, but how do I get to know which room-assistant instance send the distance. I get an MQTT-message like the following:

object topic: "room-assistant/sensor/bluetooth-classic-XX-XX-XX-XX-XX-XX/attributes" payload: object distance: 0 last_updated_at: "2021-03-04T19:49:35.014Z" qos: 0 retain: false _msgid: "e42c249e.4ce658"

Edit: My bad, I misunderstood the concept. I switched to the mqtt integration, now I get a whole MQTT message with all distances.
Thanks again.

@mKeRix
Copy link
Owner Author

mKeRix commented Mar 4, 2021

If you configure the mqtt integration (it's different from the homeAssistant integration!) you will see new topics appear under room-assistant/entity. They are grouped by instance name, entity type and entity id. These then contain all entity attributes and a diff, like described in the format section of the integration docs. For the overall entity state you could look at entity.state and entity.attributes.distance for example. Or you could look at all measured distances under entity.distances.

EDIT: Jinx!

@ljmerza
Copy link

ljmerza commented Mar 4, 2021

I think this is a great start but it still requires me to subscribe to every RA instance to find where a device is. So if I have 5 RA instances and want to track where my phone is I have to subscribe to all five instances and figure out which one has the latest data for my phone.

What would be great is subscribing to say room-assistant/entity/bluetooth-classic-xxx and this will tell me what room the device is in but also the distance from that device. I'd only have to subscribe to one topic to know everything I need to know about one device.

@mKeRix
Copy link
Owner Author

mKeRix commented Mar 4, 2021

@ljmerza If you have a stable cluster you can just determine an instance to use for your subscription, alternatively you can subscribe to e.g. room-assistant/entity/+/bluetooth-low-energy-presence-sensor/ble-some-id and filter out any messages that have hasAuthority set to false. Either of those will give you all distance values in the message, the former from a manually chosen viewpoint, the latter from the room-assistant determined cluster leader. Or am I missing a use case with that?

The distances from all instances are under entity.distances, the entity.attributes.distance is always the distance from entity.state.

@dflvunoooooo
Copy link

dflvunoooooo commented Mar 4, 2021

I think this is a great start but it still requires me to subscribe to every RA instance to find where a device is. So if I have 5 RA instances and want to track where my phone is I have to subscribe to all five instances and figure out which one has the latest data for my phone.

What would be great is subscribing to say room-assistant/entity/bluetooth-classic-xxx and this will tell me what room the device is in but also the distance from that device. I'd only have to subscribe to one topic to know everything I need to know about one device.

No you don't have to subscribe to every RA instance. I have a mqtt in node with the topic room-assistant/entity/# and after that a switch node which filters by devicename.

And wouldn't it be sufficent to subscribe to one entity, since they all communicate witch each other? For example, if I follow my kitchen entity, the mqqt message alsways contains the distances of all the other RA instances.

@dflvunoooooo
Copy link

My problem now is, that I do not get updates to devices which are not reachable by any RA instance. If I create a sensor in Node Red for the room occupancy, I will not be able to switch it to unavailable.

@mKeRix
Copy link
Owner Author

mKeRix commented Mar 5, 2021

@dflvunoooooo That would be because the entity data doesn't really change in room-assistant for that case. You should still get a state change to not_home after a while (when the internal timeout hits). If you want to do a custom timeout of some sorts I would suggest to have a flow running on an interval that checks the timestamps of the last recorded measurements.

@dflvunoooooo
Copy link

Thanks for your answer. Yes, it changes to not_home but if my created sensor is only using the distances I've got a problem. I created some crude type of trilateration with the distances from mqqt and a function node, wich tells the sensor in which room I am.
My solution is a trigger node which waits one minute for new distances and wehen non appear the sensor will be set to unavailable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants