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.

homebridge
-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.

/opt/node/bin/homebridge

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.

, , , , ,

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

  • ryan says:

    cool write up. I noticed that the terminal got mad at a few of the commands because I don't think the dashs are plain ascii?

  • Wm. Cerniuk says:

    Thanks for taking us down the bunny trail.

    The install of nodeJS and homebridge is flakey at best and seeing your path matching ours with your thoughts (sanitized I presume) matching ours is both technically very helpful as well as good therapy 😀 after the suffering %-)

  • Brent says:

    Hi Brad, I have homebridge running on my Pi Zero, but for the life of me cant get any plugin to give me an output on the GPIO to power a relay, i want to use for my garage door and a electric gate lock.

    • Brad says:

      Are you getting any specific errors? I think I recall mine being finicky when it'd just error trying to bind the the GPIO pin, saying its not ready or something. I ended up using different pins and that resolved my problem.

      EDIT: I guess I didn't post this, I hooked up my garage door with relays to do what you are doing. I need to get around to finishing my blog post on that.

      Siri controlled garage door

  • Eric M says:

    Would I see a difference in homebridge performance between a Pi Zero W and a Pi 3B+ (wired)? I have spares of both and would like to get the best performance out of the system.

    Thanks

    • Brad says:

      I don't have any issues with my homebridge on the Pi Zero W, so I would go with that and leave the Pi 3B+ alone for more performance intensive tasks. It could also depend on what plugins you install for homebridge and how intense they are.

      But the good thing about this is, you can go with the Pi Zero W, and if it doesn't work you can swap it out for the Pi 3B+. You'll never die wondering "what if".

      • Eric M says:

        Thanks Brad,

        They both work but I haven't actually timed Siri commands with smartthings plugin. So far the family hasn't complained about any delays but while upgrading a Zero W and a Pi 3B+ last night, I realized that the Zero was considerably slower at everything which made me wonder if I was sacrificing milliseconds with the Zero

Leave a Reply

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

18 + 8 =