A little guide on integrating smartthings and homeassistant (hassbian)

Here is a guide on integrating smartthings and homeassistant (hassbian)
I tried many guides that just didn’t work, so after a lot off time trying to get this to work i figured i can save someone else all that hassle i hade.

1: grab your raspberry pi 3b and install Hassbian using Etcher
Link: https://www.home-assistant.io/docs/installation/hassbian/installation/
Link:https://etcher.io/

2: download a ssh: Putty
Link:https://www.putty.org/

3: check what ip that your raspberry have: You can do this by entering your router or use
your phone and Fing app, or use: https://www.advanced-ip-scanner.com/

4: start putty, enter the ip of your raspberry pi: exempel: 192.168.1.33

5: in the console window: enter: pi as user
and: raspberry as password

6: now type: passwd and enter the default password: raspberry
then enter a password you like, this need to be typed 2 times

7: update software using this comands, one at the time
sudo apt-get update
then when its fincht type:
sudo apt-get upgrade
(you need to enter Y when you get the questone)

8: then when its finicht type: sudo reboot
the device will reboot and you need to connect using putty again:
dont forget that you changed the password above so now its: user pi password: what you entered

ok time to install some stuff.

9:first: install mqtt broker using this command.
sudo apt-get install mosquitto mosquitto-clients

10:
now we adding as password to protect it, observe that you need to enter a name after /pwfile
exempel:sudo mosquitto_passwd -c /etc/mosquitto/pwfile YOUR NAME

sudo mosquitto_passwd -c /etc/mosquitto/pwfile

then enter a password when your prompt:

11: Modifying homeassistant .yaml:

typ: cd /home/homeassistant/.homeassistant
then: sudo nano configuration.yaml

this have now opened the config file for home assistant:

i added my config after line:“customize: !include customize.yaml”
enter the config so it looks like this:

“customize: !include customize.yaml”

mqtt:
broker: localhost
port: 1883
protocol: 3.1
keepalive: 60
client_id: smartthings
username: username you entered in stage:10
password: Password you entered in stage : 10

12: now press ctrl X then press Y and Enter to save the file

Observe that spacing does matter in homeassistant,
so for example: mqtt: needs o be to the left and the next line
needs to be 2 spaces from the left, otherwise homeassistant wont start.

13: Install npm:
sudo apt-get install nodejs nodejs-legacy npm

14: install pm2:
sudo npm -g install pm2

(dont worry if you get some errors, and the installation takes some time)

15: Install the mqtt-bridge
sudo npm -g install smartthings-mqtt-bridge

16: Configure the bridge by doing this, one line at the time:

cd /opt
sudo mkdir mqtt-bridge
sudo chown pi:pi mqtt-bridge
cd mqtt-bridge
pm2 start smartthings-mqtt-bridge

17: after starting mp2 above, it will create a file we need to modify
sudo nano config.yml

Modify the file as following:

on the line host: host: mqtt://localhost

on the lines username and password: remover # so it looks like this (remember the spacing rules)

Other optional settings (dont touch this line)
username: USERNAME FROM STEPP: 10
password: UR PASSWORD FROM STEPP:10

18: now save this file by pressing: ctrl x the y and enter

19: restart mp2:
pm2 restart smartthings-mqtt-bridge

29: then run this 3 lines one at the time:

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

ok, now the are a big risk that you have gotten a error after installing pm2 that states that you need to run:

sudo systemctl daemon-reload
and the ui for home assistant isn’t loading. if so just do this steps:

first run: sudo systemctl daemon-reload
then do a reboot by doing: sudo reboot
connect again using ssl (putty) login and follow this guide:

only use the text inside " "
First, cd to system by doing:
1:“cd /etc/systemd/system”
then:
2:“sudo nano home-assistant@homeassistant.service”
this opens a empty fil: past this lines, all text inside inside " "

3:
"[Unit]
Description=Home Assistant
After=network.target

