Parse json data from mqtt

I am trying to create sensors from the mqtt data from another raspberry pi. I can receive the data when listening to the topic in Mosquitto Broker, but I cannot create a yaml file to convert the data to individual sensors. This is the data from the broker.

“time”: “2022-08-24 20:26:24”,
“model”: “Cotech-367959”,
“id”: 83,
“battery_ok”: 1,
“temperature_F”: 72.9,
“humidity”: 76,
“rain_in”: 0.59055,
“wind_dir_deg”: 146,
“wind_avg_m_s”: 0,
“wind_max_m_s”: 0,
“light_lux”: 0,
“uv”: 0,
“mic”: “CRC”

That’s a lot of data in one topic, much of it different. If you’re able to adjust the MQTT message contents, your better route is to break that out into multiple topics, as is typically the route for different pieces of data. IE:

sensors/raspi: ['83']
sensors/raspi/83/model: Cotech-367959
sensors/raspi/83/battery_ok: 1
sensors/raspi/83/temperature_f: 72.9

From there, you can easily use each individual topic as an MQTT sensor in your sensor: section or sensors.yaml file.

Alternatively, you could create Helper inputs for each piece of data from there you want. You could then use an automation with an MQTT trigger to whatever topic that’s writing to, and use Call Service cards to update them. The topic info is available for all actions to use, so you can just filter as like {{ trigger.payload_json['humidity'] }} as the value template to set each helper to. It’s a much messier option to maintain however.

you mean like

  - name: "Temperature"
    state_topic: "theMQTTtopic"
    unit_of_measurement: 'F'
    value_template: "{{ value_json.temperature_F }}"
    unique_id: xx


That worked, thanks for your help.