Smartthings MQTT Bridge

also, here is my mosquitto.conf file

/etc/mosquitto/mosquitto.conf

allow_anonymous false
password_file /etc/mosquitto/pwfile
listener 1883
listener 9001 #–> this was 8883 in my last attempt
protocol websockets
user mosquitto
persistence true
persistence_file mosquitto.db
persistence_location /var/lib/mosquitto/
pid_file /var/run/mosquitto.pid

  • is “user mosquitto” line correct, or should that match my “peteusername” from other files
  • what is that second listener port supposed to match up with? 9001 and 8883 bot/h seem to not cause an error, but not sure if those ports are actually talking to anything. Should that match another file?

Output of sudo systemctl status “mosquitto.service -l”:

Hey man. I was having this same problem and I’m not really sure what fixed it but I just did a hard reset of everything including the physical ST hub. Just make sure that your mqtt is talking to HA correctly and that your bridge on your pi is setup and running.

so here are my steps:

reboot pi
start mqtt
start bridge
restart HA
reboot ST hub
pray

haha thanks rvogel. Repeated the steps, but no such luck; maybe I didn’t pray hard enough.

I’m probably going to repeat the full installation from the top, should go quick now that I’m a master of repeating all the in between steps lol.

Man, I’m having a weird bit with my setup as well.

But my issues are to do with switching it off. I have a “Schlage” Z-Wave Wall Plug Dimmer Switch (it’s a rebranded GE / Jasco). Through a bit of trial and error, I discovered I could not turn it off by sending ~/switch/off, but I could ~/level/0 and turn it off.

Weird…

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?