[Service]
Type=simple
User=%i
ExecStart=/srv/homeassistant/bin/hass -c “/home/homeassistant/.homeassistant”

[Install]
WantedBy=multi-user.target"

4: then press “ctrl+x” and then pres “y” and “enter”
after this do:
5: “sudo systemctl --system daemon-reload”
6: Now use: “sudo systemctl start home-assistant@homeassistant”
and your home assistant should work again.

ok you have now installed mqtt-bridge on your raspberry pi, but you need to do some more stuff.
We need to install a device handler in smartthings, and a smart app,
and you also need to manually enter al devices from smartthings that you like to use in homeassistant.

Let’s get started:

30:first: gå to: https://account.smartthings.com/login?redirect=https%3A%2F%2Fgraph-eu01-euwest1.api.smartthings.com%2Flocation%2Flist

if you haven’t got a developer account you need to create one, its just to sign up for one.

31:when you logged in: go to “device handler” and click on “create new device handler”
then click on “from code”

and paste all lines from this link:


stjohnjohnson/smartthings-mqtt-bridge/blob/master/devicetypes/stj/mqtt-bridge.src/mqtt-bridge.groovy
/**

  • MQTT Bridge
  • Authors
  • Copyright 2016
  • Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except
  • in compliance with the License. You may obtain a copy of the License at:
  •  http://www.apache.org/licenses/LICENSE-2.0
    
  • Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
  • on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
  • for the specific language governing permissions and limitations under the License.
    */

import groovy.json.JsonSlurper
This file has been truncated. show original
32: then click “save” and then “publish” for me

33: then click on: “my smart apps”
34: then click on “new smartapp”
35:then click on “from code” and paste al lines from this link:


stjohnjohnson/smartthings-mqtt-bridge/blob/master/smartapps/stj/mqtt-bridge.src/mqtt-bridge.groovy
/**

  • MQTT Bridge
  • Authors
  • Copyright 2016
  • Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except
  • in compliance with the License. You may obtain a copy of the License at:
  •  http://www.apache.org/licenses/LICENSE-2.0
    
  • Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
  • on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
  • for the specific language governing permissions and limitations under the License.
    */
    import groovy.json.JsonSlurper
    import groovy.json.JsonOutput
    This file has been truncated. show original
    36: click on, “my devices” and look for “MQTT BRIDGE”
    37: klick on it
    38: klick “edit” and enter as foling:

