MQTT and JSON.. I know again

Hello, I have googled by bits off and tried many mqtt configs. I’m trying to get some data from a mqtt json event displayed in a graph.

the mqtt configs are in a separate file

The main config file def.

mqtt:
  sensor: !include_dir_merge_list configurations/mqtt

and the file in the above directory

 - name: "Particale Sensor: 10"
   state_topic: "home/pi25/particle_sensor/status"
   unit_of_measurement: ""
   unique_id: "mqtt_particled_10"
   value_template: "{{ value_json.10 }}"
 - name: "Particale Sensor: 2.5"
   state_topic: "home/pi25/particle_sensor/status"
   unit_of_measurement: ""
   unique_id: "mqtt_particled_2_5"
   value_template: "{{ value_json.2.5 }}"

No errors in the log file.

the proof of the data

The output, or lack of it :slight_smile:
image

FYI
The data is also going off to mqtt->telegraf->influx->grafana all ok.

try

    value_template: "{{ value_json['10'] }}"

and

    value_template: "{{ value_json['2.5'] }}"

What is shown in

  • developer tools – status of that entities? Are values shown?
  • in the mqtt implementation, is that sensor shown as entry? are the sensors 2.5 and 10 available there?
  • how is your recorder configuration? Do you have any including/excluding configuration which deactivates the recording of these history events?

@Edwin_D is correct. You can’t use dot notation with numbers, you have to extract the value from the dictionary using get item syntax.

There’s a small typo in his responses though. You have to alternate interior and exterior quotes

    value_template: "{{ value_json['10'] }}"

and

    value_template: "{{ value_json['2.5'] }}"

Ahh, indeed. I corrected it in case some one copies it before reading the fix, but @petro gets the :cake:.

Hello, Thank you ‘all’ very much, worked a treat, still have a long way to go on learning HA

1 Like