New MQTT config (json_attributes_topic)

According to https://www.home-assistant.io/components/sensor.mqtt/#json-attributes-topic-configuration it should be a dict i.e.:

"json_attributes_topic": {"ClientName": "name", "MAC": "mac", "DiscoveredDevices": "discovered_devices"}`

But that does not work for me…

You have to put the topic here. In my case it is just the same value as for state_topic. For example
zigbee2mqtt/motion/kitchen

But, I don’t know how to call to a list of attributes… In my case, this is my actual config:

  - platform: mqtt
    name: Cell BT
    state_topic: "homeassistant/sensor/android_bluetooth/state"
    value_template: "{{ value_json.enabled }}"
    json_attributes:
      - name
      - mac
      - discovered_devices

So, I think I should have this config:

  - platform: mqtt
    name: Cell BT
    state_topic: "homeassistant/sensor/android_bluetooth/state"
    value_template: "{{ value_json.enabled }}"
    json_attributes_topic: "homeassistant/sensor/android_bluetooth/discovered_devices"

But this config doesn’t work…

Does

json_attributes_topic: "homeassistant/sensor/android_bluetooth/state"

work?

I had the same thing following the .85 upgrade. The above change worked for me, but now I get all the states in the json string, rather than simply the one specified in the value_template. Not an issue, just shows them all (~16).

I have the same issue.

Coming from here:

To get the attributes I simple copied the state_topic to the json_attributes_topic.
But as mentioned before this will show all of the attributes, which is not as smart as before (picking the right ones).

I wonder if an issue should be created to keep also the old configuration style because it is smarter for setups where you cannot change MQTT message payloads.

1 Like

Found this in another thread

I’m receviing the configuration variable "json_attributes" is deprecated, replace with "json_attributes_topic" error in my logs but for the life of me I can’t find any references to json_attributes anywhere in my config files.

Is there something hidden I should be looking at?

I used zigbee2mqtt amongst other things such as MQTT sensor templates. Below is a snippet from one of my MQTT sensors, would that cause any issues?

  - platform: mqtt
    state_topic: "zigbee2mqtt/Cube"
    name: "Cube Battery"
    unit_of_measurement: "%"
    value_template: '{{ value_json.battery }}'
    icon: mdi:battery-bluetooth-variant

Do you have any devices created by discovery?

Excuse my ignorance but how would I tell? And if I did surely they would be created as part of the core HA functionality not effected by this issue?

I have the same issue as apt… I use zigbee2mqtt. I originally had it all set up pairing devices through that component and then managed to break it all. All the data files were still in tact but I was trying to rebuild the MQTT integration (under config). I ended up deleting it and Hassio ‘auto discovered’ my old config and it started working again. Below is the integration (apt: it is under configuration -> integrations).

59%20am

Interestingly, I do have the same number of json_attributes errors as I have sensors under that integration, but I can’t find the text “json_attributes” anywhere in my files either.

Do you know where the files may have been stored? I checked the /share/zigbee2mqtt files.

Thanks,
Matthew

1 Like

This appears fixed by today’s zigbee2mqtt component update. Thanks for the update guys.

1 Like

That seems to have fixed it for me too plus my random restarts every few hours. :slight_smile:

Can someone, post your Before and After code? I still don’t get it…

@mattat My “json_attributes” was hidden in a package…

Have you updated the zigbee2mqtt component under the Hass.io menu? It should be version 1.1.1, which made the error go away for me. I didn’t have to change any of my code.

Having manually configured all my YAML to use to new json_attributes_topic I am still getting warnings in the HA log about /mqtt/sensor.py and using json_attributes

I am running 1.1.1 and 0.87.0

Someone suggested maybe auto discovered devices? I have a bunch I don’t use that I manually added and HA added as well (I’d love to get rid of them)

@stratplayer I was having these error messages as well, turned out I had retained messages from old devices in my mqtt database. Check this out: https://github.com/Koenkk/zigbee2mqtt/issues/713
It mentions hass.io but that’s besides the issue. I have a separate mqtt container so i just removed my mosquitto.db. If you’re using the HA integrated mqtt you should see if you can clear the retained messages as mentioned in the url i mentioned.
Good luck.

edit:
I think I had json_attributes in “homeassistant/light/+/+/config” and “homeassistant/sensor/+/+/config”. be sure to check out both.

Nice one!

Seems like I have about a million retained messages from my sensors etc… Good spot on this thanks