Smartthings MQTT Bridge

Anyone using the MQTT Bridge (github.com/stjohnjohnson/smartt … qtt-bridge) to control the Smartthings hub with HA? I’ve setup my own mqtt server (mosquitto), but still having trouble getting it to connect to the ST Device, so any help would be greatly appreciated.

1 Like

I just spent the last couple of days getting mine set up with Mosquitto with no previous MQTT experience. My Mosquitto Broker is on my OpenWRT router and I used nvm/pm2 for the Node.js bridge app.

-Your HA configuration.yaml needs to point to the IP/Port of your Mosquitto broker.
-Your MQTT Bridge device on your ST needs to point to the ip/MAC/Port of the Node.js/Docker app.
-You Node.js/Docker app needs to point to your Mosquitto broker.

I would first try and get topics populating on the Node.js app and work from there. Every event will be visible if you tail the logs. With PM2 you jsut run pm2 logs smartthings-mqtt-bridge. IDK how with Docker. Once you can see the events coming in the name of your devices and their options will be printed in clear text on the log, which makes configuring the configuration.yaml much easier.

Here is an excerpt from my configuration.yaml:

mqtt:
broker: 192.168.1.1
port: 1883
client_id: home-assistant-1
keepalive: 60

lock:

  • platform: mqtt
    name: “Front Door Lock”
    state_topic: “smartthings/Front Door Lock/lock”
    command_topic: “smartthings/Front Door Lock/lock”
    payload_lock: “locked”
    payload_unlock: “unlocked”
    retain: true

and my config.yml:
mqtt:
# Specify your MQTT Broker’s hostname or IP address here
host: 192.168.1.1
# Preface for the topics $PREFACE/$DEVICE_NAME/$PROPERTY
preface: smartthings

Port number to listen on

port: 1883

and my IDE settings:
ip string 192.168.1.14
mac string ##:##:##:##:##:##
port string 1883

other than HA, nothing seems to be taking to each other… here is the tail of my events.log for mqtt-bridge

2016-03-19T23:42:58.775Z - info: Starting SmartThings MQTT Bridge - v1.2.0 2016-03-19T23:42:58.779Z - info: Loading configuration 2016-03-19T23:42:58.785Z - info: Loading previous state 2016-03-19T23:42:58.785Z - info: Perfoming configuration migration 2016-03-19T23:42:58.788Z - info: Saving current state 2016-03-19T23:42:58.790Z - info: Connecting to MQTT at 192.168.0.90:1883

To me, it looks like the bridge is trying to connect to my broker, but nothing ever happens. The IP and port shown in the log are correct for my mqtt broker, but nothing ever shows up in that log. Both are running on the same machine. Mqtt of port 1883 and bridge on port 8787. Also, nothing appears to be coming over to the bridge from the bridge device on ST, but it is pointing to the correct ip and port in the device ide.

It seems like your broker isn’t connecting to your bridge. What does you log for your broker look like? for verbose output start mosquitto with:

# mosquitto -v

That should output every event and connection attempt that goes to your broker. If you assign a specific client_id to your HA in the configuration.yaml you should be able to tell easily that HA connects. Or just follow the one that appends “paho” to the messages, as HA uses python for its MQTT and the bridge is in node.js. The other client should be your bridge. I’m not 100% sure if both lines are necessary, but I was also having trouble connecting my bridge to the broker. The solution was to configure mosquitto to:

allow_anonymous = true allow_zero_length_clientid = true

I’ve now got the Bridge connected to Broker, bu apparently my issue is with the Bridge Device talking to the Bridge running on my server. The settings in the Device (IP, Port, MAC) are all correct, and I have my devices I want to control added in the Smart App, yet still no love. Nothing is coming through to the Broker. Only thing I have seen so far could be that since the Bridge is running in Docker, should I use the docker0 MAC instead of the actual ethernet card MAC? Totally at a loss as to where to go now.

I set mine up just yesterday. You have to use the MAC address of the machine, not of the docker container. The thing that was breaking fir me is that I was starting my MQTT topics with a slash because the example had it when in fact you shouldn’t use one. So instead of “/smartthings/Fireplace Lights/switch” I had to use “smartthings/Fireplace Lights/switch” and it worked beautifully. I sent a PR to fox the blog post.

