Smartthings MQTT Bridge

So, maybe I’m not fully getting this type of setup.

I’m pretty sure I have everything setup correctly but I am not seeing my new Zwave switch show up in HA. I’ve followed this guide, but I chose to not use docker and also chose to use mosquitto vs the other mosca or whatever it’s called.

Will the devices not get discovered in this fashion and I must just add the code into the configuration.yaml file?

Sorry if I am being a bit slow on this process.

Thanks

Got it working now. Needed to restart my bridge then hass. Once that was done my zwave switch showed up in HA. I then took that entity name and placed it in my den group. Viola. “Drops Mic”

I have followed theses instructions but I can’t get this working:

I see this in the smartthings log:
fb924f2a-9e21-4514-bc9e-729c66b9aef0 7:59:44 PM: debug Forwarding device event to bridge: {"path":"/push","body":{"name":"Living Room","value":"inactive","type":"motion"}}

A bit of help would be very greatful

Looks good, does your MQTT Server receive the message? Do you have HA MQTT components setup listening for the event on the MQTT Server?

No. That’s the problem. Or at least I can’t see it doing that.

I think so.

Here is my configuration.yaml:

mqtt:
broker: 192.168.1.25
port: 1883
client_id: home-assistant-1
username: xxx
password: xxx

And my Smartthings device settings

ip string 192.168.1.25
mac string xxxxxxxxxx
port string 8080

mqtt-bridge-configuration ~/config.yml

mqtt:

Specify your MQTT Broker’s hostname or IP address here

host: mqtt://localhost

Preface for the topics $PREFACE/$DEVICE_NAME/$PROPERTY

preface: smartthings

Suffix for the state topics $PREFACE/$DEVICE_NAME/$PROPERTY/$STATE_SUFFIX

state_suffix: state

Suffix for the command topics $PREFACE/$DEVICE_NAME/$PROPERTY/$COMMAND_SUFFIX

command_suffix: cmd

Other optional settings from mqtt - npm

username: xxx
password: xxx

Port number to listen on

port: 8080

You also need to setup the corresponding device. Based on what you’ve provided it should be something like:

  binary_sensor:
    - platform: mqtt
      name: Living Room MultiSensor Motion
      state_topic: "smartthings/Living Room/motion"
      command_topic: "smartthings/Living Room/motion"
      device_class: motion
      payload_on: "active"
      payload_off: "inactive"
      retain: true    

I’ve got that already setup but as a sensor and not as a binary_sensor (I tried it as a binary sensor but I would not appear in the HA interface)

Here is what I get in the states tab:

sensor.living_room_multisensor_motion / unknown / friendly_name: Living Room MultiSensor Motion

My host doesn’t include mqtt:// - I also use the ip address but I don’t think that should cause any problem.

Here are all the steps I did to try to get this working. Would someone mind telling me what I did wrong?

(Also please note that, as I am based in the UK, I use the graph-eu01-euwest1 SmartThings API.)

Setup

I started off by installing the sd card flashed with the Hassbian image.

Then I did:

sudo apt-get update
sudo apt-get upgrade

Then to install MQTT:

sudo ./hassbian-scripts/install_mosquitto.sh

I entered a username ‘pi’ and a password ‘secret’ when prompted.

I then installed node.js

wget https://nodejs.org/dist/v4.3.2/node-v4.3.2-linux-armv6l.tar.gz
tar -xvf node-v4.3.2-linux-armv6l.tar.gz
cd node-v4.3.2-linux-armv6l
sudo cp -R * /usr/local/

Then installed smarthings-mqtt-bridge via NPM

sudo apt-get install npm
sudo npm install -g smartthings-mqtt-bridge

And then installed pm2 via NPM

sudo npm install pm2 -g

I then edited the smartthings-mqtt-bridge config

sudo cp /usr/local/lib/node_modules/smartthings-mqtt-bridge/_config.yml ~/config.yml
sudo nano ~/config.yml

---
mqtt:
  # Specify your MQTT Broker's hostname or IP address here
  host: 192.168.1.25
  # Preface for the topics $PREFACE/$DEVICE_NAME/$PROPERTY
  preface: smartthings

  # Suffix for the state topics $PREFACE/$DEVICE_NAME/$PROPERTY/$STATE_SUFFIX
  # state_suffix: state
  # Suffix for the command topics $PREFACE/$DEVICE_NAME/$PROPERTY/$COMMAND_SUFF$
  # command_suffix: cmd

  # Other optional settings from https://www.npmjs.com/package/mqtt#mqttclients$
  username: pi
  password: secret

  # Port number to listen on
  port: 8080

