HomeKit integration with a Raspberry Pi Zero W

Last week I received an email that the Raspberry Pi Zero W is now available to purchase in Australia. The idea to purchase one was a no brainier, so I did the obvious thing and made an impulse purchase. It wasn't until the Pi arrived that I had no idea what I am going to do with it.... 30 minutes in and I have it doing this.

The setup is relatively easy and can be done on macOS, Windows, Linux as it is just a NodeJS service, but in this post I'll talk about setting it up on my Raspberry Pi W Zero. I'm also not going to discuss installing Raspbian, but just using the version that came pre-installed on my microSD card (Raspbian Jessie).

I originally wanted to hook my Pi up to my garage door so I can issue commands with Siri and use HTTP requests to send signals to the Pi to do certain actions. But after a quick google session I found that there is a node package called homebridge that can interface with Apples HomeKit as well as a plugin for LIFX bulbs so I figured I'd start with an easier task of just getting Siri to control my bedroom light. All I had to do was install homebridge and a plugin, too easy. The install instructions (if you skip all the requirements and other things you should probably read) say to install homebridge with the node package manger like so.

sudo npm install -g --unsafe-perm homebridge
sudo: npm: command not found

Well that didn't work very well. I had just assumed npm was installed by default. Easy, just need to install npm.

sudo apt-get install npm
sudo npm install -g --unsafe-perm homebridge

Finally installing this time, but it threw a few warnings before eventually failing.

npm WARN engine homebridge@0.4.20: wanted: {"node":">=4.3.2"} (current: {"node":"0.10.29","npm":"1.4.21"})
npm WARN engine hap-nodejs@0.4.25: wanted: {"node":">=4.3.2"} (current: {"node":"0.10.29","npm":"1.4.21"})

Wanted node v4.3.2, got node v0.01.29. Ew, gross. Lets undo that.

sudo apt-get purge npm

Going back and doing some RTFM work I found that they mention if you are using a Raspberry Pi you need to follow these instructions. I didn't have to install C++14 as I am already on Rasbian Jessie so I can skip some of these steps. I messed up installing node because I already stopped RTFMing and just copy/pasting commands blindly. If you are using an older ARM chip like I am (armv6 in this case) then you need to install node and npm with these instructions.

wget https://nodejs.org/dist/v6.9.5/node-v6.9.5-linux-armv6l.tar.xz
tar xJvf node-v6.9.5-linux-armv6l.tar.xz
sudo mkdir -p /opt/node
sudo mv node-v6.9.5-linux-armv6l/* /opt/node/
sudo update-alternatives --install "/usr/bin/node" "node" "/opt/node/bin/node" 1
sudo update-alternatives --install "/usr/bin/npm" "npm" "/opt/node/bin/npm" 1

Then the last step is to install the remaining dependencies and attempted original installation instructions.

sudo apt-get install libavahi-compat-libdnssd-dev
sudo npm install -g --unsafe-perm homebridge

Huzzah, it installed! Now to run it.

-bash: homebridge: command not found

Damn it, not again. I know the problem is that /opt/node/bin isn't in my PATH, but I really can't be bothered fixing that. Ill just run it as a full path.


Success! Now to install this node package I found earlier called homebridge-lifx-lan. If you use Philips Hue you can use this plugin instead.

npm install -g homebridge-lifx-lan

Started up homebridge again, used the instructions it gave to add it into the Home app on my iPhone and just like that everything fell into place. I now have my bedroom light controlled by Siri.

The last thing to do is setup homebridge to run on boot of the device, though its a good thing that other people have already done the hard work with this gist.

, , , , ,

2 thoughts on “HomeKit integration with a Raspberry Pi Zero W

Leave a Reply

Your email address will not be published. Required fields are marked *

four × 5 =