Added the "ready to use" image file link to the youtube video description.

Download, write to SD, and ready to use.


Rpi ZERO version:


In this instructable, i will show you, how to install Homekit Bridge to your RPi 2, and control your home accessories.

There is a youtube video too, with step by step tutorial.

For me, Homekit on the RPi2 not worked well with other OS (Raspian), only with a Jessie image.

Tutorial video:

STEP 1 >>

Step 1: Step 1: Install Jessie

Tools needed:

- Jessie OS (version 2015-08-30)


- WinFlashTool (for write image to SD)


Download the image and the WFTool from the links, put the image file into the WFTool, and install the OS to the SD

(First step in the video)

Step 2: Step 2: Installs, Installs Everywhere...


Boot the RPi2 with Jessie.

Open a terminal program on your PC/MAC (im using putty)

Connect to your RPi2 with the putty (RPi2 ip found in your router DHCP client list)

Username: pi

Password: raspberry

In the youtube video find this step at 1:17.


next, the ragular update and upgrade:

sudo apt-get update && sudo apt-get upgrade -y

In the youtube video find this step at 1:35.


Add yourself superuser privileges (less "sudo" type)

sudo su

In the youtube video find this step at 2:13


Install python-dev and python-pip

apt-get install python-dev python-pip

In the youtube video find this step at 2:21


Install libavahi and libdnssd

apt-get install libavahi-compat-libdnssd-dev

In the youtube video find this step at 2:27


Download and install the latest node

wget http://node-arm.herokuapp.com/node_latest_armhf.d...

dpkg -i node_latest_armhf.deb

In the youtube video find this step at 2:37


Check node and npm version and installation

node -v

npm -v


Clone Homekit Bridge from github, and go into the HAP-NodeJS folder

git clone https://github.com/KhaosT/HAP-NodeJS.git

cd HAP-NodeJS

In the youtube video find this step at 3:04


There is a lot of missing modules, so install all of them in one command.

npm install -g node-gyp
npm install node-persist && npm install srp && npm install mdns && npm install ed25519 && npm install curve25519 && npm install debug && npm install python-shell

In the youtube video find this step at 3:37



npm rebuild

Step 3: Step 3: Add New Light Accessory


Go into accessories folder, and make a new light accessory:

cd accessories

nano myLight_accessory.js

In the youtube video find this step at 5:13


Copy in this empty .js file everything from the linked homekit.txt file, from the

//Light accessory line

Homekit.txt link:


Rename the accessory, change a little the "username" (looks MAC address, watch out the HEX rules)

Save the file and exit

In the youtube video find this step at 5:46

Step 4: Step 4: Make the Python Files to Control GPIO Pins


in the HAP-NodeJS folder, make a new python folder, go into.

cd ..

mkdir python

cd python

In the youtube video find this step at 7:07


Make the GPIO "on" and "off" python file

nano light1.py

Copy this into:

import RPi.GPIO as GPIO


GPIO.setup(16, GPIO.OUT)

GPIO.output(16, 1)

Save, and close the file

nano light0.py

Copy this into:

import RPi.GPIO as GPIO


GPIO.setup(16, GPIO.OUT)

GPIO.output(16, 0)

Save, and close the file

In the youtube video find this step at 7:19


Connect a led GND into one of the RPi2 GND pin. Im used the outer line 3. pin, and connect the led "+" pin tho the RPi2 GPIO.16 pin. Thats the 8. pin in the outer line.

Test the python codes:

python light1.py (led turn on)

python light0.py (led tudn off)

If everything ok, go back to HAP-NodeJS folder.

cd ..

npm rebuild

In the youtube video find this step at 8:14


Start the Homekit Bridge.

node Core.js

Step 5: Stap 5: Config Ios Device


In the video, im using Apple HMCatalog app, but find better homekit app, like EVE elgato.

Add a new home, some room, and one of the rooms, add your new light accessory.

The PIN: 03145154

Add anyway.

In the youtube video find this step at 9:28


Test it, enjoy it!

Thank you.

