Where have my sensor's attributes gone?

I have previously been using a SNZB-02 sensor with Zigbee2MQTT (a battery powered temperature and humidity sensor). This device previously exposed an entity for temperature, but this temperature entity also previously had attributes associated with it for some other measurements (humidity, battery level, link quality, etc). It used to look like this:

However, I have recently come to re-pair my Zigbee network, and the attributes have gone. This is what it looks like now:

Instead, there are separate entities now for each of the measured quantities:

My question: Is this something that has changed in a version of Home Assistant? If so, is it documented somewhere?

(The reason this matters is because it has caused a breaking change in my system. I was previously sending the temperature entity to InfluxDB, which also passed along all the humidity, battery, etc, attributes for the entity as well. See bottom of this post for details. I am aware that I can use template sensors for everything to get back attributes, but it is very cumbersome for many sensors.)

There is a general move in home assistant away from using attributes when they should be their own sensors. Attributes should not change often.

However your issue is not home assistant’s fault, it is how the zigbee2mqtt device driver now reports the states. So it is zigbee2mqtt that was updated to do this.

Looks like this change was made back in October 2020: Expose temp/humidity for HEIMAN HS1HT and SNZB-02 by sjorge · Pull Request #1638 · Koenkk/zigbee-herdsman-converters · GitHub

There is a specific Z2MQTT setting which controls this.
Can’t remember what it’s called right now, but have a look at the Z2MQTT settings page and it’s there, along with a description.

If you didn’t change anything in Z2MQTT settings before this occurred, you should have a look at the Z2MQTT release notes in case this was intentional.

EDIT: @teeeeee found the setting. It’s in Z2M > Settings > Home Assistant Integration tab > Home Assistant legacy entity attributes:

    # Optional: Home Assistant legacy entity attributes, (default: shown below), when enabled:
    # Zigbee2MQTT will send additional states as attributes with each entity. For example,
    # A temperature & humidity sensor will have 2 entities for the temperature and
    # humidity, with this setting enabled both entities will also have
    # an temperature and humidity attribute.
    # Note: Disabling this option, requires a Home Assistant restart
    legacy_entity_attributes: true

For some reason, the description is no longer visible in the Front End, but you can still see it in the Z2M docs.

1 Like

@ShadowFist Good spot. I wasn’t aware of this setting. Perhaps I had it enabled previously. This brings back the attributes for the entity as they used to be. Thanks for making me aware of this.

@tom_l I understand, and it makes sense to move away from attributes that should be their own sensors. The issue really is how data is forwarded on to an InfluxDB database. With the attributes attached to the entity as I want to have, the InfluxDB integration inserts these attributes as fields in the same measurement, which is nice. So it looks like this in the database:

> select * from RHTsensors where time>now()-5m
name: RHTsensors
time                battery domain entity_id                      friendly_name                    host humidity linkquality temperature value voltage
----                ------- ------ ---------                      -------------                    ---- -------- ----------- ----------- ----- -------
1731016532160275000 100     sensor rht_sensor_kitchen_temperature RHT Sensor Temperature (Kitchen) hass 87.61    69          18.51       18.51 3000
1731016563039998000 79.5    sensor rht_sensor_lounge_temperature  RHT Sensor Temperature (Lounge)  hass 79.08    174         16.32       16.32 2900

(The only downside here is that the temperature is stored twice in the database - once from the temperature attribute, and once from the entity state and appears under the field name “value”. As far as I’m aware, there is no way to prevent this “value” being inserted, and only inserting the attributes).

You can also do things like

> select temperature from RHTsensors where time>now()-5m group by friendly_name

which will return all the temperatures associated with the RHT sensors.

Using the “group by” in this way wouldn’t work if we piled all temperature data on our system into a measurement called “temperature”. It could return all kinds of things unrelated (e.g CPU temperatures, which have nothing to room temperatures).

Ultimately, it is nice to have multiple fields associated with each entity. At the moment, it doesn’t seem possible with the InfluxDB integration to specify multiple fields. You only get the entity’s state, which always appears as a field called “value”. So using the attributes is a workaround.

The reason it makes sense to have temperature/humidity/battery etc as multiple fields in the same measurement is because the sensor physically acquired the data at the same time, and transmitted it all at once. So the values should all share a timestamp and be tied together.

1 Like