Introduction: Raspberry Pi 2 Homekit - From Zero to Hey, Siri (Updated)
UPDATE:
Added the "ready to use" image file link to the youtube video description.
Download, write to SD, and ready to use.
UPDATE 2:
Rpi ZERO version:
Hi,
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)
http://sysprogs.com/files/SD/2015-08-30-jessie-ras...
- WinFlashTool (for write image to SD)
http://winflashtool.sysprogs.com/
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...
1:
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.
2:
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.
3:
Add yourself superuser privileges (less "sudo" type)
sudo su
In the youtube video find this step at 2:13
4:
Install python-dev and python-pip
apt-get install python-dev python-pip
In the youtube video find this step at 2:21
5:
Install libavahi and libdnssd
apt-get install libavahi-compat-libdnssd-dev
In the youtube video find this step at 2:27
6:
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
7:
Check node and npm version and installation
node -v
npm -v
8:
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
9:
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
10:
Rebuild
npm rebuild
Step 3: Step 3: Add New Light Accessory
1:
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
2:
Copy in this empty .js file everything from the linked homekit.txt file, from the
//Light accessory line
Homekit.txt link:
https://drive.google.com/file/d/0B6GR9Hj5Ut61bDZle...
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
1:
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
2:
Make the GPIO "on" and "off" python file
nano light1.py
Copy this into:
import RPi.GPIO as GPIO
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
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.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(16, GPIO.OUT)
GPIO.output(16, 0)
Save, and close the file
In the youtube video find this step at 7:19
3:
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
4:
Start the Homekit Bridge.
node Core.js
Step 5: Stap 5: Config Ios Device
1:
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
2:
Test it, enjoy it!
Thank you.
72 Comments
6 years ago
hi wehn i run "sudo node Core.js" it returns
*** WARNING *** The program 'node' uses the Apple Bonjour compatibility layer of Avahi.
*** WARNING *** Please fix your application to use the native API of Avahi!
*** WARNING *** For more information see <http://0pointer.de/avahi-compat?s=libdns_sd&e=node>
*** WARNING *** The program 'node' called 'DNSServiceRegister()' which is not supported (or only supported partially) in the Apple Bonjour compatibility layer of Avahi.
*** WARNING *** Please fix your application to use the native API of Avahi!
*** WARNING *** For more information see <http://0pointer.de/avahi-compat?s=libdns_sd&e=node&f=DNSServiceRegister>
HAP-NodeJS starting...
/home/pi/HAP-NodeJS/lib/Service.js:101
if (!this.linkedServices.includes(newLinkedService))
^
TypeError: this.linkedServices.includes is not a function
at Service.addLinkedService (/home/pi/HAP-NodeJS/lib/Service.js:101:30)
at Object.<anonymous> (/home/pi/HAP-NodeJS/accessories/AirConditioner_accessory.js:83:19)
at Module._compile (module.js:435:26)
at Object.Module._extensions..js (module.js:442:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:311:12)
at Module.require (module.js:366:17)
at require (module.js:385:17)
at /home/pi/HAP-NodeJS/lib/AccessoryLoader.js:33:29
at Array.forEach (native)
what's the problem?
6 years ago
Any chance someone can tell me what I did wrong?
pi@raspberrypi:~/HAP-NodeJS $ node Core.js
module.js:340
throw err;
^
Error: Cannot find module 'debug'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/home/pi/HAP-NodeJS/lib/Accessory.js:3:13)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
Reply 6 years ago
I should mention that I tried:
sudo npm insgall debug
npm install mdns
npm rebuild
6 years ago
Will this work on pi 3, too ?
Reply 6 years ago
1 in 1 not work, need some modification. I have not pi 3, cannot test it.
Reply 6 years ago
Same with the newest pi 2 as i know.
6 years ago
Ok I need Help
So I did everything like you said and every time I run node Core.js it says
Pls Help
Reply 6 years ago
Maybe a syntactic error in the js file? check {}, characters.
6 years ago
Good day Imre,
I have created a Homekit light switch with the Raspberry Pi
Zero. Everything work perfectly except I want to take it a step further:
Is the a line of code that I can run on the Raspberry Pi
itself to switch off the light AND notify the Core.js service that the light
has been turned off?
Currently I can run the light0.py file and turn off the
light but the Homekit service does not know about this change and my phone
(Home app) still shows that the light is on.
Ultimately what I want to do is to add a button (Switch) on
the GPIO pins to control the light from the switch and my phone. Can you please
help me?
Thank you in advance
6 years ago
Help please ı realy need to do it
6 years ago
This
6 years ago
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
7 years ago
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..
pi@raspberrypi:~/HAP-NodeJS $ node Core.js
*** WARNING *** The program 'node' uses the Apple Bonjour compatibility layer of Avahi.
*** WARNING *** Please fix your application to use the native API of Avahi!
*** WARNING *** For more information see <http://0pointer.de/avahi-compat?s=libdns_sd&e=node>
*** WARNING *** The program 'node' called 'DNSServiceRegister()' which is not supported (or only supported partially) in the Apple Bonjour compatibility layer of Avahi.
*** WARNING *** Please fix your application to use the native API of Avahi!
*** WARNING *** For more information see <http://0pointer.de/avahi-compat?s=libdns_sd&e=node&f=DNSServiceRegister>
HAP-NodeJS starting...
Parsing accessory: Fan_accessory.js
Parsing accessory: GarageDoorOpener_accessory.js
Parsing accessory: Light_accessory.js
Parsing accessory: Lock_accessory.js
Parsing accessory: TemperatureSensor_accessory.js
Parsing accessory: Test_accessory.js
Parsing accessory: Thermostat_accessory.js
events.js:160
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE :::51826
at Object.exports._errnoException (util.js:1008:11)
at exports._exceptionWithHostPort (util.js:1031:20)
at Server._listen2 (net.js:1253:14)
at listen (net.js:1289:10)
at Server.listen (net.js:1385:5)
at EventedHTTPServer.listen (/home/pi/HAP-NodeJS/lib/util/eventedhttp.js:58:19)
at HAPServer.listen (/home/pi/HAP-NodeJS/lib/HAPServer.js:155:20)
at Accessory.publish (/home/pi/HAP-NodeJS/lib/Accessory.js:480:16)
at /home/pi/HAP-NodeJS/Core.js:32:13
at Array.forEach (native)
Reply 6 years ago
I'm getting the same errors. Did you solve the problem?
Reply 6 years ago
To solve the EADDRINUSE :::51826 error, we just need to reboot the RPi.
6 years ago
hi!
i try to install for myself... and get some errors in the step 2-9..
and when execute : node Core.js get they error and dont run...
(Thank for help)
module.js:339
throw err;
^
Error: Cannot find module 'debug'
at Function.Module._resolveFilename (module.js:337:15)
at Function.Module._load (module.js:287:25)
at Module.require (module.js:366:17)
at require (module.js:385:17)
at Object.<anonymous> (/home/pi/HAP-NodeJS/lib/Accessory.js:1:75)
at Module._compile (module.js:435:26)
at Object.Module._extensions..js (module.js:442:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:311:12)
Reply 6 years ago
looks like you need is install debug
Sudo npm install debug
6 years ago
finally works!, the server start well, i add the accessory, but the led dont turn on...
in the test of the python files, led turn on and off..
Reply 6 years ago
Where is your python file?
Reply 6 years ago
the same as in the example, light1.py and light0.py
I put the file path and it works,
/python/light0.py
/python/light1.py