Monday, June 20, 2016

Running HomeBridge on my Synology NAS to interface SmartThings with HomeKit

I have gone through a few platforms and configurations in my home automation adventures. I've used openHAB and the Wink Hub. Recently, I have stuck with the SmartThings Hub V2 for almost half a year. Apart from some instabilities, which they have been working on, I have been happy with the setup. It interfaces with my Amazon Echo perfectly for voice control, which is great! Because of this, I have not really bothered with trying to get Apple's Siri plugged into my home. But I have been seeing HomeBridge come up in many discussions which allows Apple's HomeKit to work with devices that are not approved. Since it got me curious, I decided to set it up and see what it's like!



Installing HomeBridge on my Synology NAS with Docker


The first thing I did was find and configure a Docker image of HomeBridge. HomeBridge is a service that runs on your network emulating the HomeKit API. This allows unapproved third-party devices to be configured with HomeKit and controlled with Siri.


After downloading one of the Docker images for HomeBridge, I followed the directions found on it's Docker page. It essentially involves creating a shared folder where you will store your HomeBridge files that the Docker container will access. Templates of the configuration files are found here.

Unfortunately, the GUI wizard for Docker on Synology does not provide the opportunity to configure the container as necessary so it must be started from the terminal via SSH or some other method.

docker run --name=HomeBridge -d --restart=always --net=host -p 51826:51826 -v /volume1/docker/homebridge:/root/.homebridge psmith/synology-docker-homebridge:0.13
The main aspects of the command include linking the shared folder to the expected directory in the container where the config file is expected, setting the proper port and setting the net host. The net host is what we miss with the GUI. Without that, the HomeBridge service does not properly broadcast on the network and HomeKit will not be able to find it.



In my docker/homebridge shared folder I prepared two files, config.json and package.json.

The package.json file contains the command so that homebridge-smartthings will be installed. This plugin is needed for HomeBridge to interface with my SmartThings hub.

{  "scripts": {
    "install": "npm install -g homebridge-synology homebridge-smartthings --unsafe-perm"
  }
}

The config.json file contains the bridge setup and the SmartThings platform setup. The SmartThings setup required setting the unique app_id and access_token which I will obtain after configuring the SmartThings SmartApp for HomeBridge.

{
    "bridge": {
        "name": "Homebridge",
        "username": "CC:22:3D:E3:CE:30",
        "port": 51826,
        "pin": "031-45-154"
    },
    
    "platforms": [
  { 
      "platform": "SmartThings",
   "name": "SmartThings",
      "app_url": "https://graph.api.smartthings.com:443/api/smartapps/installations/",
      "app_id": "************************",
      "access_token": "************************",
      "polling_seconds": 600,
      "update_seconds": 1
  }
 ]
}

Preparing SmartThings



For the SmartThings setup I followed the instructions found on the smartthings-homebridge page. A few things that I noticed missing from the instructions were

  • In order to see the Settings button under My SmartApps, you need to first integrate your account with a GitHub account. I already had a GitHub account, so linking them was quick.
  • Before you can see JSON Complete API appear under My Apps in the SmartThings app, you need to publish the program from the My SmartApps webpage by clicking on the program pdlove : JSON Complete API and then selecting the Publish button at the top.
Opening the program within My Apps in your cellphone, after you enable all the devices, there is a Config section which provides the unique app_id and access_token needed for the HomeBridge configuration on my server file config.json.

iOS Setup and Final Thoughts


It took me a while to understand how to set everything up, but once I saw the Docker container log say Homebridge is running on port 51826 without it crashing I knew I was almost done! Now I just had to find a HomeKit app to configure and hope it all works well.

I checked online for different HomeKit apps I could use that are free. The Insteon+ app required you to register an account first, and then Lutron app could not find my HomeBridge. I finally found success with the Devices app. It was able to find the HomeBridge and detect all my devices on the SmartThings hub.

After I asked Siri to turn on one of my lights, it worked! I do not have an Apple TV so I will not be able to use Siri when I am away from home, but I believe this can be useful in locations where I cannot yell to my Amazon Echo. The setup was relatively easy with Docker containers and the SmartThings plugin already available for HomeBridge. For those with a SmartThings Hub hoping to control it with Siri, HomeBridge is the real deal!





4 comments:

  1. super! I hope that is still working! can you add any device you want regardless the brand?

    ReplyDelete
    Replies
    1. Yes, it has been stable and reliable. Since it is just an interface for the SmartThings hub, any device that works with SmartThings should work fine through HomeBridge to iOS.

      Delete
    2. thanks a lot, I will install it and try some wemo plugs and switches!

      Delete
  2. Unfortunately, just discovered that the ds216play I bought is 32 bit so can't run Docker. Guess my wife and her iOS devices are going to be out of luck, at least for now.

    ReplyDelete