MQTT Discovery json_attribute_topic not supported

HI I have been refactoring the code for all my devices to support discovery and have noted that the json_support_topic is not available to the dicovery process (or I am doing something wrong).

This is not causing a problem as I can still access the attributes and use the data in automations and in Lovelace, it just not as user friendly.

is json_attribute_topic not supported then in MQTT Discovery? That’s a shame. Was planning to use it to handle large payloads of multiple values without having to a create a /config topic for each of them.

I had to think when I posted this question. I now use the native api to communicate with my local devices.

you can have a look at this https://github.com/petergridge/ha_monitor it may help you.

According to the documentation, it is supported by MQTT Discovery.

Thanks, @123 - I should have checked the doc first. It does need updating and the examples are misleading.

My use case is that I have 60 sensors that I want to automatically created in HA via MQTT. I don’t want to create individual homeassisant/xx/config topics for each of them so now using json_attributes to have them all listed as individual attributes under a single sensor state/object. It kinda works but displaying the data in lovelace is tricky as you can’t use the entities card and now have to individually list them. In any case I couldn’t get the json_attribute_template to work either. I wish the examples would be more clear and show real data.

Here’s an example:

This is how you would manually define a sensor that uses json_attributes_template.

## Designed to receive a payload like this:
## {"used_space": 25, "sys_clock_speed": 1500, "cpu_temp": 43.0, "voltage": 0.8500, "cpu_load": 1.25, "memory": "False", "swap": "False"}
## Demonstrates how to re-map the JSON data's key names to new attribute names
  - platform: mqtt
    name: "Test Sensor"
    state_topic: "test"
    value_template: "{{ value_json.cpu_load }}"
    json_attributes_topic: "test"
    json_attributes_template: >-
      { "used": {{value_json.used_space}},
        "speed": {{value_json.sys_clock_speed}},
        "temp": {{value_json.cpu_temp}},
        "voltage": {{value_json.voltage}},
        "memory": "{{value_json.memory}}",
        "swap": "{{value_json.swap}}" } 

Here’s how you could use a script to define the same sensor via MQTT Discovery. Note how the double-quotes used in json_attributes_template must be escaped.

#script:
  create_test_sensor:
    sequence:
      - service: mqtt.publish
        data:
          topic: homeassistant/sensor/test/config
          retain: true
          payload: >
            {
              "name": "Test Sensor",
              "state_topic": "test",
              "value_template": "{{ value_json.cpu_load }}",
              "json_attributes_topic": "test",
              "json_attributes_template": "{ \"space\": {{value_json.used_space}}, \"speed\": {{value_json.sys_clock_speed}}, \"temp\": {{value_json.cpu_temp}},  \"voltage\": {{value_json.voltage}}, \"memory\": \"{{value_json.memory}}\", \"swap\": \"{{value_json.swap}}\" }"
            }

I ran the script, it created sensor.test_sensor, then I published the sample payload (shown below) and it was successfully received and corresponding attributes were created:

Screenshot from 2020-09-02 10-42-55

Payload:

{"used_space": 25, "sys_clock_speed": 1500, "cpu_temp": 43.0, "voltage": 0.8500, "cpu_load": 1.25, "memory": "False", "swap": "False"}