How to use IKEA TRADFRI with a Samsung Smartthings

So as you may or may not know one of my hobbies as of late has been Home Automation. My favorite platform is Home Assistant as it allows me to connect a whole plethora of products together and use them in a giant mesh throughout my house. 
I recently setup IKEA Tradfri bulbs in my Master Bedroom and the Daughters room and I was able to connect them into Home Assistant with mixed reviews. The integration with the IKEA Tradfri lights is already part of the standard build for Home Assistant, however I have to admit that it is not always reliable for me and I find myself using either the Tradfri app or the remote controls that I purchased for them. 
This weekend my Son asked if I could do the same for him so he could be cool like his sisters. So I went to IKEA and purchased a new Light bulb. Now one of the things that I have noticed from being a user of the system that no one mentions is that if you desire to use a remote for the lights, you will need to purchase one for each room your are setting up as there is no way to switch between light groups on the remote. So not only and I purchasing an $11 light bulb (because I am cheap) but I have to purchase a $20 Remote!!
I had done some research online and found that the IKEA Tradfri bulbs are actually using a form of ZigBee to communicate and that it might be possible to use it with a Samsung Smartthings Hub. 
So when I got home from IKEA I opened up my laptop and searched for a Guide and I found one listed below which I was able to follow with great ease considering I had already done a lot of this work when setting up the MQTT Bridge with Smartthings. 

https://smarterhomelife.com/everything/2017/8/11/pairing-ikea-tradfri-smart-lights-with-smartthings-how-to


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.