MQTT discovery with json_attributes

The MQTT autodiscovery is fantastic. But, I am struggling with adding json_attributes to the sensors. The configuration I have looks like this:
name: “Office Temperature”,
state_topic: “tb/office/sensor”,
value_template: “{{ value_json.Temperature }}”,
availability_topic: “tb/office/status”,
payload_available: “Online”,
payload_not_available: “Offline”,
device_class: temperature,
unit_of_measurement: “°C”,
json_attributes:
- “Reboot count”
- “Packet count”
- “Uptime”
- “Gateway”
- “Localtime”
- “Address”
- “Voltage”
- “Humidity”
- “Software version”

The question is how do I jsonify the json_attributes? Tried the following and many variants:
{
“name”: “Office Temperature”,
“state_topic”: “tb/office/sensor”,
“value_template”: “{{ value_json.Temperature }}”,
“availability_topic”: “tb/office/status”,
“payload_available”: “Online”,
“payload_not_available”: “Offline”,
“device_class”: “temperature”,
“unit_of_measurement”: “°C”,
“json_attributes”: “- Humidity - Voltage”
}

Does anyone have the answer for how to format the json_attributes?

This resolved after studying the parsing code.

For future reference, this is the way to do it:
“json_attributes”: “Humidity, Voltage, Gateway”

Before you rely too much on json_attributes, please note that it is marked as deprecated:

https://www.home-assistant.io/components/sensor.mqtt/

Thanks! This must be a pretty new addition. The attributes_topic looks much easier to use :slight_smile:

I have tried to build a mqtt discovery topic for a sensor which sends mqtt data in json and values can be accessed by jsonpath. I tried to follow the instructions here, but failed.

I added this to the configuration.yaml and restarted the docker container

mqtt:
  sensor:
    - name: "WP_control target high"
      state_topic: "WP_control/SET15"
      value_template: "{{ value_json.zone1.heat.target.high }}"
      json_attributes_topic: "tele/sonoff/sensor"
      json_attributes_template: "{{ value_json.zone1 | tojson }}"

    - name: "WP_control target high low"
      state_topic: "WP_control/SET15"
      value_template: "{{ value_json.zone1.heat.target.low }}"
      json_attributes_topic: "tele/sonoff/sensor"
      json_attributes_template: "{{ value_json.zone1 | tojson }}"

After restart, I still cannot see a new mqtt device:

The messages look like this:

You aren’t creating a device, you’re creating a single entity. Check developer tools → states page for your entity. Which should be named sensor.wp_control_target_high