<p>Any chance someone can tell me what I did wrong?</p><p><strong>pi@raspberrypi</strong>:<strong>~/HAP-NodeJS $</strong> node Core.js</p><p>module.js:340</p><p> throw err;</p><p> ^</p><p>Error: Cannot find module 'debug'</p><p> at Function.Module._resolveFilename (module.js:338:15)</p><p> at Function.Module._load (module.js:280:25)</p><p> at Module.require (module.js:364:17)</p><p> at require (module.js:380:17)</p><p> at Object.&lt;anonymous&gt; (/home/pi/HAP-NodeJS/lib/Accessory.js:3:13)</p><p> at Module._compile (module.js:456:26)</p><p> at Object.Module._extensions..js (module.js:474:10)</p><p> at Module.load (module.js:356:32)</p><p> at Function.Module._load (module.js:312:12)</p><p> at Module.require (module.js:364:17)</p>
<p>I should mention that I tried:</p><p>sudo npm insgall debug</p><p>npm install mdns</p><p>npm rebuild</p>
<p>Will this work on pi 3, too ?</p>
<p>1 in 1 not work, need some modification. I have not pi 3, cannot test it.</p>
<p>Same with the newest pi 2 as i know.</p>
<p>Ok I need Help</p><p>So I did everything like you said and every time I run node Core.js it says </p><p>Pls Help</p>
<p>Maybe a syntactic error in the js file? check {}, characters.</p>
<p>Good day Imre,</p><p>I have created a Homekit light switch with the Raspberry Pi<br>Zero. Everything work perfectly except I want to take it a step further:</p><p>Is the a line of code that I can run on the Raspberry Pi<br>itself to switch off the light AND notify the Core.js service that the light<br>has been turned off? </p><p>Currently I can run the light0.py file and turn off the<br>light but the Homekit service does not know about this change and my phone<br>(Home app) still shows that the light is on.</p><p>Ultimately what I want to do is to add a button (Switch) on<br>the GPIO pins to control the light from the switch and my phone. Can you please<br>help me?</p><p>Thank you in advance</p>
Help please ı realy need to do it
Hello please someone help me ı reinstall rasperian 3 times but ı wıll take this error again to again whats the problem please someone help me
<p>Hi Planetleak,</p><p>Thank you for the great tutorial! Everything works perfectly except the auto start on boot. I want to connect a light switch to the GPIO to control the light from the switch and from my phone. How will I be able to do this? Edit the light0.py files or run a separate python? If so what code do I need?</p><p> Please help me. </p><p>Kind Regards</p><p>Liam Blom </p>
<p>Hi, I want to do the same, have you solved?</p>
<p>Hi, if you want to control light from gpio, use relay module, and control that relay with the GPIO pins. The code sample you find in this instructable STEP 4 or in the videos what i linked from my youtube channel. You can use that code. I buyed cheap RF controlled sockets for lamp, and i control the transmitter buttons with the rpi gpio pins, or if not secured the data transfer, you can use cheap RF433 transmitter direct with rpi, to control sockets. Unfortunately my rf sockets ar not work in that way, so im control the transmitter buttons with rpi gpio and optocouplers(opto-isolator). Best Regards: Imre</p>
<p>Hi Imre,</p><p>I'm looking to use the existing wiring in my home. I want to use the existing light switches that are in my wall and connect them to my Pi Zero as a GPIO input? That way I can turn off the light at the wall switch as well as with Siri or the Home app. So to explain, I want to connect my existing Light switch to my Pi Zero as an input, connect a relay to my Pi Zero, as in your tutorial, as an output. That way I can see if the light is on or off on my phone. Where would I have to insert the code? </p><p>Kind Regrads</p><p>Liam</p>
<p>Please see the schematic on what I mean. I don't describe things very well :)</p>
<p>Hi, and what if you change the wall lamp switch to wireless wall switch, and control that switch with raspberry via rf modul? Or you can control the remote controller pins directly with an opto isolator. Im using this way for my wireless socket control prototype. </p>
<p>hi, Thank you for your valuable tutorial. everything works fine except I get error messages when I add Test_accessory.js which is for to control Led. the code is same with you shared in text document except some names. when I want to run node Core.js I get some errors. any idea for these errors. thanks..</p><p><strong>pi@raspberrypi</strong>:<strong>~/HAP-NodeJS $</strong> node Core.js</p><p>*** WARNING *** The program 'node' uses the Apple Bonjour compatibility layer of Avahi.</p><p>*** WARNING *** Please fix your application to use the native API of Avahi!</p><p>*** WARNING *** For more information see &lt;http://0pointer.de/avahi-compat?s=libdns_sd&amp;e=node&gt;</p><p>*** WARNING *** The program 'node' called 'DNSServiceRegister()' which is not supported (or only supported partially) in the Apple Bonjour compatibility layer of Avahi.</p><p>*** WARNING *** Please fix your application to use the native API of Avahi!</p><p>*** WARNING *** For more information see &lt;http://0pointer.de/avahi-compat?s=libdns_sd&amp;e=node&amp;f=DNSServiceRegister&gt;</p><p>HAP-NodeJS starting...</p><p>Parsing accessory: Fan_accessory.js</p><p>Parsing accessory: GarageDoorOpener_accessory.js</p><p>Parsing accessory: Light_accessory.js</p><p>Parsing accessory: Lock_accessory.js</p><p>Parsing accessory: TemperatureSensor_accessory.js</p><p>Parsing accessory: Test_accessory.js</p><p>Parsing accessory: Thermostat_accessory.js</p><p>events.js:160</p><p> throw er; // Unhandled 'error' event</p><p> ^</p><p>Error: listen EADDRINUSE :::51826</p><p> at Object.exports._errnoException (util.js:1008:11)</p><p> at exports._exceptionWithHostPort (util.js:1031:20)</p><p> at Server._listen2 (net.js:1253:14)</p><p> at listen (net.js:1289:10)</p><p> at Server.listen (net.js:1385:5)</p><p> at EventedHTTPServer.listen (/home/pi/HAP-NodeJS/lib/util/eventedhttp.js:58:19)</p><p> at HAPServer.listen (/home/pi/HAP-NodeJS/lib/HAPServer.js:155:20)</p><p> at Accessory.publish (/home/pi/HAP-NodeJS/lib/Accessory.js:480:16)</p><p> at /home/pi/HAP-NodeJS/Core.js:32:13</p><p> at Array.forEach (native)</p>
<p>I'm getting the same errors. Did you solve the problem?</p>
<p>To solve the EADDRINUSE :::51826 error, we just need to reboot the RPi. </p>
<p>hi!</p><p>i try to install for myself... and get some errors in the step 2-9..</p><p>and when execute : node Core.js get they error and dont run...</p><p>(Thank for help)</p><p>module.js:339</p><p>throw err;</p><p>^</p><p>Error: Cannot find module 'debug'</p><p>at Function.Module._resolveFilename (module.js:337:15)</p><p>at Function.Module._load (module.js:287:25)</p><p>at Module.require (module.js:366:17)</p><p>at require (module.js:385:17)</p><p>at Object.&lt;anonymous&gt; (/home/pi/HAP-NodeJS/lib/Accessory.js:1:75)</p><p>at Module._compile (module.js:435:26)</p><p>at Object.Module._extensions..js (module.js:442:10)</p><p>at Module.load (module.js:356:32)</p><p>at Function.Module._load (module.js:311:12)</p>
<p>looks like you need is install debug</p><p>Sudo npm install debug</p>
<p>finally works!, the server start well, i add the accessory, but the led dont turn on...</p><p>in the test of the python files, led turn on and off.. </p>
<p>Where is your python file?</p>
<p>the same as in the example, light1.py and light0.py </p><p>I put the file path and it works,</p><p>/python/light0.py</p><p>/python/light1.py</p>
<p>Move python files from python folder to the HAP-NodeJS/ folder.</p>
<p>when I install srp, it shown npm err </p><p>npmERR!argv &quot;/usr/bin/nodejs&quot; &quot;/usr/bin/npm&quot; &quot;install&quot; &quot;-g&quot; &quot;--unsafe-perm&quot; &quot;homebridge&quot;</p><p>npmERR!node v6.9.1</p><p>npmERR!npm v3.10.8</p><p>npmERR!code 128</p><p>npmERR! Command failed: git clone --template=/root/.npm/_git-remotes/_templates --mirror git://github.com/KhaosT/node-srp.git /root/.npm/_git-remotes/git-github-com-KhaosT-node-srp-git-7ab735e3</p><p>npmERR! 克隆到裸版本库 '/root/.npm/_git-remotes/git-github-com-KhaosT-node-srp-git-7ab735e3'...</p><p>npmERR! fatal: Could not read from remote repository.</p><p>npmERR!</p><p>npmERR! Please make sure you have the correct access rights</p><p>npmERR! and the repository exists.</p><p>npmERR!</p><p>npmERR!</p><p>npmERR! If you need help, you may report this error at:</p><p>npmERR! &lt;https://github.com/npm/npm/issues&gt;</p><p>npmERR! Please include the following file with any support request:</p><p>npmERR! /home/pi/npm-debug.log</p>
<p>Try this:</p><p>npm install</p>
Errors and wrong version of curve25519?<br><br>Change <br>npm install curve25519 <br> to <br>npm install ccurve25519-n <br> then <br>sudo npm install<br><br>On fresh Jessie install on pi Zero. <br><br>It took me one whole day to work that out <br><br>You're welcome.
<p>Hey, FYI if you clone the repo as root, it causes problems when you try and npm rebuild, so I would suggest jumping out of root to clone the repo</p>
<p>Hi,</p><p>Core.js works perfectly but I can't turn on led when I open lamp with apple home app.</p><p>I used 16th pin (greep led + 330ohms capacitance) for (+) (Power) and 39th pin for (-) (Ground)</p>
<p>i try to reinstall npm, and get this:</p><p>npmERR!install Couldn't read dependencies</p><p>npmERR! Linux 4.1.7-v7+</p><p>npmERR!argv &quot;/usr/local/bin/node&quot; &quot;/usr/local/bin/npm&quot; &quot;install&quot;</p><p>npmERR!node v4.0.0</p><p>npmERR!npm v2.14.2</p><p>npmERR!path /home/pi/package.json</p><p>npmERR!code ENOPACKAGEJSON</p><p>npmERR!errno -2</p><p>npmERR!syscall open</p><p>npmERR!package.json ENOENT: no such file or directory, open '/home/pi/package.json'</p><p>npmERR!package.json This is most likely not a problem with npm itself.</p><p>npmERR!package.json npm can't find a package.json file in your current directory.</p><p>npmERR! Please include the following file with any support request:</p><p>npmERR! /home/pi/npm-debug.log</p>
<p>Hi, try this:</p><p>npm install </p><p>npm update</p>
<p>nothing!</p><p>get errors...</p><p>:-(</p>
<p>Delete non used accessories. Many peaople got problem with fan accessory.js</p><p>If not help, try to make a clean install. There is a step by step video tutorial for zero and pi2 on my youtube channel, or you can see the videos here too in this instructable.</p>
<p>i try the &quot;ready to use&quot; versi&oacute;n... and get the same error... :-(</p>
<p>Thank you for this awesome instructable! I made it, it works perfectly and I can add more accessories. However, node Core.js stops working and all accessories become inaccessible once I close the putty session. Do I need an autostart script? Do I need to launch it using different commands? I used the one that is included in the instructable: node Core.js</p><p>Thank you!</p>
<p>Hello, thanks.</p><p>Use &quot;forever&quot; to continue run.</p><p>Install:</p><p>sudo npm install forever -g</p><p>Run:</p><p>sudo forever start Core.js (from the HAP-NodeJS folder)</p>
<p>Thank you for your fast response! it works perfect. What do I need to execute the 'sudo forever start Core.js' in case that there is a power cut?</p>
<p>Try this (not tested):</p><p>nano /etc/init.d/corestart</p><p><br> cd home/pi/HAP-NodeJS<br> sudo forever start Core.js</p><p><br>chmod 755 /etc/init.d/corestart<br>update-rc.d corestart defaults</p>
<p>Sorry, forgot: only the &quot;cd home...&quot; and &quot;sudo forever..&quot; lines need in the corestart. The last two lines need to run after exited from nano.</p>
<p>Thank you, I achieved the autostart on reboot using PM2 at the end. Do you know how I can create an accessory to manage a blind? I created a light accessory to manage it but I would like to know if there is a better way.</p>
<p>Hi Francisca,</p><p>How did you get PM2 to start Core.js on boot? Please help I've tried everything!!</p><p>Kind Regards</p><p>Liam</p>
<p>Thanks! I made it but it is not working because I force a power cut and the accessories become inaccessible from the app. I got two warnings in the last line (I do not know if it is the cause of the problem).</p>
<p>I got the unaccessible accessories with older HAP-NodeJS git too, try to update the git.</p>
<p>Awsome tutorial.</p><p>I only had to made a small modification to the myLight.js file to change the path of the python files; from light1.py to python/light1.py (same for ligth0.py)</p>
<p>awsome but need some code for powercut.</p>
<p>awsome but need some code for powercut.</p>
<p>awsome but need some code for powercut.</p>
I just saw the &quot;ready to use&quot; image on the the YouTube link. Will that work on the rp2? Are there any special instructions for this update?

About This Instructable




More by planetleak:iPhone Touch ID windows login ESP8266 TV remote for Homekit Raspberry Pi 2 Homekit - from zero to Hey, Siri (Updated) 
Add instructable to: