Smartthings MQTT Bridge

I just remembered I had this exact same issue when I migrated from a Pi1 to a Pi3. I forgot to update the MAC address in the ST IDE MQTT-Bridge device config options. After I made the changes, it still wasn’t working. I had to delete the SmartApp instance and then setup a new one. Maybe that’s your problem.

1 Like

I was thinking that as well.

Here are the steps I took on my last build. Hopefully they’re useful to someone.

Build Image from latest raspian and update it

sudo apt-get update; sudo apt-get upgrade

Install All In One homeassistant installer

wget -Nnv https://raw.githubusercontent.com/home-assistant/fabric-home-assistant/master/hass_rpi_installer.sh && chown pi:pi hass_rpi_installer.sh && bash hass_rpi_installer.sh

Reset mosquitto password before we get started. For this example, use username pi and password mqttpass.

sudo mosquitto_passwd /etc/mosquitto/pwfile pi
sudo systemctl restart mosquitto.service

Setup smarthings-mqtt-bridge via npm

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

setup pm2 to run the processes

sudo npm install pm2 -g

create and edit smartthings-mqtt-bridge config

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

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 https://www.npmjs.com/package/mqtt#mqttclientstreambuilder-options
  username: pi
  password: mqttpass

  # Port number to listen on
  port: 8080

Configure the SmartThings Device handler, Device, and SmartApp using steps outlined in https://github.com/stjohnjohnson/smartthings-mqtt-bridge1

Device Settings
IP: raspberry pi IP
MAC: Raspberry pi MAC
Port: 8080

Add mqtt to HomeAssistant config configuration.yaml

mqtt:
  broker: localhost
  port: 1883
  client_id: home-assistant-1
  username: pi
  password: mqttpass

Add switches to their own file, or configuration.yaml

- platform: mqtt
  name: "MQTT Dining Room Light"
  state_topic: "smartthings/Dining Room Light/switch"
  command_topic: "smartthings/Dining Room Light/switch"
  payload_on: "on"
  payload_off: "off"
  retain: true

start the bridge

pm2 restart smartthings-mqtt-bridge

restart HASS

sudo systemctl restart home-assistant.service

That should do it. You may want to sudo reboot

6 Likes

I’ve been following this thread and @AceoStar instructions as above but I’ve hit a brick wall. I’m running Hassbian and all is set up as above, but running ‘pm2 logs smartthings-mqtt-bridge’ results in ‘Error: listen EADDRINUSE :::1883’. This ‘sudo lsof -i TCP:1883’ results in the following;

COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
mosquitto 490 mosquitto 3u IPv4 10345 0t0 TCP *:1883 (LISTEN)
mosquitto 490 mosquitto 4u IPv6 10346 0t0 TCP *:1883 (LISTEN)
mosquitto 490 mosquitto 5u IPv6 41596 0t0 TCP localhost:1883->localhost:56404 (ESTABLISHED)
hass 14259 homeassistant 7u IPv6 42713 0t0 TCP localhost:56404->localhost:1883 (ESTABLISHED)

My level of experience on this is fairly limited and if anyone could suggest how I can permanently remedy the problem, I’d appreciate the help. I can kill some or all of the PIDs but the problem returns upon reboot. If I had hair, it’d be torn out by now.

Problem resolved!
Funnily enough, when I said “all is set up as above” I was entirely wrong and had the wrong port in the config.yml
Thanks for all who contributed here. Much appreciated.

That’ll get ya every time! Glad its working out :slight_smile:

Hey this actually came at the perfect time because I have been meaning to do this for the longest time but have not been able to until now! I am following what @AceoStar has posted above and I am coming across a couple of problems though, so maybe you guys could help me with that.

When I try to run “pm2 logs smartthings-mqtt-bridge” I get an error saying that smartthings-mqtt-bridge was not found. I try running “sudo npm install -g smartthings-mqtt-bridge” again and I am also able to edit and view the config file that is made from it. Any ideas on what was wrong? Also, how can I ensure that mosquitto is running properly? I am a complete newbie, so any and all ideas and steps are much appreciated :slight_smile:

@AceoStar: This is a great tutorial. I want to add my small contribution, as it isn’t something I’ve seen written anywhere.

Make PM2 start the MQTT-bridge on boot
(only tested on the Pi AIO installer)

First make sure the bridge is running in PM2:
pm2 start smartthings-mqtt-bridge

Save the process to the dump file:
pm2 save

Set PM2 to start on boot:
pm2 startup -u pi

I received this message:
[PM2] Init System found: systemd [PM2] You have to run this command as root. Execute the following command: sudo env PATH=$PATH:/usr/local/bin pm2 startup systemd -u pi --hp /home/pi

So execute the command:
sudo env PATH=$PATH:/usr/local/bin pm2 startup systemd -u pi --hp /home/pi

I hope this works for you guys, let me know if there’s a better way!

