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