1 Like

I’ve finally tracked my problem to a socket error when the bridge connects to the mqtt server, Now I just have to figure out WHY. All of my subs are named correctly. I wish it was that easy!! LOL

So I am still having issues getting this setup and running. The bridge is connected to MQTT and it APPEARS that HA is connected to MQTT, although I am not 100% sure of that. I see messages coming over from smartthings in the MQTT log, but when I click on my Hall Light in HA, nothing happens. I also have HA setup to show my power usage and inside temp , but they are blank even though I can see the messages in the MQTT log coming over from smartthings. All my configs seem to be correct, but it’s just not working.

HA and MQTT and the broker are all running on the same server. I have tried using the IP address, as well as “localhost” where called for.

configuration.yaml

mqtt:
  broker: 192.168.0.90
  port: 1883
  client_id: hass
  keepalive: 60

 sensor:
    platform: mqtt
     state_topic: "smartthings/CT100 Thermostat/temperature"
    name: "Indoor Temp"
    qos: 0
    unit_of_measurement: "°F"
    value_template: '{{ value.x }}'

  sensor 3:
    platform: mqtt
    state_topic: "smartthings/Aeon Home Energy Meter/power"
    name: "Power Usage"
    qos: 0
    unit_of_measurement: "Watts"
    value_template: '{{ value.x }}'

  light:
    platform: mqtt
    name: "Hall Light"
    state_topic: "smartthings/Hall 1/switch"
    command_topic: "smartthings/Hall 1/switch/set"
    brightness_state_topic: "smartthings/Hall 1/level"
    brightness_command_topic: "smartthings/Hall 1/level/set"
    state_value_template: "{{ value_json.state }}"
    brightness_value_template: "{{ value_json.brightness }}"
    payload_on: "ON"
    payload_off: "OFF"
    optimistic: false
    qos: 0

mosquitto.log

1460265298: New connection from 192.168.0.90 on port 1883.
1460265298: New client connected from 192.168.0.90 as hass (c1, k60, u'glenn').
1460265300: Socket error on client hass, disconnecting.
1460265302: New connection from 192.168.0.90 on port 1883.
1460265302: New client connected from 192.168.0.90 as hass (c1, k60, u'glenn').
1460265494: New connection from 192.168.0.90 on port 1883.
1460265494: New client connected from 192.168.0.90 as mqttjs_398dae5b (c1, k10, u'glenn').
1460265921: Saving in-memory database to /var/lib/mosquitto/mosquitto.db.
1460266773: New connection from 192.168.0.53 on port 1883.
1460266773: New client connected from 192.168.0.53 as glenn (c1, k60, u'glenn').
1460266981: Client hass disconnected.
1460266982: New connection from 192.168.0.90 on port 1883.
1460266982: New client connected from 192.168.0.90 as hass (c1, k60).
1460267722: Saving in-memory database to /var/lib/mosquitto/mosquitto.db.

Hi Guys, Pretty new to HA but trying to get ST and MQTT flowing properly…

I have the smarttihngs mqttbridge listening fine.

info: Starting SmartThings MQTT Bridge - v1.3.3
info: Loading configuration
info: Loading previous state
info: Perfoming configuration migration
info: Saving current state
info: Connecting to MQTT at mqtt://192.168.1.116:1883
info: Configuring autosave
info: Configuring API
info: Listening at http://localhost:8080

as you can see… also when checking logs from mosquitto it shows its connected. But i am not getting anything but ping req and responses in Mosquitto logs, I checked ST ide and mac addresses and IP’s are fine. any suggestions?

I should probably update this. All is running as it should now. The only thing I havig an issue with is autostarting the script on boot. Tried pm2, tried systemctl in systemd, tried the Startup Programs from the GUI in Ubuntu 15.10. All are failing.

I’m struggling with this too … The issue seems to be that the network isn’t fully up when Mosquitto starts, I am trying to move from dhcp to a fixed ip but haven’t got it working yet.

Please help out a total newb:

I’m having problems with every aspect of this, primarily because I don’t know my way around linux at all. I installed the bridge and launched it via PM2 but the logs are showing errors:

info: Starting SmartThings MQTT Bridge - v1.3.4
0|smartthi | info: Loading configuration
0|smartthi | info: Loading previous state
0|smartthi | info: Perfoming configuration migration
0|smartthi | info: Saving current state
0|smartthi | info: Connecting to MQTT at mqtt://127.0.0.1
0|smartthi | info: Configuring autosave
0|smartthi | info: Configuring API
0|smartthi | Error: listen EADDRINUSE :::1883
0|smartthi |     at Object.exports._errnoException (util.js:1026:11)
0|smartthi |     at exports._exceptionWithHostPort (util.js:1049:20)
0|smartthi |     at Server._listen2 (net.js:1262:14)
0|smartthi |     at listen (net.js:1298:10)
0|smartthi |     at Server.listen (net.js:1376:9)
0|smartthi |     at Function.listen (/usr/local/lib/node_modules/smartthings-mqtt-bridge/node_modules/express/lib/application.js:617:24)
0|smartthi |     at setupApp (/usr/local/lib/node_modules/smartthings-mqtt-bridge/server.js:383:13)
0|smartthi |     at /usr/local/lib/node_modules/smartthings-mqtt-bridge/node_modules/async/lib/async.js:718:13
0|smartthi |     at iterate (/usr/local/lib/node_modules/smartthings-mqtt-bridge/node_modules/async/lib/async.js:262:13)
0|smartthi |     at /usr/local/lib/node_modules/smartthings-mqtt-bridge/node_modules/async/lib/async.js:274:29

Here is my config.yml

mqtt:
# Specify your MQTT Broker's hostname or IP address here
host: 127.0.0.1
# 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: xxxxxx

# Port number to listen on
port: 1883

Second problem is that I don’t understand the instructions on how to edit the parameters for the device type on the ST IDE. What does this mean:
** Important: make sure you set the Hub in the device settings! it's a non-optional field but we can't work without it.

Also, where do I make these changes inside the device type?
Configure the Device Type (via the IDE) with the IP Address, Port, and MAC Address of the machine running the Docker container