1 Like

@hoffsta Thanks for your post! Would that help the situation I am in as well? I’m not with my pi to try it at the moment

Before running pm2 logs smartthings-mqtt-bridge are you running pm2 start smartthings-mqtt-bridge?

First thing I’d do is look in /usr/local/bin and see if pm2 and smartthings-mqtt-bridge are installed there. I had an issue with my version of NodeJS not installing packages to that location. I had to remove and reinstall node and npm from a different method.

As for mosquitto, you can do a quick test. Open two ssh windows, in one, type:
mosquitto_sub -d -u username -P password -t dev/test

In the other type:
mosquitto_pub -d -u username -P password -t dev/test -m "Hello world"

Does “Hello World” pop up in the first window?
Of course this depends on you having created a password file in mosquitto. If you haven’t, omit the -u and -P arguments.

@hoffsta oh wow I never even knew I had to start running smartthings-mqtt-bridge. I was following @AceoStar step for step with everything that he wrote, when I get home with the pi I will try starting it and let you know how it goes.

Also another quick question: since I’m installing everything on my pi, when it says
` mqtt:

Specify your MQTT Broker’s hostname or IP address here

host: mqtt://localhost`

do I replace all instances of “localhost” with the IP address of my pi?

You shouldn’t need to if you’re on the same Pi. “localhost” ‘127.0.0.1’ or the actual IP address should all work.

@hoffsta Thank you so much for your help! I got it working! Your post about having it run on reboot actually came in very handy today, so thank you very much. How am I able to add a slider so that I could change the brightness of a lightbulb?

Awesome, glad I could help!

light:
  platform: mqtt
  name: "Bedroom Light Switch"
  state_topic: "smartthings/Bedroom Light Switch/switch"
  command_topic: "smartthings/Bedroom Light Switch/switch"
  brightness_state_topic: 'smartthings/Bedroom Light Switch/level'
  brightness_command_topic: 'smartthings/Bedroom Light Switch/level'
  brightness_scale: 100
  qos: 0
  payload_on: "on"
  payload_off: "off"
  optimistic: false

You won’t see the brightness slider on the front end unless you click into the card for the light. Look into building custom input sliders if you want to see that instead of the on/off switch. I haven’t worked on any of that yet.

Thank you! It works exactly how I always wanted it to. Thank you very much

1 Like

I have been trying to setup the bridge. I have followed @AceoStar steps. When I enter pm2 start smartthings-mqtt-bridge I get /usr/bin/env: node: No such file or directory would anyone understand why? Or what I am doing wrong?

sudo ln -s “$(which nodejs)” /usr/local/bin/node

2 Likes

Thank you!

First off, I would like to thank everyone here (and on other communities). There is so much great and helpful information here. Secondly, this is the first time I’ve posted to any forum ever so please bear with me. I believe this is the best place to ask this question but let me know if I’m wrong.

My end goal is to not have to rely on IFTTT (way too slow) using the ESP8266 for custom control of “Smartthings” devices…I also happen to think MQTT is pretty neat…

I currently have a RPi3 with Raspian (Jessie), Home Assistant, mosquitto, samba, and the ST-mqtt-bridge installed. All seem to work great on their own, except HA is acting a little weird since I re-imaged away from Hassbian. HA will always fail to execute services (such as restart) and always says I have an “Invalid Config” for “mqtt:”. Otherwise it controls devices that it finds just fine.

Since AceoStar seems to have a similar setup to me, I have followed his posts (specifically on Jan 24) as closely as possible. This should give you an idea of what I have done already.

Now for my problem: I have no idea what my problem is. I have checked every .yaml, .yml, and .config file multiple times and they all seem to be what I need. I have updated everything to latest versions. As I said before, each program seems to run fine on the pi with no errors. To me, it seems like they are just not linked together correctly as nothing I do influences anything else. The exception being mosquitto which seems to talk to itself - I type “mosquitto -v” in one putty terminal and when I publish in another terminal it acknowledges the publish and…does nothing else.

I will happily provide any other info, I am just not sure how much/what to provide now. So let me know!

Any additional help will be greatly appreciated as I have already read every ST, HA and MQTT forum and spent days dobugging (yes, I mean “do”) and trying to fix my dobugs. I think I’ve just reached the edge of my understanding and now I’m just jumping off!

Thanks!

Edit: I have figured it out. I found out later that everything was talking by a video from BRUH explaining how to setup mosquitto to talk to HA. I then found a comment on the HA “Smarter SmartThings with MQTT and Home Assistant” walk through saying: “Your MQTT bridge and SmartThings IDE should be using port 8080. Home Assistant config uses 1883.” I found out that my mosquitto.conf file was configured on port 1883 instead of 8080. I’m now up and running!

Thank you all for your contributions here!

OMG I have been beating my head against the wall all morning with this… Thanks!!!