MQTT entity does not show numeric value

Hi all,

I’m trying to integrate a humidity sensor in HA using MQTT. My payload looks like the following (I’m testing it with mosquitto_pub):

mosquitto_pub -h 123.123.123.123 -t garden/humidity/vegetables -m '{"humidity": 87.324, "timestamp": 1745310200}' -u mqtt -P mqtt

My configuration in configuration.yaml looks like this:

mqtt:
  sensor:
    - name: "Veggie garden"
      unit_of_measurement: "%"
      state_topic: "garden/humidity/vegetables"
      value_template: "{{ value_json.humidity | float }}"
      force_update: true

However, when I look at the entity, it does not show anything:

Could somebody please tell me what I’m missing or doing wrong?

Did you restart HA ?
Did you republish the message after restarting ?

Yes I restarted HA, i.e. reread configuration.yaml. I can see that the changes take effect, for example by changing the sensor name. However, extracting the numeric value from the JSON string and setting it as state does not appear to be working

Turns out the problem was in calling mosquitto_pub. When I call it using mosquitto_pub -h 192.168.2.174 -t garden/humidity/vegetables -m '{\"humidity\": 66.666, \"timestamp\": 1745310200}' -u mqtt -P mqtt it works. The difference was the \"…Topic closed

1 Like