This tutorial is for those using a Raspberry Pi with Hass.io, and the Hass.io add-ons: Mosquitto broker (included in default repository), and SmartThingsBridge (from vkorn’s repository). There are other tutorials out there, but not specifically using the items listed above. I’ll continue editing this post for corrections/cleanup.
For a basic understanding of how the communications works from Smartthings to Home Assistant and vice versa, check out this image posted on the HA blog. It won’t make sense now, but should later on. We are creating the Bridge SmartApp (in SmartThings), Device Type (in SmartThings), Rest Bridge (in HA), and Broker (in HA) in this tutorial.
1) Install the Mosquitto (MQTT) Broker Hass.io add-on
Connect to your Home Assistant frontend using a web browser (e.g. http://hassio.local:8123)
- From the Sidebar (click on the 3 horizontal lines in upper left corner), go to Hass.io>>Store icon>>Mosquitto broker add-on>>Open>>Install
- Don’t touch the Options or the Network settings of the MQTT broker add-on. Ports should be 1883 and 8883. Here are my default settings:
{ "plain": true, "ssl": false, "anonymous": true, "logins": [], "customize": { "active": false, "folder": "mosquitto" }, "certfile": "fullchain.pem", "keyfile": "privkey.pem" }
- The default port of Mosquitto Broker is 1883–the SmartThingsBridge add-on will need to connect to this port. Check that this port is listed correctly in the SmartThings Bridge add-on options.
- Make sure the add-on is installed correctly by checking the state and logs for any errors. You can see the state and logs when you view the add-on’s info from the Hass.io section of the Sidebar.
2) Install the SmartThingsBridge Hass.io add-on from Vlad’s (vkorn) repository
- Connect to your Home Assistant frontend using a web browser (e.g. http://hassio.local:8123)
- From the Sidebar (click on the 3 horizontal lines in upper left corner), go to Hass.io>>Store icon
- In the section ‘Add-on Repositories’, add the repository ‘GitHub - vkorn/hassio-addons: Hass.io add-ons’ and click ‘save’
- A new section called ‘Vlad’s repository’ should appear and you should see his SmartThingsBridge hass.io add-on. Click on it, open, and install.
- In the SmartThingsBridge add-on options, leave everything as default. If you installed the Mosquitto Broker Hass.io add-on, the MQTT broker default port should be 1883 and the MQTT bridge port 2080. Here are my default options:
{ "broker_host": "172.17.0.1", "broker_port": 1883, "preface": "smartthings", "state_suffix": "state", "command_suffix": "cmd", "login": "login", "password": "password", "bridge_port": 2080 }
- Make sure the bridge’s default port is 2080–the SmartThings device will need to connect to this port. You will need to make sure this port is listed correctly in the SmartThings device.
- Note: I am not sure what the “broker_host: 172.17.0.1” in the Options means. I left it as-is because I was able to connect the broker and bridge using these default settings.
3) Create the Smartthings Device Handler and Device
- Follow the steps in this tutorial, starting at the section ‘SMARTTHINGS DEVICE’
- I named my device handler as 'MQTT Bridge Device Handler and my device as ‘MQTT Bridge Device’
- Double-check the preferences of your newly created Smartthings Device. You can edit the IP address and port, which should be the local IP address of the RPi hosting HA, and the port 2080, if you’ve been following my instructions.
- I had issues creating a SmartThings device because I could not fill out the device sections ‘Location’ and ‘Hub’. You should have registered your Smartthings hub by now and it should show up under the ‘My Locations’ tab. My hub was registered, but it wasn’t showing up properly in the ‘My Hubs’ section. To fix this, I clicked on ‘My Locations’, my hub, then on ‘List Devices’. Once I navigated here, I clicked on ‘My Devices’ at the top section and was able to see my hub and devices. I was able to add a new device with the location and hub drop-down menu properly showing my Smartthings hub. It will just magically work one of these days.
4) Create the Smartthings SmartApp
-
Follow the steps in this tutorial (BUT ALSO SEE MY NOTES BELOW), starting at the section ‘SMARTTHINGS APP’. Stop after you’ve completed that section and return to this tutorial.
-
One difference in the tutorial you will need to change is that the MQTT bridge port you use is 1883, not 8080. We are using a different MQTT broker than what is used in the linked tutorial.
5) Add the SmartApp to your Smartthings instance
- This step is briefly described in the tutorial, but here are the specific instructions to follow in the mobile app:
- Open Smartthings mobile app, click on Automation icon (looks like a house) >> SmartApps >> Add a SmartApp >> My Apps >> MQTT Bridge SmartApp (whatever you named it)
- I named my SmartApp as ‘MQTT Bridge SmartApp’
- In the Inputs section when adding the SmartApp, select the inputs and the supported devices that you want to communicate to Home Assistant. I did not select any Philips Hue light bulbs since HA does a great job connecting to the Philips Hue bridge.
6) Edit the HA configuration.yaml file to enable the MQTT broker
mqtt: broker: localhost discovery: true discovery_prefix: smartthings
- I’ve read forum comments saying that using ‘localhost’ should be fine. The tutorial says replace it with the location of the broker. You may need to experiment with this if things aren’t working for you.
7) Reboot and check if things are working
-
My preferred method to reboot is to go to the Dashboard >>Hass.io >> 3 dots button >> Restart Home Assistant
-
In the MQTT broker logs, do you see ‘new connection’ and ‘new client connected’? If so, that means the SmartThingsBridge is communicating to the broker
-
In the SmartThingsBridge logs, do you see entries like “Saving current state”, “Subscribing to…” or “Incoming message from SmartThings…”? If so, then SmartThings is communicated to the SmartThingsBridge.
8) Add your sensors to Home Assistant configuration.yaml
-
In my example, I am adding a Z-Wave door/window sensor that reports open/closed. We will use a MQTT binary sensor to represent this in HA. Other sensors can report more than on/off and you will need to use the correct MQTT sensor in your configuration.yaml. Look at the related components on this page to see the different MQTT sensors.
-
Find the names of your sensors by viewing the SmartThingsBridge logs at Dashboard >> Hass.io >> SmartThingsBridge >> Logs
-
You can also change the logger level in your configuration.yaml to show MQTT activity logs. Look up Logger component documentation for more info. My configuration.yaml looks like this:
logger:
default: critical
logs:
homeassistant.components.mqtt: debug -
If you have a door/window sensor, open and close your doors (in real life), and then see if the SmartThingsBridge logs detected the action. In my logs, I saw “Incoming message from SmartThings: smartthings/Front Door Sensor/contact/state = open”
-
NOTE: this is case-sensitive! Open != open. Use the exact case listed in the logs when you create your sensors in configuration.yaml.
-
Create a section called in the configuration.yaml called “binary_sensor”. See below:
binary_sensor: - platform: mqtt name: "Fridge Door" state_topic: "smartthings/Fridge Door/contact/state" payload_on: "open" #This is case sensitive! payload_off: "closed" #This is case sensitive! device_class: opening #Your sensor will read as open/closed instead of on/off with this setting retain: true #this is important so HA doesn't report the sensor as disconnected
