Smartthings MQTT Bridge

I have been struggling to get this working over the past week, and have finally figured it out. Posting in case anyone else runs into this issue.

The problem was that I could see the SmartThings switch activity in the smartthings-mqtt-bridge logs, but could not control the SmartThings switch via my HA switch. The HA switch would not react to incoming messages or post to SmartThings.

I was able to see that SmartThings was sending the MQTT states as “smartthings/Living room Lights/switch/state”; however in my HomeAssistant configuration, I had specified the state_topic as “smartthings/Living room Lights/switch” which is consistent with all of the documentation I have been able to find. Changing the state_topic to “smartthings/Living room Lights/switch/state” and the command_topic to “smartthings/Living room Lights/switch/cmd” has finally bridged the gap between my HA switch and SmartThings.

Everything now works as expected. Moral of the story: don’t assume your devices are publishing the same messages as everyone else :slight_smile:

3 Likes

I got this finally working but damn it hurt. Brutal. This stuff isn’t new to me, it’s just there are so many damn steps that have to be just right and you miss one you screwed. Gots to somehow collapse these steps down.

My contribution to the missed steps club was kinda stupid and early on. I didn’t setup the Smart App and select the devices to send notifications from. From the MQTT bridge setup step 6:

“Configure the Smart App (via the Native App) with the devices you want to share and the Device Handler you just installed as the bridge”

In the app, you go to “Add a SmartApp” then scroll down to + “My Apps”. You then select the different devices to get notifications for. Finally “Notify this Bridge” and do the Device Bridge you created in the previous step.

Grrs.

I’m seeing activities in the log for the smartthing-mqtt-bridge and my Sylvannia Zigbee Lightbulb does turn on

When I use the Smartthings App from my phone, I see the following smartthings-mqtt-bridge logs:
0|smartthi | info: Incoming message from SmartThings: smartthings/Front Door Lights/level = 7
0|smartthi | info: Incoming message from MQTT: smartthings/Front Door Lights/level = 7
0|smartthi | info: Skipping duplicate message from: smartthings/Front Door Lights/level = 7
0|smartthi | info: Incoming message from SmartThings: smartthings/Front Door Lights/level = 10
0|smartthi | info: Incoming message from MQTT: smartthings/Front Door Lights/level = 10
0|smartthi | info: Skipping duplicate message from: smartthings/Front Door Lights/level = 10
0|smartthi | info: Incoming message from SmartThings: smartthings/Front Door Lights/level = 100
0|smartthi | info: Incoming message from MQTT: smartthings/Front Door Lights/level = 100
0|smartthi | info: Skipping duplicate message from: smartthings/Front Door Lights/level = 100
0|smartthi | info: Incoming message from SmartThings: smartthings/Front Door Lights/level = 93
0|smartthi | info: Incoming message from MQTT: smartthings/Front Door Lights/level = 93
0|smartthi | info: Skipping duplicate message from: smartthings/Front Door Lights/level = 93
0|smartthi | info: Incoming message from SmartThings: smartthings/Front Door Lights/level = 32
0|smartthi | info: Incoming message from MQTT: smartthings/Front Door Lights/level = 32
0|smartthi | info: Skipping duplicate message from: smartthings/Front Door Lights/level = 32
0|smartthi | info: Incoming message from SmartThings: smartthings/Front Door Lights/level = 100
0|smartthi | info: Incoming message from MQTT: smartthings/Front Door Lights/level = 100
0|smartthi | info: Skipping duplicate message from: smartthings/Front Door Lights/level = 100

But when I use HomeAssistant, the smartthings-mqtt-bridge log shows the following; but my lights does NOT turn on.
0|smartthi | info: Incoming message from MQTT: smartthings/Front Door Lights/level = on
0|smartthi | info: Skipping duplicate message from: smartthings/Front Door Lights/level = on

I’m assuming it is my HomeAssistant configuration is wrong. Here’s a part of my configuration.yaml file:

  - platform: mqtt
    name: "Front Door Lights"
    state_topic: "smartthings/Front Door Lights/level"
    command_topic: "smartthings/Front Door Lights/level"
    brightness_state_topic: "smartthings/Front Door Lights/level"
    brightness_command_topic: "smartthings/Front Door Lights/level"
    payload_on: "on"
    payload_off: "off"
    retain: true

