I’m using SmartThings hub in my home automation. While it has been working reasonably well, it is missing some features that I would love to have. Home Assistant is an open-source home automation platform which supports a lot more devices and has the components that I need in my smart home.
In this post, I’ll show you how to setup SmartThings with MQTT Bridge and Home Assistant, so that information can be shared between SmartThings and Home Assistant. It runs on a Raspberry Pi 3 and uses Raspbian Stretch (Debian 9) in Python virtual environment (not Hass.io).
This guide assumes
- Raspberry Pi’s IP address is 192.168.1.101
- SmartThings’s IP address is 192.168.1.207
Home Assistant
Install dependencies for Home Assistant
1 2 3 4 | $ sudo apt-get update $ sudo apt-get upgrade $ sudo apt-get install python3-pip python3-dev python3-venv $ sudo pip3 install --upgrade virtualenv |
Create user & group for Home Assistant
1 2 | $ sudo adduser --system homeassistant $ sudo addgroup homeassistant |
Create installation directory for Home Assistant
1 2 3 4 | $ sudo mkdir /srv/homeassistant $ sudo chown homeassistant:homeassistant /srv/homeassistant $ sudo python3 -m venv /srv/homeassistant $ sudo chown -R homeassistant:homeassistant /srv/homeassistant/ |
Install or Update Home Assistant
1 2 3 | $ sudo su -s /bin/bash homeassistant $ source /srv/homeassistant/bin/activate (homeassistant)$ pip3 install --upgrade homeassistant |
Create Autostart using systemd
Add the following to /etc/systemd/system/home-assistant.service
1 2 3 4 5 6 7 8 9 10 11 | [Unit] Description=Home Assistant After=network-online.target [Service] Type=simple User=homeassistant ExecStart=/srv/homeassistant/bin/hass -c "/home/homeassistant/.homeassistant" [Install] WantedBy=multi-user.target |
Reload systemd and start Home Assistant automatically at boot.
1 2 | $ sudo systemctl --system daemon-reload $ sudo systemctl enable home-assistant.service |
Run Home Assistant
Fresh installation will take some time to complete setup.
1 | $ sudo systemctl start home-assistant.service |
Home Assistant Frontend
Browse to http://192.168.1.101:8123 to open the Home Assistant Frontend
Install MQTT Broker
I’m using Mosquitto as the MQTT broker in my setup.
1 | $ sudo apt-get install mosquitto |
SmartThings MQTT Bridge
Install Node.js & npm
1 2 | $ curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash - $ sudo apt-get install -y nodejs |
Install smartthings-mqtt-bridge
1 | $ sudo npm install -g smartthings-mqtt-bridge |
Configure smartthings-mqtt-bridge
Add the following to /config.yml
1 2 3 4 5 6 7 8 | --- 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 # Port number to listen on port: 8080 |
Install supervisor
Supervisor is a process control and monitoring system to ensure process runs forever. Smartthings-mqtt-bridge suggests PM2 but I prefer using Supervisor.
1 | $ sudo apt-get install supervisor |
Add the following to /etc/supervisor/conf.d/smartthings-mqtt-bridge.conf
1 2 3 4 5 | [program:smartthings-mqtt-bridge] command=/usr/lib/node_modules/smartthings-mqtt-bridge/bin/smartthings-mqtt-bridge autostart=true autorestart=true startretries=999999999999999 |
Execute the following to run smartthings-mqtt-bridge
1 2 3 | $ sudo supervisorctl reread $ sudo supervisorctl reload $ sudo supervisorctl restart smartthings-mqtt-bridge |
SmartThings
Install smartthings-mqtt-bridge’s Device Handler and Smart App for SmartThings
- Install the Device Handler in the Device Handler IDE using “Create via code”
- Add the “MQTT Device” device in the My Devices IDE. Enter MQTT Device (or whatever) for the name. Select “MQTT Bridge” for the type. The other values are up to you.
- Configure the “MQTT Device” in the My Devices IDE with the IP Address (192.168.1.101), Port (8080), and MAC Address of the Raspberry Pi.
- Install the Smart App on the Smart App IDE using “Create via code”
- Configure the Smart App (via the Native App) with the devices you want to share and the Device Handler you just installed as the bridge
- Via the Native App, select your MQTT device and watch as MQTT is populated with events from your devices
Configure Home Assistant
To add SmartThings devices to Home Assistant over MQTT, first enable MQTT in Home Assistant:
1 2 3 4 5 | mqtt: broker: localhost port: 1883 client_id: home-assistant-1 keepalive: 60 |
Devices from the MQTT Bridge are published to the path smartthings/<Device Name>/<Attribute>
For example, this is my contact sensor from SmartThings:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | # Main Door Contact Sensor - platform: mqtt name: "Main Door Contact" state_topic: "smartthings/Main Door/contact" retain: true - platform: mqtt name: "Main Door Contact Temperature" state_topic: "smartthings/Main Door/temperature" unit_of_measurement: '°C' retain: true - platform: mqtt name: "Main Door Contact Battery" state_topic: "smartthings/Main Door/battery" unit_of_measurement: "%" retain: true |
With this setup, I can have the best of both worlds. SmartThings is the main hub, and Home Assistant complements SmartThings with additional features.
Leave A Comment