Smartthings MQTT Bridge

I’ll post the rest of my files also so we can see if maybe I’m just overlooking something…
configuration.yaml


mqtt:
broker: 192.168.0.200
client_id: home-assistant-1
username: !secret mqtt_username
password: !secret mqtt_password
port: !secret mqtt_port

switch:

  • platform: mqtt
    name: “Bed Fan Light”
    state_topic: “smartthings/Bed Fan Light/switch”
    command_topic: “smartthings/Bed Fan Light/switch”
    brightness_state_topic: “smartthings/Bed Fan Light/level”
    brightness_command_topic: “smartthings/Bed Fan Light/level”
    brightness_scale: 100
    qos: 0
    payload_on: “on”
    payload_off: “off”
    optomistic: false

config.yml

mqtt:
host: 192.168.0.200
preface: smartthings
username: username
password: password
port: 8080

mosquitto.conf
(should user be the username the same as in the mqtt setup, the !secret mqtt_username?)

allow_anonymous false
password_file /etc/mosquitto/pwfile
user mosquitto
listener 1883
listener 8883
protocol websockets
persistence true
persistence_file mosquitto.db
persistence_location /var/lib/mosquitto/
pid_file /var/run/mosquitto.pid

Anything else I can post that would help?

I believe that defines the user the service runs as… mine is the same.

Your configuration.yaml from HA should use the username/password from your mosquitto setup as referenced from your /etc/mosquitto/pwfile.

What port are you using? this should be 1883 based on your mosquitto config…

Yeah the username/password are the same in config.yml, configuration.yaml. And I can see the username in /etc/mosquitto/pwfile and the hashed password

Sorry, should have included that. But yes I have it set as 1883.

Does the client_id matter? I don’t remember setting that anywhere but there (and I just copied it from somewhere else)

Also copied the mosquitto.conf from somewhere, do I need both listeners 1883 and 8883?

Believe it just identifies where the messages come from and should not have any impact… my is ‘home-assistant’.

Everything looks good and matches my setup.

My setup has been working for a while but I do remember having similar issues getting it to initially connect. Not sure how I resolved.

One is for websockets the other is not, again shouldn’t cause an issue. I have two as well.

Does the bridge or broker give any meaningful log?

What commands should I use to view those??

Hmm, depends on where they are outputing…

my mosquitto has:

