MQTT messages not updating HassIO switch state

Tags: #<Tag:0x00007f20436c8ee0> #<Tag:0x00007f20436c8238>


Hello everyone,
This is my very first post and very first attempts to setup and use HassIO./Home Assistant.
I have experimented for 3 days and so far, I’ve installed and configured (almost successfuly) SSH, Configurator, MQTT Bridge (from Adam’s repo), Mosquitto MQTT broker and all my devices.
It is important to note that my devices are all registered on my Smartthing hub (v3), until I receive my Zigbee dongle. I have used this guide (Anyone integrated Smartthings into Hassio yet?).
So here we go: I can see all my devices in the Home panel of Hassio, all my sensors are sending appropriate data. I can control all my switches. So far so good.
Now the problem: When I switch ON a light with something else than Hassio (Smartthings app, or Google Assistant), the corresponding switch in Assio does not move (it stays OFF). Same thing when I turn something off. I checked the SmarthingsBridge logs, and I can see the topic and command in there. When using MQTTLens connected to my HassiO MQTT broker, I can also see the topics/command going through… But HAssIO does not update the buttons’ state. If there was something wrong between the MQTT broker and the Bridge, I believe I should not be able to control devices from HassIO… so I’m getting crazy. I’ve searched for hours now, so any indication would be greatly appreciated.
Thanks a lot.


You will need to share your MQTT lights configuration if you want some help. It’s probably a typo somewhere. Don’t forget to format your code properly (see message at top of this forum)


Thanks. I should have thought about that :slight_smile:
Here is my configuration file:

  # Name of the location where Home Assistant is running
  name: Home
  # Location required to calculate the time the sun rises and sets
  latitude: xxxx
  longitude: xxxx
  # Impacts weather/sunrise data (altitude above sea level in meters)
  elevation: 0
  # metric for Metric, imperial for Imperial
  unit_system: metric
  # Pick yours from here:
  time_zone: Europe/Paris
  # Customization file
  customize: !include customize.yaml

# Show links to resources in log and frontend

# Enables the frontend

# Enables configuration UI

# Uncomment this if you are using SSL/TLS, running in Docker container, etc.
  ip_ban_enabled: true
  login_attempts_threshold: 5

# Checks for available updates
# Note: This component will send some information about your system to
# the developers to assist with development of Home Assistant.
# For more information, please see:
  # Optional, allows Home Assistant developers to focus on popular components.
  # include_used_components: true

# Discover some devices automatically

# Allows you to issue voice commands from the frontend in enabled browsers

# Enables support for tracking state changes over time

# View all events in a logbook

# Enables a map showing the location of tracked devices

# Track the sun

# Allow diagnosing system problems

# Sensors
  # Weather prediction
  - platform: yr

# Text to speech
  - platform: google
    language: 'fr'

# Cloud

group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml

    title: Configurator
    icon: mdi:wrench

  discovery: true
  discovery_prefix: smartthings
  username: "user"
  password: "pass"

 key: xxxxxxxxxxxxxxxxxxxx

####################################### DEVICES BELOW 

light - plafonnier:
  platform: mqtt
  name: "Plafonnier"
  command_topic: "smartthings/Plafonnier/switch"
  payload_on: "on"
  payload_off: "off"
  retain: true

light - canape:
  platform: mqtt
  name: "Canapé"
  command_topic: "smartthings/Canapé/switch"
  brightness_state_topic: "smartthings/Canapé/level"
  brightness_command_topic: "smartthings/Canapé/level"
  brightness_scale: "100"
  payload_on: "on"
  payload_off: "off"
  retain: true

binary_sensor - portail:
  platform: mqtt
  name: "Portail"
  state_topic: "smartthings/Portail Sensor/contact"
  payload_on: "open"
  payload_off: "closed"
  device_class: opening

sensor - portail - battery:
  platform: mqtt
  name: "Sensor Portail"
  state_topic: "smartthings/Portail Sensor/battery"
  unit_of_measurement: '%'

switch - chauffage enfants:
  platform: mqtt
  name: "Chauffage Enfants"
  command_topic: "smartthings/Chauffage Chambre Enfants/switch"
  payload_on: "on"
  payload_off: "off"
  retain: true

sensor - chambre kids - temperature:
  platform: mqtt
  name: "Sensor Temperature Enfants"
  state_topic: "smartthings/Température Chambre Enfants/temperature"
  unit_of_measurement: '°C'

sensor - chambre kids - humidity:
  platform: mqtt
  name: "Sensor Humidite Enfants"
  state_topic: "smartthings/Température Chambre Enfants/humidity"
  unit_of_measurement: '%'

sensor - chambre kids - battery:
  platform: mqtt
  name: "Sensor Battery Enfants"
  state_topic: "smartthings/Température Chambre Enfants/battery"
  unit_of_measurement: '%'

