Issue Zigbee2MQTT and redundant entities (linked)

Hello,

I have a strange behaviour with Zigbee2MQTT integration. All works fine and HA can catch all measurements from Zigbee Devices.

Linked entities are redundant. I thought it was only a visual statement. But, InfluxDB confirmed it.

Field keys are created in InfluxDB HA database for each device entities :

name: sensor.0x5c0272fffeceb025_melody
fieldKey          fieldType
--------          ---------
alarm             float
friendly_name     float
friendly_name_str string
humidity          float
linkquality       float
melody            float
temperature       float
value             float
volume_str        string
name: sensor.0x5c0272fffeceb025_volume
fieldKey          fieldType
--------          ---------
alarm             float
friendly_name     float
friendly_name_str string
humidity          float
linkquality       float
melody            float
state             string
temperature       float
volume_str        string

This applies to all my devices and may become unmanageable with several hundred entities.

What can I do to have only one value per entity?

Thank you in advance for your help.

Multiple entities get created for a Zigbee device, as the device’s capabilities needs to be mapped to different entity types (sensor, binary_sensor, etc.). However, they all share the device’s attributes, that’s why they appear on every entity.

And all attributes are recorded for each entity record, that’s HA recorder design (which is far from the most efficient but at least it works !).

I’ve started creating templates for each data I really want to record. For instance, I want to record a temperature, but I don’t care about the link quality, the battery status and so on. So I create a simple entity with just a status : the temperature. Each record is 5 times smaller than the original entity record.

I have been inspired by this post. It’s very informative to have a look at the content of your database, how many records of each entity, which average record size,…
Large homeassistant database files - Configuration - Home Assistant Community (home-assistant.io)

Hi Christoph, I understand well for the sharing of attributes between entities. But, I don’t understand why each entity must have all the values ​​of the other entities. I hardly dare to imagine the size of the database if a device has 10 entities. This means that each entity will have 10 attributes. While I usually only need one attribute per entity (value/state).

Hi David, thank’s for your template idea and database exploration.

Can disabling auto discovery also be a solution? So each entity is entered manually? A tedious job in perspective …

Disk space is cheap, so why bother? Only option I see (so far) is to disable MQTT discovery support on z2m’s side and create MQTT entities in HA direct.

Also, David’s approach using template sensors to read only state from Zigbee entities, while at the same time excluding the original entities from recorder is valid.

Yes it will work, but that might be a lot of work. :slight_smile:
I have 16 or 17 Shelly modules that are included with manual MQTT sensors and that’s a lot lines in yaml file. I consider migrating to new Shelly core integration at some point because all those lines start to bother me.

And I wouldn’t even consider doing witout auto-discovery for my 60+ zigbee devices connected through Zigbee2MQTT…

Christoph, Of course storage is not a problem. But, unnecessary data in a database in quantity can quickly become an indexing problem.

Here’s example for a device that store a lot of entities data in HA database :

