MQTT setup not working as per documentation?

I have followed the temperature and humidity sensor setup as per the mqtt documentation here.

The problem I’m experiencing is that only the temperature sensor definition is being updated when a new temperature value arrives. When I flip the config around, i.e. place the humidity sensor last, then only the humidity sensor is updated. The other value stays as unknown.

Is the doc I followed still valid or has something changed?

The message that I’m publishing to the Mosquitto broker on the HA server from another pi is received in HA as follows.

 Message 0 received on home/garage/sensor1 at 22:56:
{
    "temperature": 26.9,
    "humidity": 53.9
} 

My sensor include file defines my sensor as follows. (I tried many combinations, including placing the config in the configuration.yaml file.)

 
  - platform: mqtt
    state_topic: '/home/garage/sensor1'
    name: 'Garage Humidity'
    unit_of_measurement: '%'
    value_template: '{{ value_json.humidity }}'

  - platform: mqtt
    state_topic: 'home/garage/sensor1'
    name: 'Garage Temperature'
    unit_of_measurement: '°C'
    value_template: '{{ value_json.temperature }}'

I cannot see any messages regarding the matt sensors in the log.

Messages to HA are only published roughly every 5 mins, which is an average of the last couple of sensor readings.

No other messages are being sent other than the message with the temperature and humidity values as above. There are also no other mqtt sensors on the network.

I’m running Hassio (Home Assistant OS?) v2020.12.2

Any idea of what I’m missing?

Use MQTT Explorer to see what is actually being published.
Look to see what your actual topics are, I think you probably want ‘/home/garage/sensor1/temperature’ as an example; but you need to verify it with something like MQTT Explorer.

Remove the leading forward slash ( / ) from the first state topic. So this:

state_topic: '/home/garage/sensor1'

Becomes:

state_topic: 'home/garage/sensor1'

1 Like

Thanks for spotting my mistake and responding so quickly Tom!

I can’t believe the time I wasted on this typo :-/

It also makes perfect sense why swopping the sensors around worked. I only flipped everything below state topic as state_topic was “the same” for both.

1 Like