0

I've created a thermometer sensor using an ESP8166 with MQTT to publish temperature updates. The JSON emitted is in the format:

{
    "temperature": "53.4"
}

In Home Assistant, I created a sensor in configuration.yaml:

sensor:
  - platform: mqtt
    name: Backyard Temperature
    unique_id: a1234
    state_topic: home/temperature
    value_template: '{{ value_json.temperature }}'
    unit_of_measurement: F

The sensor is correctly sending the JSON payload, and MQTT subscriptions running on my desktop are receiving the updates, but the value is never updated on the Home Assistant dashboard (the state remains as the literal "Unknown").

Here's what the rendered group looks like. Odd there's a switch on the group heading. Group rendering

Can anyone see what I'm missing? According to the documentation, I've done everything for this to work.

Jim Marquardt
  • 3,959
  • 1
  • 12
  • 21

2 Answers2

0

I think your state_topic value needs to be in quotes

state_topic: "home/temperature"

at least that is what I do in my HA and it has all the readings.

Here is what my configuration.yaml has:

  - platform: mqtt
    state_topic: "temp/read/Outside"
    value_template: "{{ value_json.temp }}"
    unit_of_measurement: '°F'
    device_class: "temperature"
    name: "Outside Temp"
JD Allen
  • 799
  • 5
  • 12
0

After uninstalling/reinstalling the Mosquitto broker, I realized that I hadn't checked the discovery option. With that set, it is working as expected. D'oh!

Jim Marquardt
  • 3,959
  • 1
  • 12
  • 21