Quantcast
Channel: Configuration - Home Assistant Community
Viewing all articles
Browse latest Browse all 106579

Json attributes template for mqtt sensor?

$
0
0

'Ello,

Quick question : I have a sensor sending values through mqtt to HA. Here’s an example payload :
Topic : random/confidential

{"DeviceId":"Meter 3","Time":"2025-01-06 02:47:41","D31":"58318.84","created_at":"2025-01-06 02:47:42"}

In HA’s config file I created a sensor like so :

mqtt:
  sensor:
    - name: "Meter 3"
      expire_after: 55
      unique_id: 3
      state_topic: "random/confidential"
      value_template: "{{value_json.D31}}"
      json_attributes_topic: "random/confidential"
      json_attributes_template: //not sure

I’m able to see D31 values no problem - but I also want to create 2 additional attributes : DeviceId (named as “Meter no.”) and Time (named as “EST”) to show as attributes of the Meter 3 entity.

I’m not sure how to use the “json_attributes_template” command for this.

I tried this :

mqtt:
  sensor:
    - name: "Meter 3"
      expire_after: 55
      unique_id: 3
      state_topic: "random/confidential"
      value_template: "{{value_json.D31}}"
      json_attributes_topic: "random/confidential"
      json_attributes_template: >
        {"Meter no." : {{value_json.DeviceId}},
          "EST" : {{value_json.Time}}}

But that did nothing - I can still see D31 values but not those other attributes (DeviceId and Time) in the entity card.

Thanks.

2 posts - 2 participants

Read full topic


Viewing all articles
Browse latest Browse all 106579

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>