Json_attributes_topic - json_attributes deprecated


json_attributes is deprecated. Simple replacing json_attributes with json_attributes_topic gives me some errors.

Could someone give an example on how to use json_attributes_topic right? Is there a new format?

(string)(Optional)The MQTT topic subscribed to receive a JSON dictionary payload and then set as sensor attributes.

(list | string)(Optional)(Deprecated, replaced by json_attributes_topic) A list of keys to extract values from a JSON dictionary payload and then set as sensor attributes.

EDIT: It looks like with adding the whole topic as attributes we can no longer chose which attributes we like to show.
With the new way all attributes are shown. Am I right? Does someone know why this change happened?

Also this way we have duplicate values as state an attribute, like in this example the battery state:

New MQTT config (json_attributes_topic)



I don’t know the answer, but did come across this in another thread:


I checked out the unit tests for the mqtt.py (https://github.com/home-assistant/home-assistant/blob/master/tests/components/sensor/test_mqtt.py) component and it seems its expecting a json array.

- lastRing
- doorbellRing

json_attributes_topic: '["lastRing","doorbellRing"]'


I tried your suggestions, but it doesn’t work. Maybe someone else can confirm that to be sure it’s not my mistake.
The attributes don’t show up.

I think _topic indicates that it’s a mqtt topic this line listens to. Still don’t know if there is a way to filter attributes (only pick the ones we want).


Idea seems to be that there is a separate MQTT topic & payload for attributes. All fields in that payload end up as sensor attributes. This might be handy for something, but doesn’t cover all the cases deprecated json_attributes did, because it allowed to cherrypick necessary attributes from payload. One cannot always change MQTT messages sent by sensor and I think it is impossible to migrate to new json_attributes_topic without changes in system that publishes MQTT messages.

So I think that old json_attributes should be kept also.