I then setup the Device Handler and SmartApp following: GitHub - stjohnjohnson/smartthings-mqtt-bridge: Bridge between SmartThings and MQTT

Device Settings
IP: 192.168.1.25
MAC: ma:ca:dr:es:s
Port: 8080

And then added this to the HA configuration.yaml

mqtt:
  broker: 192.168.1.25
  port: 1883
  client_id: home-assistant-1
  username: pi
  password: secret

And then added a switch to the configuration.yaml

switch:
  - platform: mqtt
    name: "MQTT Left Lamp"
    state_topic: "smartthings/Left Lamp/switch"
    command_topic: "smartthings/Left Lamp/switch"
    payload_on: "on"
    payload_off: "off"
    retain: true

Then

pm2 restart smartthings-mqtt-bridge
sudo systemctl restart home-assistant.service

I also did a reboot at the end and checked that both services were running

Logs

So here are the SmartThings logs when the switch is turned on (the smarttapp logs):

653e9a65-edb7-4603-b11e-6476d4a52d09  12:41:58 PM: debug Forwarding device event to bridge: {"path":"/push","body":{"name":"Left Lamp","value":"on","type":"switch"}}
653e9a65-edb7-4603-b11e-6476d4a52d09  12:41:57 PM: debug Forwarding device event to bridge: {"path":"/push","body":{"name":"Left Lamp","value":"turningOn","type":"switch"}}

And here are the SmartThings logs when the switch is turned on (the device logs):

a61bb2ab-d453-471b-8d20-f0a187df4895  12:41:58 PM: debug Sending '{"path":"/push","body":{"name":"Left Lamp","value":"on","type":"switch"}}' to device
a61bb2ab-d453-471b-8d20-f0a187df4895  12:41:57 PM: debug Sending '{"path":"/push","body":{"name":"Left Lamp","value":"turningOn","type":"switch"}}' to device

The HA log:

17-03-11 12:35:36 WARNING (Thread-11) [homeassistant.components.recorder] Ended unfinished session (id=6 from 2017-03-11 11:04:59.344912)
17-03-11 12:35:36 WARNING (Thread-11) [homeassistant.components.recorder] Found unfinished sessions

And the pm2 logs:

pm2 logs smartthings-mqtt-bridge

[PM2] Spawning PM2 daemon with pm2_home=/home/pi/.pm2
[PM2] PM2 Successfully daemonized
[TAILING] Tailing last 15 lines for [smartthings-mqtt-bridge] process (change the value with --lines option)
[STREAMING] Now streaming realtime logs for [smartthings-mqtt-bridge] process

So what should I do to fix this?
I see the switch in the HA UI but turning it on or off does nothing (same if I turn it on or off via the SmartThings app)
As I already said at the begging: as I am based in the UK, I use the graph-eu01-euwest1 smartthings api. So if any of the scripts use the datbase I might need to change the api?
Also there is no portforwarding to do if I am correct?

2 Likes

This kind of sounds like the MQTT Bridge smart app isnt working quite right. Check out this MQTT viewer plugin. https://chrome.google.com/webstore/detail/mqttlens/hemojaaeigabkbcookmlgmdigohjobjm?hl=en Use that to connect to your mqtt sever and observe all traffic. Then, hit a light connected to your hub. Did it send a mqtt event? Did you make sure to go into the Smart App settings and select all of your lights then hit save?

Correct, no port forwarding is needed unless you’re trying to do something beyond what we’ve talked about.

1 Like

If Mosquitto is running on the same device as Home Assistant, change the MQTT Broker host to mqtt://localhost in the Smarthings MQTT config.yml.

Make sure the Device Network ID is the MAC Address of the machine running the MQTT Bridge, except remove the colons.

These are the steps I have saved to set this up (excluding the SmartApp Part).
sudo apt install nodejs
sudo npm install -g smartthings-mqtt-bridge
sudo npm install pm2 -g
sudo ln -s /usr/bin/nodejs /usr/bin/node
pm2 start smartthings-mqtt-bridge
pm2 startup
RUN COMMAND
pm2 save
sudo nano config.yml : Change HOST/PASSWORD

1 Like

I too am in the UK and having problems getting this to work reliably.

I run MQTT on a pi, have installed a simulated device on the UI and can happily turn on and off my light after a ST hub reboot. But then - after just a few minutes - it stops working.

Looking at the logs it seems that when it works I get logged a “Parsing” debug notice (see attached redacted). When it stops working this “Parsing” notice no longer appears in the logs.

Any suggestions as to what may be going wrong?

In case it helps, here is the device log showing the before and after the failure …