Anyone can provide any helpful hints? I’ve been on this installation for almost 2 weeks now and still can get this to work.

I also noticed the following when I start-up homeassistant:

2017-08-05 13:40:50 ERROR (MainThread) [homeassistant.core] Error doing job: Exception in callback <function async_subscribe.<locals>.async_mqtt_topic_subscriber at 0x73fc52b8>
Traceback (most recent call last):
  File "uvloop/cbhandles.pyx", line 49, in uvloop.loop.Handle._run (uvloop/loop.c:48380)
  File "/usr/lib/python3.6/site-packages/homeassistant/components/mqtt/__init__.py", line 232, in async_mqtt_topic_subscriber
    hass.async_run_job(msg_callback, dp_topic, payload, dp_qos)
  File "/usr/lib/python3.6/site-packages/homeassistant/core.py", line 247, in async_run_job
    target(*args)
  File "/usr/lib/python3.6/site-packages/homeassistant/components/light/mqtt.py", line 230, in brightness_received
    device_value = float(templates[CONF_BRIGHTNESS](payload))
ValueError: could not convert string to float: 'off'

This just confirmed what was happening with my setup. Thanks for that.

1 Like

The error you are seeing is being caused by sending a payload of type string for level instead of a float: such as a number between 0 and 100.

Try changing the component to type “light” instead of type “switch” in your configuration.yaml, and add the brightness_scale option. Reference the below post:

1 Like

Thanks bdgf10! I don’t see the issues in the homeassistant logs any more. Now my next steps is to figure out why my HA is not communicating through smartthings mqtt bridge. From smartthings app I do see activity via through the MQTT bridge.

Thanks @bdgf10 !

You the bomb! I just got my HA talking properly after follow your earlier post about add “state” and “cmd”. Woohoo!!!

Here’ my updated configuration.yaml file:

light:
  - platform: mqtt
    name: "Front Door Lights"
    state_topic: "smartthings/Front Door Lights/switch/state"
    command_topic: "smartthings/Front Door Lights/switch/cmd"
    brightness_state_topic: "smartthings/Front Door Lights/level/state"
    brightness_command_topic: "smartthings/Front Door Lights/level/cmd"
    brightness_scale: 101
    payload_on: "on"
    payload_off: "off"
    optimistic: true
    retain: true
1 Like

Running into another odd issue; not sure if it is related to changing the topics as I mentioned above. The behavior I am seeing is that if I turn on my switch using the physical switch, SmartThings, or Alexa the light will turn on and the HA dashboard updates accordingly. However; after a minute or two, HA sends the off command and turns the switch off. If I turn on the switch with HA, the switch remains on. This strange behavior also happens if I initially turn the switch on with HA and try to turn it off using anything else, HA will send the on command again.

I was thinking it may be a polling issue, but I’m using a Leviton Vizia RF + with instant update so that shouldn’t be an issue…

Any ideas?

Any idea on how to do this on hassio

@noshali I am running on Hassio and besides the issues I have described above, everything seems to be working. There is an addon for the smartthings-mqtt-bridge that someone already created. Just Google for the addon.

1 Like

@bdgf10 I’m having the same issue where I have a ihome switch and it randomly turn off or on. Example, the switch is off and I use Smartthings or iHome native app to turn on the switch, it will turn on. But, after a few minutes it will automaticaly turn off. However, if I turn it on with HomeAssistant, it stays on forever.

To troubleshoot, I shutdown HomeAssistant and try to use the native apps (iHome and/or Smartthings). When I turn it on, it stays on permanently. So, I’m thinking HomeAssistant is the source of where the issue is.

Any ideas how to troubleshoot?

Is there any additional logging I can turn on to troubleshoot? I tried the following:

logger:
  default: critical
  logs:
    homeassistant.components.switch: debug

@kdubmisc I’m facing your exact issue. If I disable the SmartThings-mqtt-bridge then everything works fine, but I’m also thinking it has something to do with state management in HA. I haven’t had time to troubleshoot it much, but will try to look into it soon.