log_dest stderr
log_type all
connection_messages true
log_timestamp true```

so I look at stderr, you can change that to an actuall log file like ```/etc/mosquitto/mosquitto.log```

my bridge logs to a error.log, events.log, and access.log file in my config directory.

Hmm not really seeing anything in there. I only have an events.log and it’s pretty empty.
Having trouble finding the mosquitto logs but sudo systemctl status mosquitto.service -l has stuff like

Jul 14 18:20:04 hassbian mosquitto[6755]: 1500056404: Sending PUBLISH to home-assistant-1 (d0, q0, r0, m0, ‘smartthings/Bed Fan Light/switch’, … (2 bytes))

Not seeing anything in ST yet though

Got mosquitto.log file working… Just restarted mosquitto and it logged this

1500058655: mosquitto version 1.4.12 (build date Thu, 25 May 2017 22:38:16 +0100) starting
1500058655: Config loaded from /etc/mosquitto/mosquitto.conf.
1500058655: Opening ipv4 listen socket on port 1883.
1500058655: Opening ipv6 listen socket on port 1883.
1500058655: Opening websockets listen socket on port 8883.
1500058656: New connection from 192.168.0.200 on port 1883.
1500058657: Socket error on client , disconnecting.
1500058657: New connection from 192.168.0.200 on port 1883.
1500058657: New client connected from 192.168.0.200 as home-assistant-1 (c1, k60, u’myUsername’).
1500058657: Sending CONNACK to home-assistant-1 (0, 0)
1500058657: Received SUBSCRIBE from home-assistant-1
1500058657: smartthings/Car Charger/switch (QoS 0)

Could that socket error be all the problem? How can I figure out what the actual error is?

It also has things like

1500058855: Received PUBLISH from home-assistant-1 (d0, q0, r0, m0, ‘smartthings/Bed Fan Light/switch’, … (2 bytes))
1500058858: Received PUBLISH from home-assistant-1 (d0, q0, r0, m0, ‘smartthings/Bed Fan Light/switch’, … (2 bytes))
1500058867: Received PUBLISH from home-assistant-1 (d0, q0, r0, m0, ‘smartthings/Bed Fan Light/switch’, … (2 bytes))
1500058898: Received PINGREQ from home-assistant-1
1500058898: Sending PINGRESP to home-assistant-1
1500058958: Received PINGREQ from home-assistant-1

Looks like HA is connecting, but I don’t see your bridge. Did your Bridge get setup on the SmartApp to indicate where the SmartApp should send updates? If so, did you try rebooting ST?

Appears so from your earlier screenshot. I notice you have it setup for certain modes… are you in one of those right now? Try removing the modes from the smartapp.

:smiley:

It looks like one of my switches is working now! But for some reason the ‘Bed Fan Light’ one doesn’t work. In HA the switch is in the off position even though it is actually on, and when I toggle it to on it just switches back over.

Edit: Never mind it all seems to be working now! Thank you so much for all your help. I’m not exactly sure what fixed it but it works. haha

Happy to help. I went through the same initial pain. Now that it’s up and running, it should be smooth sailing. I haven’t had a problem since.

Just wanted to post and say I’ve been trying to get this working for about 3 weeks now and finally got it going today. All of you have been a great help. The simplest thing did it for me and that was just restarting my ST hub. life is funny.

Anyhow, I’m now trying to set up a zigbee button and zigbee dimmable lightbulbs connected to my st hub. Does anyone have an example of what that should look like in configuration.yaml?

You’ll be using the MQTT components so it will look something like this:

    - platform: mqtt
      name: "Eave Lights"
      state_topic: "smartthings/Eave Lights/switch"
      command_topic: "smartthings/Eave Lights/switch"
      payload_on: "on"
      payload_off: "off"
      retain: true

I tried that but it didn’t seem to work for the button. Do i need to use “smartthings/iris smart button/button”? Also, would I put all my devices under the -platform mqtt header or do I need to separate them somehow?

I solved my problem just in case anyone comes across this. I wasn’t able to add the button to my main UI but i can monitor it and create actions based off of it through an automation like so

- alias: test button push
  trigger:
    platform: mqtt
    topic: smartthings/Iris Smart Button/button
  action:
    service: homeassistant.toggle
    entity_id: switch.ge_12721_lighting_control_duplex_receptacle_switch
1 Like

I had the same issue! After a bunch of installs and uninstalls of different versions, this command seemed to be the one that finally got me the 0.12 version: Unfortunately I am having trouble finding the post that got me there, but going back through my command router commands here is the order, after uninstall:

curl -sL https://deb.nodesource.com/setup_0.12 | sudo -E bash -
sudo apt-get install -y nodejs

then followed by the pm2:
sudo npm install pm2 -g
sudo npm install -g smartthings-mqtt-bridge

Then running the pm2 command gives you a splash screen:
pm2 restart smartthings-mqtt-bridge
—>

                    -------------

/\\\\\\_/\\/\\/\\\\_
_/\/////////\_/\\\
/\\\/\///////\_
/\_
/\_/\//\_/\//\_/////\_
_/\\\\\\/
/\\///\/\/
/\_
/\/
/\/////////
/\_
///\/
/\_/\//_____
/\_
/\_////\_/\//_____
/\_
/\_/\_/\/________
/\_/\_/\_/\\\\\\\_
_////////////////////////

     Welcome to most Advanced Process Manager for Node.js

A few months late, but maybe will help someone else, at least

Can someone help me with this issue I’m having. I’ve been trying to get this bridge set up the past few days and can’t quite get it. Getting close thanks to this thread though!

  • My issue is that I can control my GE lights through the SmartThings app, and it shows up on my HA homepage, AND I am seeing the messages coming across the cmd sceen when I do “pm2 logs smartthings-mqtt-bridge” (image below). But, when I try to control from HA screen or sending a mosquitto_pub message it does not work. Also, when I control on the webpage, it doesn’t work but it self switches its display back to match the actual light state. So I feel like I’m so close!

    Another weird thing is that when I do the HA switch using “on” message, it reports “Passing level instead of switch on”

  • the “info: Incoming message from SmartThings:” lines work, but the “MQTT” lines do not - do your guys pm2 loggs look similar?


-getting these red lines before it turns green and connects, but I don’t know how to look into that error

configuration.yaml:

mqtt:
broker: 127.0.0.1
port: 1883
client_id: home-assistant-1
keepalive: 60
username: petesusername
password: secretpass
protocol: 3.1
discovery: true
discovery_prefix: smartthings

switch: !include_dir_list switches/

light:

  • platform: hue
    host: 192.168.1.73

light 2: !include_dir_list lights/

LightFile:

platform: mqtt
name: “MQTT Dining Room LightSwitch”
state_topic: “smartthings/Dining Room LightSwitch/switch”
command_topic: “smartthings/Dining Room LightSwitch/switch”
brightness_state_topic: “smartthings/Dining Room LightSwitch/level”
brightness_command_topic: “smartthings/Dining Room LightSwitch/level”
brightness_scale: 100
brightness_value_template: ‘{{ value }}’
payload_on: “on”
payload_off: “off”
qos: 0
optimistic: false
retain: true

~/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 mqtt - npm

username: peteusername
password: secretpass

Port number to listen on

port: 8080

note: I used the hassbian all in one installer… Alosm I had to do some weird node uninstalls and installs to get the 0.12 node version in order to install pm2 and smartthings-mqtt-bridge. So hopefully that didn’t screw with anything.

Thanks for any help!