New MQTT config (json_attributes_topic)

Hi,

I have some mqtt sensors, but in HA 0.85.0, there is a new way to configure the old json_attributes list.
Is there any example to migrate to the new way??

I receive this warning in log:

configuration variable "json_attributes" is deprecated, replace with "json_attributes_topic"

But, if I change only this name, I receive this:

Invalid config for [sensor.mqtt]: value should be a string for dictionary value @ data['json_attributes_topic']. Got ['name', 'mac', 'discovered_devices']. (See ?, line ?). Please check the docs at https://home-assistant.io/components/sensor.mqtt/

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.