Another question: Did you install the smartthings bridge manually or via an addon?

Post back if you make any progress. I have a feeling it is something simple…

Thinking about it some more, it looks like you and I both appending /state and /cmd to the end of our topics. That might have something to do with it.

@bdgf10 I’m using the docker install version of HA. I’ve used smartthings bridge as addon

I did do some additional troubleshoot. I stop all the services: Mosquitto MQTT and Smartthings Bridge.
I then went to manually delete the mosquitto.db file. After I deleted the mosquitto.db file, i restated HA, started Mosquitto MQTT and Smarthings Bridge.

It seems to be working for the last 4 days so far. Hopefully it remains stable.

Looking for Help :thinking:

I finally got my HA to read the state of the device but I can’t control it through HA. Here is my setup:


Raspberry Pi 3 with Hassio installed


Mosquitto Broker (Hassio plugin)

{
  "plain": true,
  "ssl": false,
  "anonymous": false,
  "logins": [
    {
      "username": "uname",
      "password": "pword"
    }
  ],
  "customize": {
    "active": false,
    "folder": "mosquitto"
  },
  "certfile": "fullchain.pem",
  "keyfile": "privkey.pem"
}

SmartThingsBridge (plugin from here)

{
  "broker_host": "192.168.1.31",
  "broker_port": 1883,
  "preface": "smartthings",
  "state_suffix": "state",
  "command_suffix": "cmd",
  "login": "uname",
  "password": "pword",
  "bridge_port": 8080
}

configuration.yaml (HA config file)

mqtt:
  broker: 192.168.1.31
  protocol: 3.1
  keepalive: 60
  client_id: hass-1
  username: uname
  password: pword

light:
  - platform: mqtt
    name: "Living Room Lamp"
    state_topic: "smartthings/Living Room Lamp/switch/state"
    command_topic: "smartthings/Living Room Lamp/switch/cmd"
    payload_on: "on"
    payload_off: "off"
    retain: true

MQTT-Bridge Device

MQTT Bridge IP Address: 192.168.1.31
MQTT Bridge Port: 8080
MQTT Bridge MAC Address: [my pi mac address]


“Living Room Lamp” is a smart bulb (not a switch). If I turn it on via actiontiles, the switch in HA turns on but I cannot control it from HA.

Does anyone see anything I’m missing?

I have the same vkorn add-on you do. I have an extremely similar issue to you.

Communication has been very one way, state updates from smartthings have been good, HA, reflects them almost instantly. Try to turn the light off in HA and MQTT fires the off cmd to the bridge, but nothing happens except HA flipping the status back to “off” a few seconds later.

info: Subscribing to smartthings/Dining Hall/switch/cmd
info: Incoming message from SmartThings: smartthings/Dining Hall/switch/state = on
info: Incoming message from SmartThings: smartthings/Dining Hall/switch/state = off
info: Incoming message from SmartThings: smartthings/Dining Hall/switch/state = on
info: Incoming message from MQTT: smartthings/Dining Hall/switch/cmd = off
info: Incoming message from MQTT: smartthings/Dining Hall/switch/cmd = off

EDIT:
It’s important to use the correct MAC

MAC address is everything in smartthings, My pi was connected via wi-fi, smartthings wanted to see the wlan0 MAC address of my PI, not the eth0 address. Good Luck!

I have the same issue. Smartthings reports the states, but i cannot change a state from HA to Smartthings.

On top, Smartthings doesnt even show anything in the log if i try to push a command to it.

Did you see my note about the MAC address? Make sure the MAC address in your smartthings MQTT bridge is correct. That was my problem, I had the eth0 MAC address for my raspberry PI when I needed the wlan0 MAC address because my PI was connected wirelessly.

If you don’t have the MAC address in your smartthings MQTT bridge device, nothing will appear in smartthings even though the bridge is receiving/sending messages.

1 Like

I actually just changed it to the wlan0 MAC and it works. Which is weird to me, because my PI is connected via Ethernet & WIFI. Maybe i need to disable the WiFi Part to make it work via Ethernet.