# Switch portail
  name: Portail
  icon: mdi:gate
  initial: off

When turning the “Plaffonier” light on then off using the Smartthings application, I see the MQTT messages in Smartthings Bridge logs (and the light turns on/off):

info: Incoming message from SmartThings: smartthings/Plafonnier/switch = on
info: Incoming message from MQTT: smartthings/Plafonnier/switch = on
info: Skipping duplicate message from: smartthings/Plafonnier/switch = on
info: Incoming message from SmartThings: smartthings/Plafonnier/switch = off
info: Incoming message from MQTT: smartthings/Plafonnier/switch = off
info: Skipping duplicate message from: smartthings/Plafonnier/switch = off
info: Incoming message from SmartThings: smartthings/Plafonnier/switch = off
info: Incoming message from MQTT: smartthings/Plafonnier/switch = off
info: Skipping duplicate message from: smartthings/Plafonnier/switch = off

I can also see the MQTT messages reaching the MQTT Broker (using MQTTlens)
I hope someone can find the cause…


Personally I would suggest you work on getting your topics to follow best practices on MQTT. Spaces, special characters, etc are not good to have. Keep it simple and keep them to a standard.

I’m confused by your configuration yaml.

Your entities have spaces in them. It’s weird.

You have a brightness state and command on the same topic.

Your “plafonnier” light has a command topic but no state?


and to add to it i’m really not even sure how you aren’t getting tons of config errors since you don’t have any of your entities grouped properly into components.

you should be getting errors saying that, for instance, that it can’t find the component “light - plafonnier:” since it doesn’t exist. and you should be getting similar errors for every device you have.

Are you sure that is your working configuration.yaml file that your HA is running on right now?


I’ll rework it all to remove spaces and special characters.
I have removed the state when it was duplicated with command on the same topic.
When looking at the Bridge logs, I don’t see any state topic at all, only swithc topics…


No error in the log file… Yes I’m sure this is the config I’m running. And all the entities are showing on the home page and I can control every device without problem from HA.
Grouping was an option, but the way I declared devices is documented here: (Style 2)


well there you go. i’ve never seen anyone ever use that style before. TBH, i’m not sure how conducive that style will be to long term growth of your system. Once your configuration.yaml grows to 5000 lines will you be able to split that out easily to different directories/yaml files?


So you recommend style 1 then?
Since I’ll rework the config, I can change that (you made a good point with splitting). But I doubt this is the cause of my problem.


That’s the style I use and I would venture a guess that the vast majority of HA users also use style 1.


I definitely see many problems with your configuration. Luckily it’s been over a year since I wrote that tutorial (which has some mistakes, whoops), so I’ve learned a thing or two. You should try to create a MQTT light or switch using my example below.

First, if you are using @vkorn’s Hassio Smartbridge add-on, you need to recheck your add-on settings. There is a setting called ‘comand_suffix’ and ‘state_suffix’ that you should remember when defining your MQTT switches and lights. My add-on config looks like this.

  "broker_host": "",
  "broker_port": 1883,
  "preface": "smartthings",
  "state_suffix": "state",
  "command_suffix": "cmd",
  "login": "smartthingsbridge",
  "password": "passwordhere",
  "bridge_port": 2080

If you use this add-on setting, then your state and command messages from SmartThings should look like this:

info: Incoming message from MQTT: smartthings/Stairs/level/cmd = 25
info: Incoming message from MQTT: smartthings/Stairs/switch/cmd = on
info: Incoming message from MQTT: smartthings/Stairs/switch/cmd = off
info: Incoming message from SmartThings: smartthings/Stairs/level/state = 44
info: Incoming message from SmartThings: smartthings/Stairs/switch/state = off
info: Incoming message from SmartThings: smartthings/Stairs/level/state = 10

Notice that state and command suffix are defined and applied to the MQTT messages. ‘Stairs’ is a smart bulb that belongs in the Home Assistant light platform. To change brightness level, I need to define the ‘brightness_command_topic’ and ‘brightness_state_topic’. Below is an example of my MQTT light:

- platform: mqtt
  name: "Stairs"  
  command_topic: "smartthings/Stairs/switch/cmd"
  brightness_command_topic: "smartthings/Stairs/level/cmd" 
  state_topic: "smartthings/Stairs/switch/state"
  brightness_state_topic: "smartthings/Stairs/level/state"
  brightness_scale: 100
  payload_on: "on"
  payload_off: "off"  
  • Your Plafonnier light looks like it should be a switch instead. Are you able to change brightness level on this light?
  • Like @flamingmoe said, you did not define state_topic on the Plafonnier light.


Thanks a lot for the advices!!!
I won’t be able to confirm if this works, as I’ve just received a Zigbee dongle so I can get rid of SmartThings and directly integrate with HA.
Again, thanks a lot to everyone for having had a look.