Home Assistant MQTT Sensor discovery enhancements, areas support.#102
Conversation
| payload['device_class'] = params['device_class'] | ||
| payload['unique_id'] = "{}-{}".format(flora['mac'].lower().replace(":", ""), sensor) | ||
| payload['device'] = { | ||
| 'identifiers' : ["MiFlora{}".format(flora['mac'].lower().replace(":", ""))], |
There was a problem hiding this comment.
Out of curiosity, what is this used for?
There was a problem hiding this comment.
It is necessary info for HA Device registry so Miflora Device is created upon HA MQTT discovery with its device connection (BTLE MAC address) and then all sensors like temperature, lux, moisture etc. are linked with this new device and identified with by theirs unique_id (btle_mac-temperature, btle_mac-light, ....). Details: https://www.home-assistant.io/integrations/sensor.mqtt/. There is also ha-core github discussion with mqtt json example: home-assistant/core#16943 (comment).
There was a problem hiding this comment.
Sorry. Of course I'm aware of the device discovery feature :) I was asking about the identifiers specifically. Documentation says
A list of IDs that uniquely identify the device. For example a serial number.
But would you by any chance know what it is actually used for? I wonder whether or not more than one element per sensor would make sense... just curious :)
There was a problem hiding this comment.
If we are talking about unique_id: it is necessary to be unique for each entity(=sensor) - probably some unique index in device registry db/table. Each entity with unique_id must be then linked by 'device' section with its physical device (control unit with multiple sensors). If you look into new miflora the MQTT topic, then each sensor (temperature, lux, moisture, conductivity, battery) has different unique_id, but same parent device. That is how relationship is defined and HA know the connections.
Details:
https://developers.home-assistant.io/docs/device_registry_index/
There was a problem hiding this comment.
regarding multiple Identifiers - don't know why there should be more than one unique identifiers... can't think of some use case when you would need more identifiers. But I'm not a HA guru... :)
There was a problem hiding this comment.
Nope me neither. Maybe something for a later point. Feels like this whole concept of devices becomes more and more important in HA
|
In the Home Assistant device view the battery level for smartphones is given. Seems like that is not supported by MQTT Sensor. Do you know more about that? |
Can you clarify what you mean? Battery levels on my screenshot ( #101 ) are Miflora battery levels... or do you mean something else? |
Aha! Didn't see them. That is pretty cool! All good. I will test and merge this evening |
|
@bangom I tried your PR and with that the HA integration. I have Bluetooth connection issues on my RPI0W and will need to look into this. |
Turns out that my two years old sensors with firmware version 2.6.2 are not supported by btlewrap 🤷♂ Just in case you are interested |
Seems OK to me, tested latest git version with merged pull. |
According to HA MQTT Sensor Discovery (https://www.home-assistant.io/integrations/sensor.mqtt/) miflora-mqtt-daemon should also send sensor's "unique_id" along with it's "parent device" information (identifiers, connections, firmware, ... ) configuration variables.
After that, the discovered MQTT sensor is added automatically into HA Device Registry (https://developers.home-assistant.io/docs/device_registry_index/) and visible in HA GUI. Also, Miflora sensor can be then used with HA Areas.
Whole enhancement is discussed in #101 .