[SOLVED] How to use json_attributes? (e.g. MQTT Sensor)

@mattp May I suggest marking this post as solved?

I have raised a Pull request with an example to the MQTT Sensor page

The example sensor below shows a configuration example which uses JSON in the state topic to add extra attributes. It also makes use of the availability topic. Attributes can then be extracted in Templates;
Example to extract data from the sensor below
'{{ states.sensor.bs_client_name.attributes.ClientName }}'

# Example configuration.yml entry
sensor:
  - platform: mqtt
    state_topic: "HUISHS/BunnyShed/NodeHealthJSON"
    name: "BS RSSI"
    unit_of_measurement: "dBm"
    value_template: '{{ value_json.RSSI }}'
    availability_topic: "HUISHS/BunnyShed/status"
    payload_available: "online"
    payload_not_available: "offline"
    json_attributes:
      - ClientName
      - IP
      - MAC
      - RSSI
      - HostName
      - ConnectedSSID  

See this example in use: Genestealer/Home-Assistant-Configuration

3 Likes