Configuration: MQTT Sensor with Multiple Topics

Hi all. I’m fairly new to HA, and I could use some assistance with configuration syntax. I’m running Home Assistant on an Ubuntu VM, with Mosca for MQTT, and the SmartThings-MQTT-Bridge for using the SmartThings Hub locally. I have two-way communication working from HA to ST and vice versa, and I’m able to control a smart switch locally from HA. So far so good.

I’m struggling a bit with figuring out how to define devices in configuration.yaml, particularly contact/multi-sensors. If I enter:

#Bedroom Multi-sensor from SmartThings
sensor:
  platform: mqtt
  name: "Bedroom Sensor Temperature"
  state_topic: "smartthings/Bedroom Sensor/temperature"
  unit_of_measurement: "F"

I get the intended result, a panel in the overview that displays the temperature of the sensor. Similarly, if I change the topic to “…/contact” and remove the unit of measurement, I get a panel that displays the open/close value of the sensor.

The issue is that I can’t figure out how to get both of those topics to appear. If I place them both in the config file like this:

#Bedroom Multi-sensor from SmartThings
sensor:
  platform: mqtt
  name: "Bedroom Sensor Temperature"
  state_topic: "smartthings/Bedroom Sensor/temperature"
  unit_of_measurement: "F"
sensor:
  platform: mqtt
  name: "Bedroom Sensor Contact"
  state_topic: "smartthings/Bedroom Sensor/contact"

It will only show me the second topic (contact). If I reverse the order, it will only show temperature. I’ve tried getting rid of the second “sensor:” line, I’ve tried both topics under a single entry, no joy. I’m sure it’s a fairly simple correction to make but I haven’t been able to find an example config file to use for reference.

Any hints would be very much appreciated. Thanks!

Edit: Of course I found the solution right after posting this… I’m going to leave the post up in case it helps anyone else.

Here’s the correct syntax:

#Bedroom Multi-sensor from SmartThings
sensor:
  - platform: mqtt
    name: "Bedroom Sensor Temperature"
    state_topic: "smartthings/Bedroom Sensor/temperature"
    unit_of_measurement: "F"
  - platform: mqtt
    name: "Bedroom Sensor Contact"
    state_topic: "smartthings/Bedroom Sensor/contact"

The leading dashes appear to be required, and it isn’t necessary to repeat “sensor:” between the items. You can see the highlighted code and the end result here: https://i.imgur.com/Dch0iPq.png

And yes, my room really is that hot.

1 Like

Based on the YAML syntax errors you made, I recommend you review this section of the documentation. It explains why the data must be structured the way you ultimately figured out through trial and error.

1 Like

Thanks, that’s definitely helpful!