preferences {
        input("ip", "string",
            title: "MQTT Bridge IP Address",
            description: "MQTT Bridge IP Address",
            required: true,
            displayDuringSetup: true
        )
        input("port", "string",
            title: "MQTT Bridge Port",
            description: "MQTT Bridge Port",
            required: true,
            displayDuringSetup: true
        )
        input("mac", "string",
            title: "MQTT Bridge MAC Address",
            description: "MQTT Bridge MAC Address",
            required: true,
            displayDuringSetup: true

Do I change the “ip”, “port”, and “mac” above?

Thanks!

I’ve been beating my head against a wall on this for a bit as well. Smartthings is at the center of my system, so I’m anxious to get it up and going so I can start moving functionality over to hass :slight_smile: Alas, I can’t get it going either .

I’ve tried a ton of different options, but for simplicity, I’ll show you everything I’ve done from start to finish. This is a ground zero install on Raspberry Pi. There are currently no errors, but I can’t see any events in any of the logs that I’ve checked. Any debug steps would be appreciated, I’d love to get this going and update the docs. I’d be happy to run through it on gitter some weeknight if that’s easier :smiley:

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
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 /usr/local/lib/node_modules/smartthings-mqtt-bridge/config.yml
sudo nano /usr/local/lib/node_modules/smartthings-mqtt-bridge/config.yml

mqtt-bridge-configuration /usr/local/lib/node_modueles/smartthings-mqtt-bridge/config.yml

mqtt:
  # Specify your MQTT Broker's hostname or IP address here
  host: 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: 1883

** 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

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

#Device Settings

IP: raspberry pi IP
MAC: Raspberry pi MAC
Port: 1883

Logging. On physical press of dining room light

IDE - MTTQ Bridge Log
4a29a366-0fa9-4d6e-a3a9-758909fb6001 9:55:04 PM: debug Forwarding device event to bridge: {“path”:"/push",“body”:{“name”:“Dining Room Light”,“value”:“on”,“type”:“switch”}}

3 Likes

have you gone through this article it really helped me get it working after about 2 weeks of trying

Check the MQTT bridge port number, it should not be 1883. If you have not changed the bridge port, it should be 8080.

The broker is listening on 1883, the MQTT bridge port should listen on another port (same port as listed in the SmartThings device)

re:@richardholst Yes I’ve been using that as a guide, yet somehow, I still managed to mix up the ports, which thankfully @hongtat caught.

Thanks everyone. I think you solved at least one problem, I was using the wrong ports. I did not change the mosquitto starting port, so I think you’re correct. that it should be 8080. I applied the following changes and rebooted, but I’m still seeing the same thing. I added a bit more debug into below my config.

config.yml mqtt-bridge config

mqtt:
    # Specify your MQTT Broker's hostname or IP address here
    host: 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

#Device Settings via IDE

ip	string	raspberry pi IP
mac	string	raspberry pi MAC
port	string	8080

#configuration.yml HomeAssistant configuration

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

switch configuration

- 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  

#Debug Info

Pressing the switch in HomeAssistant doesnt send anything to any of the logs. Any tips on additional debugging I can do to help see what’s going on?

#Live logging in smartthigns ide on physical button press
This seems to indicate that the device at least sent something over

bdbdc8c3-bb55-46d1-a1ad-91b5a3fbe9cd  7:16:44 PM: debug Patched device state.
bdbdc8c3-bb55-46d1-a1ad-91b5a3fbe9cd  7:16:43 PM: debug Post the device state to server: 97bd6613-a8b6-4d93-9c60-a4a0d9925788
bdbdc8c3-bb55-46d1-a1ad-91b5a3fbe9cd  7:16:43 PM: debug Detected state change: 97bd6613-a8b6-4d93-9c60-a4a0d9925788
4a29a366-0fa9-4d6e-a3a9-758909fb6001  7:16:43 PM: debug Forwarding device event to bridge: {"path":"/push","body":{"name":"Dining Room Light","value":"on","type":"switch"}}
9a87fbdb-c520-41e4-bd21-592f1721d170  7:16:43 PM: debug Sending '{"path":"/push","body":{"name":"Dining Room Light","value":"on","type":"switch"}}' to device

When I connect a desktop MQTT client (MQTTLens) to mosquitto from my desktop, I can view the messages being sent from Smartthings to MQTT, so I think I can assume that hass and mqtt portion is correct.

#running logs to check the output

pm2 logs smartthings-mqtt-bridge
[STREAMING] Now streaming realtime logs for [smartthings-mqtt-bridge] process
0|smartthi | info: Starting SmartThings MQTT Bridge - v1.3.4
0|smartthi | info: Loading configuration
0|smartthi | info: Loading previous state
0|smartthi | info: Perfoming configuration migration
0|smartthi | info: Saving current state
0|smartthi | info: Connecting to MQTT at mqtt://mqtt

Shouldnt that last line say something more like Connecting to MQTT at localhost or mqtt://localhost?

Try

  • Restart all daemons
  • On & off the switch in HA whether it can on/off in ST - you should be able to find the logs in ST ide.
  • Test mosquitto_pub -h 127.0.0.1 -t "smartthings/Dining Room Light/switch" -m "on" or “off” whether it updates in HA

Thanks again. I did the following.

sudo reboot

then restarted the bridge since it doesnt auto boot

pm2 start smartthings-mqtt-bridge

I tested the switches in HA. They do not update the Live Logs for MQTT device in the smartthigns IDE. I can however, see these messages when viewing from a MQTT desktop client, shown above.

Next, I manually tested the publish, specifying the fake credentials I’m using.

mosquitto_pub -h 127.0.0.1 -P mqttpass -u pi -t "smartthings/Dining Room Light/switch" -m "on"

Yes, this updated the value in home assist like we were hoping, so it seems like HA and MQTT are fine. :slight_smile:

I think it’s just the bridge and Smartthings. But the MQTT bridge is definitely showing activity in smartthings IDE, its just not showing actions from HA when I press the button. I assume its trying to publish changes it sees via the smart app.

hmm. I just re-read the note about authentication not being supported a year ago… Is anyone actually using this with auth?

I don’t use auth.

What’s the best way to turn it off in Mosquitto?

allow_anonymous true

?