How to get mqtt payload as a sensor value

Hi Friends.

i have built an arduino based temperature sensor (among other functionalities) and am able to get data on my mqtt server. The temperatures are not encoded as JSON rather a simple value say 30.25 degrees under tele/mega-gate/sensors/temp0 topic.

Now, i’m trying to create a sensor in home assistant that will get this value, however all recommendation to do this are based on tasmota or similar where the payloads are encoded as JSON.
image

- platform: mqtt
  state_topic: 'tele/mega-gate/sensors/temp0'
  name: 'HA box temp'
  device_class: temperature
  availability_topic: 'tele/mega-gate/LWT'
  payload_available: "Online"
  payload_not_available: "Offline"
  value_template: '{{ value_json["temp0"] }}'

i cannot get any value from the HA sensor, but of course the arduino and temperature sensors are working normally, posting the temperature readings to MQTT

Remove the value_template option. You are publishing 30.25 to the state_topic so no template is needed to extract it from the payload.

thank you very much :slight_smile: it was simple fix.

1 Like