Hi,

I’m getting my bridge configured too and when I go to add a device I’m not sure what to call it in the topics. How would you call a door open/close sensor in configuration.yaml?

example:
“smartthings/Front Door/switch”

Is that correct for a door sensor? I haven’t seen any list of what these devices should be called. Is there one?

Hi,

im really thankful for your app, it was the only way i could get to home assistant and keep my devices as they are, but i have a problem i started few days ago and i cannot figure out how to configure this device in hass :confused: thats a fibaro rgbw controller. i would love some help.

The bridge for my other stuff works like a charm :slight_smile:

My Bridge was working fine but today it just started acting strange. I am not able to switch on or off lights from home-assistant. It shows the light switch on. I can see it in smartthings logs and event in mqtt that command is received but light doesn’t turn on. If i do that same from smarthtings the light turn on and even the home-assistant is updated with current state. Any ideas where should i start looking.

I think they are updating the servers for us and the problem is on the smartthings side. The st community reports that strange thing are happening :confused:

After spending three days and some nights over it, I think it’s a good time to ask for some help.
I guess most of my issues are trivial but I am new to some of these technologies and issues are probably basic.
Anyway, I must have it working and not going to give up easy :slight_smile:

Installed the HASSbian RPI with its built-in MQTT. Works great. Have an Arduino communicates with it. Noted that out of the box it is already using three ports: 8123, 1883 and 8080.

Tried the NPM method described here.

  1. Installed NPM.
  2. Noted that I must install the package using sudo.
  3. Noted that I get warnings from the kind of: wanted: {"node":">= 0.12"} (current: {"node":"0.10.29","npm":"1.4.21"})
  4. Trying running just $ smartthings-mqtt-bridge as described wasn’t recognzied by RPi, so I improvised sudo npm run smartthings-mqtt-bridge which ended up with:
    npm ERR! Error: ENOENT, open ‘/home/pi/package.json’
    npm ERR! Additional logging details can be found in:
    npm ERR! /home/pi/npm-debug.log

boo.

Next, tried the Docker approach:

  1. Installed Docker, pulled the package. till here all good.
  2. Trying running the container with -p 8080:8080 ends with error on these ports already in use, which they are.
  3. Altering to other ports (9090:9090 for example) initiate the container with no errors, but with no great success either: The container doesn’t really run: hitting sudo docker ps comes back empty.
  4. To better understand what’s going on I tried to get it attached with: sudo docker run -it --name=“mqtt-bridge” -v /opt/mqtt-bridge:/config -p 9090:9090 stjohnjohnson/smartthings-mqtt-bridge
    which brings back:
    standard_init_linux.go:178: exec user process caused “exec format error”

boo2 to me.

Any help will be awesome!!! :grinning:

I’m not sure what to do here. My smartthings-mqtt-bridge works fine when run on its own but when I try and load it with pm2 I’m getting an error that it doesn’t exist.

pi@hassbian:/ $ pm2 restart smartthings-mqtt-bridge
Use --update-env to update environment variables
[PM2][ERROR] Process smartthings-mqtt-bridge not found

Any help would be great here. I’d love to be able to get this fixed so I can auto-start it.

Well I started from scratch with a new Hasbian build and updated node before installing everything and I seem to be able to load the bridge in PM2. I have a new issue now though. For some reason no matter what I do the config.yml stays in my pi’s root directory. I can’t seem to get it moved and when the bridge loads up nothing works. I’m not sure its even reading from the config.

pi@hassbian:~ $ sudo cp /usr/local/lib/node_modules/smartthings-mqtt-bridge/_config.yml ~/config.yml
cp: cannot stat ‘/usr/local/lib/node_modules/smartthings-mqtt-bridge/_config.yml’: No such file or directory

Bridge appears to load fine its just not working. Any help would be great.

pi@hassbian:~ $ pm2 restart smartthings-mqtt-bridge
Use --update-env to update environment variables
[PM2] Applying action restartProcessId on app [smartthings-mqtt-bridge](ids: 0)
[PM2] smartthings-mqtt-bridge
┌─────────────────────────┬────┬──────┬───────┬────────┬─────────┬────────┬─────┬───────────┬──────────┐
│ App name │ id │ mode │ pid │ status │ restart │ uptime │ cpu │ mem │ watching │
├─────────────────────────┼────┼──────┼───────┼────────┼─────────┼────────┼─────┼───────────┼──────────┤
│ smartthings-mqtt-bridge │ 0 │ fork │ 23134 │ online │ 107 │ 0s │ 66% │ 12.6 MB │ disabled │