1:NAME. MQTT Bridge
2:Label: MQTT Bridge
3:Device network id: ENTER YOUR RASPBERRY PI MAC ADDRESS: exempel:
B827EBFE100C (you can find it the same way you found the ip address in step: 3
4:TYPE: MQTT Bridge
5:Vertion: Publish
6: Hub: your hub

39: klick update

40: now klick back in the browser
41: click: Preferences (edit)
42: enter your info in the fields:

1: Ip adress of your raspberry pi: exempel: 192.168.1.33
2: port number of the broker: 8080
3: mac adress of the raspberry pi: exempel: B8:27:EB:FE:10:0C

43: klick save.

44: now open smartthings classic app on your phone.
and click on “Things” you should see MQTT Bridge now.

klick on it and go to “smartapps” you should see 2 lines: MQTT Bridge and the name off your smart app, for exempel “hass” , klick on “hass” scroll to the bottom and klick on “notify this bridge”
klick on, your bride. then click on one switch you like to use (using switch in the exempel)

45:klick save and then back,
46: klick on the small wheel on top right
47: check so your info is corekt:

for exempel:

Give your device a name: MQTT Bridge
MQTT Bridge Ip Adress: 192.168.1.33 (ip to your raspberry pi)
MQTT Bridge Port: 8080
MQTT Bridge MAC ADDRESS: B8:27:EB:FE:10:0C (your mac address)

klick save:

Ok, we are now going to ad the switch you shoes in the app:

in ssh: type: cd /home/homeassistant/.homeassistant
then: sudo nano configuration.yaml

now we are back in the config file for homeassistant and we can now ad the switch:
this is a exempel below, you need to ad your switch, so check the exact name
and path to your device: i added my switch after mqtt service as exempel:

mqtt:
broker: localhost
port: 1883
protocol: 3.1
keepalive: 60
client_id: smartthings
username: YOUR USERNAME
password: YOUR PASSWORD

switch:

platform: mqtt
name: “Byro Stora Sovrummet”
state_topic: “smartthings/2:Byro Stora Sovrummet/switch”
command_topic: “smartthings/2:Byro Stora Sovrummet/switch”
payload_on: “on”
payload_off: “off”
retain: true

after this is done: klick ctrl x and then y and enter to save the file

then do
1:sudo systemctl restart mosquitto.service
2:pm2 restart smartthings-mqtt-bridge
3:sudo systemctl restart home-assistant@homeassistant.service

now open your browser and go to homeassistant ui, and test the switch,
if homeassistant doesn’t start, you have done a typo in the config file,
remember, every space matters.

EDIT: After updating homeassistant, the mqtt-bridge stopped working. this is how i fixed it.
if you followed the guide above just do this steps

1: connect using ssh: och login using your user and password
2: sudo apt-get update
3: sudo apt-get upgrade
4: curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
5: sudo apt-get install nodejs
6: sudo nano /config.yml
this opens a file, enter the same things in this file, as you did in stepp: 17 &18 above. (on the lines: host, user, and password)

after you saved the file using ctrl x y enter
1:sudo systemctl restart mosquitto.service
2:pm2 restart smartthings-mqtt-bridge
3:sudo systemctl restart home-assistant@homeassistant.service

and now it should be back to normal.

//Regards
Ps: sorry for the bad grammar,

8 Likes

Great guide.
I would recommend hassio for newbies however.
Especially for those who only uses windows as their os

true, i started to use hass,io but since i got a raspberry pi 3b, i hade to use hassbian since hass.io doesn’t support raspberry pi 3b for now. now i really like it, but i will probably try hass.io when they release it for 3b

1 Like

Thanks for writing up this tutorial! It was an amazing help!

One question though, how did you find the config for your example switch? I’m not sure where to get that part. I’ve configured the rest and I can see it polling.

Hi im glad you find it useful.
that depends, do you mean how to find the name for the different devices or do you mean were you find out what to ad after
Device name/? (switch/light/pull and so on)

Am I supposed to come up with the name or use the name from the ide? Are there specific fields to be used for any of those? Or do I get the values from another source? Also, I found that I was getting errors after updating the configuration file in home assistant with the MQTT section. Do you have an example with the formatting? What I put was MQTT on the top line to the left and side and then all the other lines below it I did two spaces indented. Is that correct?

Thank you so much for this guide? I have had no end to trouble trying to get this to work with HASS. I have considered selling my smartthings devices!

I have had success with your guide up until the point of the smartapp in Samsung.
In the classic mobile app (iOS), under “My Home”, Things “MQTT Bridge”, it shows as connected (OK), if I select it and then select “SmartApps” is says “No Installed Smartapps”.
I have reinstalled the smartapp from code several times and it hasn’t helped.
My NodeJS smartthings-mqtt-bridge does not show any communications, however I can see it connecting to my local mosquitto server, I can also see events from HASS, just not Samsung.

Any ideas??

1 Like

hi, i use the logg on home-assistant to see what the names are, In the samsung app when you decided what devices and funktion that should be pusht to home-assistant, start with one device, then go to the logg and check the name being received from smartthing, i normaly flipp the switch a couple of times to get the different states. then if its a light i put it under light on home assistant like this.
platform: mqtt
name: “Byro Stora Sovrummet” (HERE YOU CAN CALL IT WHAT YOU LIKE, and this is what you will see)
state_topic: “smartthings/2:Byro Stora Sovrummet/switch” (THIS IS THE NAME FROM THE LOGG)
command_topic: “smartthings/2:Byro Stora Sovrummet/switch” (This IS THE NAME FROM THE LOGG)
payload_on: “on” (THIS IS THE STATE), payload on lights turns on)
payload_off: “off” (state oFF, light turns off)
retain: true ( THAT IT SHOULD REMEMBER THE STATE IT WAS ON IF THE POWER GOES OUT)