112469|sensor|sensor.0x5c0272fffeceb025_humidity|47|{"alarm": false, "humidity": 47, "linkquality": 195, "melody": 18, "temperature": "18.3", "volume": "low", "unit_of_measurement": "%", "friendly_name": "0x5c0272fffeceb025 humidity", "device_class": "humidity"}|119774|2021-02-02 18:05:35.071923|2021-02-02 20:46:59.554933|2021-02-02 20:46:59.554933|112457
112470|sensor|sensor.0x5c0272fffeceb025_melody|18|{"alarm": false, "humidity": 47, "linkquality": 195, "melody": 18, "temperature": "18.3", "volume": "low", "friendly_name": "0x5c0272fffeceb025 melody"}|119775|2021-02-02 16:46:29.295481|2021-02-02 20:46:59.555115|2021-02-02 20:46:59.555115|112458
112471|sensor|sensor.0x5c0272fffeceb025_duration||{"alarm": false, "humidity": 47, "linkquality": 195, "melody": 18, "temperature": "18.3", "volume": "low", "unit_of_measurement": "second", "friendly_name": "0x5c0272fffeceb025 duration"}|119776|2021-02-02 16:46:29.295626|2021-02-02 20:46:59.555276|2021-02-02 20:46:59.555276|112459
112472|sensor|sensor.0x5c0272fffeceb025_temperature_min||{"alarm": false, "humidity": 47, "linkquality": 195, "melody": 18, "temperature": "18.3", "volume": "low", "unit_of_measurement": "\u00b0C", "friendly_name": "0x5c0272fffeceb025 temperature min"}|119777|2021-02-02 16:46:29.295767|2021-02-02 20:46:59.555469|2021-02-02 20:46:59.555469|112460
112473|sensor|sensor.0x5c0272fffeceb025_temperature_max||{"alarm": false, "humidity": 47, "linkquality": 195, "melody": 18, "temperature": "18.3", "volume": "low", "unit_of_measurement": "\u00b0C", "friendly_name": "0x5c0272fffeceb025 temperature max"}|119778|2021-02-02 16:46:29.295904|2021-02-02 20:46:59.555626|2021-02-02 20:46:59.555626|112461
112474|sensor|sensor.0x5c0272fffeceb025_humidity_min||{"alarm": false, "humidity": 47, "linkquality": 195, "melody": 18, "temperature": "18.3", "volume": "low", "unit_of_measurement": "%", "friendly_name": "0x5c0272fffeceb025 humidity min"}|119779|2021-02-02 16:46:29.296047|2021-02-02 20:46:59.555779|2021-02-02 20:46:59.555779|112462
112475|sensor|sensor.0x5c0272fffeceb025_humidity_max||{"alarm": false, "humidity": 47, "linkquality": 195, "melody": 18, "temperature": "18.3", "volume": "low", "unit_of_measurement": "%", "friendly_name": "0x5c0272fffeceb025 humidity max"}|119780|2021-02-02 16:46:29.296184|2021-02-02 20:46:59.555930|2021-02-02 20:46:59.555930|112463
112476|sensor|sensor.0x5c0272fffeceb025_volume|low|{"alarm": false, "humidity": 47, "linkquality": 195, "melody": 18, "temperature": "18.3", "volume": "low", "friendly_name": "0x5c0272fffeceb025 volume"}|119781|2021-02-02 16:46:29.296317|2021-02-02 20:46:59.556082|2021-02-02 20:46:59.556082|112464
112477|sensor|sensor.0x5c0272fffeceb025_linkquality|195|{"alarm": false, "humidity": 47, "linkquality": 195, "melody": 18, "temperature": "18.3", "volume": "low", "unit_of_measurement": "lqi", "friendly_name": "0x5c0272fffeceb025 linkquality", "icon": "mdi:signal"}|119782|2021-02-02 20:43:12.334374|2021-02-02 20:46:59.556234|2021-02-02 20:46:59.556234|112465
112478|binary_sensor|binary_sensor.0x5c0272fffeceb025_humidity_alarm|off|{"alarm": false, "humidity": 47, "linkquality": 195, "melody": 18, "temperature": "18.3", "volume": "low", "friendly_name": "0x5c0272fffeceb025 humidity alarm"}|119783|2021-02-02 16:45:56.557486|2021-02-02 20:46:59.556395|2021-02-02 20:46:59.556395|112466
112479|binary_sensor|binary_sensor.0x5c0272fffeceb025_temperature_alarm|off|{"alarm": false, "humidity": 47, "linkquality": 195, "melody": 18, "temperature": "18.3", "volume": "low", "friendly_name": "0x5c0272fffeceb025 temperature alarm"}|119784|2021-02-02 16:45:56.557535|2021-02-02 20:46:59.556548|2021-02-02 20:46:59.556548|112467
112480|binary_sensor|binary_sensor.0x5c0272fffeceb025_alarm|off|{"alarm": false, "humidity": 47, "linkquality": 195, "melody": 18, "temperature": "18.3", "volume": "low", "friendly_name": "0x5c0272fffeceb025 alarm"}|119785|2021-02-02 16:45:56.557583|2021-02-02 20:46:59.556700|2021-02-02 20:46:59.556700|112468

We end up with 60 unnecessary data by queries batch. On few records is not problematic. On thousands of recordings, I hardly dare imagine it.

When I open Chronograf to explore my HA InfluxDB database, I have pain in my eyes :smiley:

It would have been nice to be able to select which attributes to consider after discovery process.

There’s at leat two ways it could be improved :

  • Either ignore/deactivate manually unecessary attributes of each entity from MQTT integration
  • Or add an option in HA recorder to ignore some attributes

But I can imagine that is not so trivial and probably not top-priority as it currently works. :slight_smile:

How can I deactivate attributes on each entity ? Deactivate the entity itself it’s ok.