Json_attributes_topic - json_attributes deprecated


#1

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?

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

json_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?

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


New MQTT config (json_attributes_topic)
#2

Anyone…?


#3

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


#4

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.

old:
json_attributes:
- lastRing
- doorbellRing

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


#5

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).


#6

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.