Controlling your home using Siri with Homebrige, Docker and a Raspberry Pi

Hugo Larcher
Coding Entropy
Published in
3 min readJan 3, 2016

--

Running Homebridge with Docker on a Raspberry Pi

Ok, so you discovered HomeKit during the WWDC in 2014 and you got pretty excited to control your Phillips Hue lightning system with Siri. But after a unusual long silence from Apple you discovered that all devices had to be certified by Apple to be compatible with HomeKit. So you now have to ditch all your home automation equipment and buy certified hardware. But wait … Nick Farina recently published on GitHub is latest project Homebridge, a lightweight Node.js server emulating the HomeKit API.

Hey Siri, turn on the lights !

Homebridge features a lot of plugins to control a range of home automation devices, including Hue lights and proves to interact perfectly with Siri. It’s the perfect utility to run on a low-power Raspberry Pi, but its installation can be a bit complicated : using a pre-built Docker image allows an easy deployment.

Docker on the Raspberry Pi

If you already have Docker running on your Pi skip directly to the next chapter.

The easiest way to install Docker on your Raspberry Pi is to use a pre-built image from the Hypriot team. Follow their instructions to install their HypriotOS on your SD card and boot your Raspberry Pi.

Don’t forget to change the default credentials …

Configuring and running HomeBridge

Start by creating a ~/homebridge folder on your RaspberryPi. It will contain the configuration and HomeBridge will use it to remember paired devices. Then create a config.json file inside :

Consider changing the default username and pin. Also add your Hue bridge IP and username.

Now we are ready to run Homebridge using a custom Docker image I built:

A few explanations:

  • -net host : binds the container to the Raspberry network layer (Homebridge relies on Apple Zeroconf via Avahi to get detected by the iOS devices, it needs full access to local network)
  • -p 0.0.0.0:51826:51826 : network port used by Homebridge server
  • $(find /dev/snd/ -type c | sed ‘s/^/ — device /’) : optional. Allows the container to access the Raspberry’s audio devices. I used this to create a radio plugin that allows you to stream webradios on the Raspberry and control them via Siri.
  • -v /path/to/homebridge/config/folder/:/root/.homebridge : binds your local homebridge configuration folder to the container.
  • /root/run_homebridge.sh : a custom script which resets Avahi daemon and runs Homebridge

Pairing with an iPhone

Siri’s magic happenin’ here !

HomeKit is a framework on the iPhone and there is no default app to control it. You have to download an app from the AppStore. I used the app recommended by the HomeBridge team MyTouchHome ($2) which is quite intuitive. Once the app is downloaded, touch “+ Accessory” and your HomeBridge should appear (the Raspberry and your iPhone should be connected to the same local network). If you connected your Hue bridge to HomeKit, your lights should appear.

Close the app and try a “Siri, turn on the lights” ! Magic should happen.

You can create scenes in MyTouchHome and trigger them using Siri. eg. “Hey Siri, it’s the morning!”. A list of Siri commands on HomeBridge wiki (work in progress).

Enjoy!

--

--