Smartthings to Home Assistant using MQTT

I have been away for a while, but in my absence I have been playing with a Home Automation System called Home Assistant. You can find out more about it here on their website: https://home-assistant.io/ 

One of my Father’s Day Gifts from my Wife and Kids was a SmarThing Hub with a Arrival sensor. Now Home Assistant has literally hundreds of pre-built integrations however SmartThings is not one of them. To make it work with Home Assistant you will have to use a protocol called MQTT which is very versatile and can be used to create your own Automations.  (Find out more about it here.)

Now my Home Assistant instance is running on a Rasberry Pi 3 (also a Father’s Day Gift) however it also runs on a Raspberry Pi 2. I am also running HASSbain which is a Raspian image created by Home Assistant. As for MQTT there are a few products out there that you can use, I prefer Mosquitto as there seems to be more guides out there on how to configure and manage it.

Start off by checking for and installing updates for Raspian:

sudo apt-get update

sudo apt-get upgrade

this could take a while depending on your setup.

Next you will need to setup the smarthings-mqtt-bridge via npm
sudo apt-get install npm

sudo npm install -g smartthings-mqtt-bridge

Then you will need to setup pm2 to run the processes
sudo npm install pm2 -g

Once installed you will need to 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
Here is what the mqtt-bridge-configuration ~/config.yml file should look like if all is configured correctly.
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

Now that all of the local configurations have been completed you need to configure the SmartThings Device handler, Device, and SmartApp using steps outlined in https://github.com/stjohnjohnson/smartthings-mqtt-bridge150

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

Next you will need to add mqtt to HomeAssistant config configuration.yaml
mqtt:
  broker: localhost
  port: 1883
  client_id: home-assistant-1
  username: pi
  password: mqttpass

Now you will need to add your devices to their own file, or configuration.yaml
Since I am using mine for presence detection mine looks something like this

device_tracker:
  – platform: mqtt
    name: “MQTT Presense Detection”
    devices: 
      Friendly Name: smartthings/device name/presence
      Friendly Name1: smartthings/device name/presence
     
Now you will need to start the bridge

sudo ln -s “$(which nodejs)” /usr/local/bin/node
pm2 restart smartthings-mqtt-bridge

restart Home Assistant
sudo systemctl restart home-assistant.service

That should do it. You may want to sudo reboot

In the future I may do more of these as I have learned at lot from it, including beginning to dabble with Docker.

Leave a Reply