Hi, this is not for Hass.io, only hassbian. Use this instead.
https://github.com/vkorn/hassio-addons/tree/master/smartthings

much easier since basically all will be done for you.
you only need to install, mqtt, sett a name and password and point the bridge to it.

in the smart app, it sound like you installing it more then one time, after installing it go to, the developer site on samsung and edit the info there (adding mac number and so on) Then click on the House icon in your phone and scroll down until you see MQTT Bridge or what you called it, open it and check so all info is ok, when your done it should connect to home-assistant. If it doesn’t work for you i can make guide with images as soon as i have the time, //Regards

Thanks. I am not using Hassio. But Raspbian stretch with hass installed manually.

I tried deleting everything (device handler, device and smartapp). I created the handler first, from code, then the device, I used the eth0 MAC for the device network ID. Once publishing I then edited the IP (192.168.1.9) put the port in (8080) and the same MAC as before.

Again I see the device in the classic smartthings app. The new one states that I cannot connect.

When I look at my smartthings-mqtt-bridge.

    root@controller:~# smartthings-mqtt-bridge
info: Starting SmartThings MQTT Bridge - v3.0.0
info: Loading configuration
info: Loading previous state
info: Perfoming configuration migration
info: Saving current state
info: Connecting to MQTT at mqtt://192.168.1.9:1883
info: Configuring autosave
info: Configuring API
info: Listening at http://localhost:8080

in Mosquitto

All I see is the triggers I sent via Hass

root@controller:/home/pi/GassistPi/src# mosquitto_sub -v -h localhost -p 1883 -t '#'
smartthings/Fireplace Lights/switch on
‘smartthings/Outlet/switch’ ‘on’

In the mosquitto log, I can see the connection from smartthings-mqtt-bridge and my HASS

1537139348: New connection from ::1 on port 1883.
1537139348: New client connected from ::1 as mosqsub/5132-controller (c1, k60).

on your phone, start smartthings app then click on HOME, then under THINGS, there you click on Mqtt bride, then on smartapps,then on Hassio (or what you called it)
have you selected the devices and what functions that should be puscht to the bridge in this window?

yes, I see the bridge. And it’s status as OK. I haven’t selected any functions/capabilities? Where do I do that?

that’s why you dont see any devices,
open the images, they are not in order, but they are markt 1,2,3,4

thanks for the detail. this brings me back to the main problem I am having. I cannot access those screens because the smartapp is not recognized.

1 Like

Any ideas what could have gone wrong?

a ok, go to market place, then my smartapps, klick on mqtt bridge, scroll all the way down, to Bridge, in the field notify this bridge, ad you mqtt, assign a name, Now go back to home and see if you get the menu

2 Likes

Oh great, I haven’t seen this menu before…
I did as you suggested, but getting this error when I try to save.

never seen that error before, looks like you installd mqtt wrong or you haven’t added the info correct online on samsung site. Go to smartthings on a web browser and login to your account, go to location list, then click on, my hubs, scroll down to mqtt, klick on it, then click

on edit and check so the info is correct.

Thanks! I do have this information filled out correctly.
however did you use colons in the MAC address? I have format 11:11:11:11:11:11

OMG. It suddenly started working!
There was a power outage and my smarthings hub restarted, all of a sudden I could set the settings in smartapp and export the various devices! I am seeing them all in MQTT, now all I have to do is setup home assistant.

THANK you SO much for walking me through this nightmare. I am going to bookmark this page and hopefully update the home assistant and smartthings-mqtt-bridge documentation.

You are my saviour!

:slight_smile: