Introduction: Arduino and Apple HomeKit Integration - Control Your Home From Siri! IoT Is Here

Picture of Arduino and Apple HomeKit Integration - Control Your Home From Siri! IoT Is Here

This Instructable will give you a quick and easy way to add an arduino board to Apple's HomeKit on an iOS device. It opens up all sorts of possibilities including Scripts running on the server, combined with Apples HomeKit "Scenes", it makes for a powerful combo!

This is by no means a complete solution or ready for long term use but it demonstrates what's possible with a bit more work :)

Whats needed:

  • Arduino with Ethernet Shield or WiFi
  • Raspberry Pi or some other server
  • Solid State Relay or Normal relay with control circuit
  • Bread board - optional
  • Project Box
  • Some Time
  • iOS device
  • Extension Lead to carve up

Step 1: Setup the Server

Picture of Setup the Server

This project requires the use of a server to run the HomeBridge software. I used a Raspberry Pi as I had it readily available but in theory anything that can run Node.Js should work!

You can follow this guide here to get this up and running on a Raspberry Pi. Other instructables are around to build a Raspberry Pi if you need those!

https://github.com/nfarina/homebridge/wiki/Running...

Once installed you need install a plugin and customise the config.json file

Step 2: Config and Plugins

Open your config.json file which should be in ~/.homebridge/config.json using your favourite text editor and add the following

{
"bridge": {

"name": "Homebridge",

"username": "CC:22:3D:E3:CE:30",

"port": 51826,

"pin": "031-45-154"

},

"platforms": [

],

"accessories": [

{

"accessory": "Http",

"name": "Living Room Lamp",

"on_url": "http://192.168.1.201:80/?on",

"off_url": "http://192.168.1.201:80/?off",

"http_method": "GET"

}

]

}

You will also need to install the homebride-http plugin. The HomeBridge software will make HTTP GET requests to the Arduino which will then turn the Solid State Relay on or off. The call looks like this:

http://192.168.1.X:80/?on

http://192.168.1.X:80/?off

To install the plugin type:

npm install homebridge-http

Step 3: Setup the Solid State Relay

Picture of Setup the Solid State Relay

I have used quite a heavy duty Solid State Relay. This can be (and will be in future versions of this) replaced for something much smaller. Obviously rate this for the load you intend to run off it.

This is effectively a 'Smart' extension lead now.

The positive Leg of the Solid State relay will connect to pin 5 on the arduino.

The negative will connect to the GND pin.

All usual warnings apply when dealing with 120/ 220 vdc - TAKE CARE.

Step 4: Connect the Solid Sate Relay and Upload the Arduino Code

Picture of Connect the Solid Sate Relay and Upload the Arduino Code

Open up your arduino environment and upload this sketch.

Customise your IP address as needed.

This should now be ready for testing.

Launch homebridge on the server!

Step 5: Test!

Picture of Test!

Now that everything is in place its time to test!

Download Elgatu Eve from the App Store on you iOS device.

You should see Homebridge as an accessory available to be connected. Use the pin number 031-45-154, this can be customised in the config.json file.

Once connected you can move this around within the App into the desired Room etc. Give Siri a test! It should be able to control the relay using voice!

Step 6: Next Steps

The plan is to shrink this down and use something like a Nano and embed this in Lightswitches / wall sockets with much smaller Relays and use WiFi for a complete Home Automation system.

Hope someone gets some use out of this! Many thanks to Nick Farina for his work on the Homebridge Software!

A video is coming soon.

Check out my blog:

www.arduinoblogger.com

Comments

bernigibtsschon (author)2017-09-01

Hej, thank you for your great tutorial! What I didn't understand:

- What exactly is the purpose of node.js?

- If I do not want to use a raspberry pi (I do not have any), what are my options? I heard that Homekit devices can be controlled by AppleTV -- can I use the AppleTV for this project, too? And how?

DolboD (author)2017-08-02

why do you need arduino if you use raspberri bi? it would be cool to use just arduino and run the homekit server there

PiergentiliA (author)2016-02-21

Hello ... I did it. Only a problem. the pin5 is high for a while and soon low. I checked the code from the web page with out homebridge. I'm afraid that a delay for the links (on and off) are necessary because you activate on and off at the same time. Can you check the code? a request ... How to add more controls ( 2 or more relay)?

bgodsell (author)PiergentiliA2016-08-20

use this instead. It did the trick for me...

if(readString.indexOf("?on") >0)//checks for on

{...}

if(readString.indexOf("?off") >0)//checks for off

{...}

ArthurM96 (author)bgodsell2017-06-06

This was what I was looking for!!

GalenW1 (author)bgodsell2016-09-17

thank you that was driving me crazy i spent an hour trying to fix it myself

andyman5002 (author)2017-02-25

I've redone my blog http://www.arduinoblogger.co.uk. Going to start updating it with more projects and post them here too!

jackwan1 (author)2017-02-21

Hi I am 99%, I got the homebridge loaded on Ubuntu and was able to pair the homebridge on Elgato Eve, the only problem is after that homebridge appeared as an accessory, I still have no control of my device. siri does not seem to recognize the command "please open my Garage Door" in the Eve "setup" I saw Accessory Name "Homebridge" Manufacturer: default, Model: default, serial number: default The homebridge is in room garage and the above setup is in the "accessory Info" Am I missing some thing?

Of course, I've changed the ip addresses to a static address. Homebridge also recognized my name change to "My Garage Door" instead of "Living Room Lamp". The arduino code loaded up without a hitch. I am using an Xboard, which is combined Arduino Leonado and two relays. The relays are on D7 and D8 so I made the appropriate changes in the .ino skatch as well. I used ping 7 instead of ping 5 and made the changes throughout the skatch

SamuelB140 (author)2016-12-29

Awesome tutorial! I'm up and running, but am wondering if there's a way I could use an Arduino without using an ethernet connection. Could I somehow use the USB? Maybe using something like this?

https://www.instructables.com/id/Internet-Controlled-Arduino-no-Ethernet-shield/step2/Getting-Started-Arduino-Part/

andyman5002 (author)SamuelB1402017-02-06

yes you could use USB. You would need to parse the commands via the serial interface instead.

ajain20 made it! (author)2016-11-06

I am almost there but this section of config.json is causing pain. When I remove this, all good..Is there any known issue this code?

TheMartinDobson2 (author)ajain202016-11-08

My set up didn't have an issue with it. What error seems to be happening?

TheMartinDobson2 made it! (author)2016-10-25

I couldn't end up getting the Raspberry Pi to install the homebridge-http plugin even after multiple attempts. For some reason it was saving it to an odd directory and not one that Homebridge wanted it to be in. So I would constantly get an error saying that it couldn't find any plugins. Weird. I'll have to revisit the Pi3 server part another day.

I did however use the majority of your tutorial and the one you linked to above to get the Node.js and Homebridge running in a terminal window on my Mac. After some playing around I was able to get my phone talking to the Mac, and then after altering the Arduino code a bit (and setting up a DHCP reservation IP address through my router for the Arduino) I managed to get it to communicate with the Arduino. Then, after all that was done, I read the other comments below (Credit: @bgodsell) and got the Arduino's external relay module to control properly. [Note for anyone in the future using an external relay module: Most of them are a switch LOW to activate relay, so wiring up as NC or some editing of the Arduino activation code may be necessary]

I'm also curious anyone knows how to edit the config.json file to get more items added and to properly populate the devices with full Metadata. Currently, it shows my switch as a "default-manufacturer" etc. Doesn't really matter but really finishes off this customization. Do you have any ideas or examples for this?

Thanks for the great tutorial!

Glad you found it useful!

Also, for anyone who is having issues with getting communication to your Arduino's ethernet shield, make sure that you have set up the static IP address in your router's settings. I typically reserve IPs that are in the high range of supplied IPs so as to not have the possibility of any two getting into an IP conflict. (Ie, range is 10.0.1.2->10.0.1.200, My raspberry Pi is at 10.0.1.199, and the Arduino is at 10.0.1.197)

Once the static IP addresses have been assigned and you're still getting connectivity issues, run a ping test to the devices. Supplying power to my Arduino would confuse the Ethernet shield, so often either an Arduino reset, power cycle, and/or unplugging/replugging the ethernet cord would fix any connectivity issue.

Open a terminal window on your Mac, Or cmd window on a Windows Machine, type: ping 10.0.1.197 (this is the Specific IP address you have assigned to your Arduino in the .ino sketch file and in your router's DHCP reservation)

An error will be returned if there is an issue communicating with the Ethernet Sheild, and once the error has been corrected you will start getting time response from the sheild. (See attached photo)

Zavin (author)2016-10-20

Hey. Can it be done vwith arduino and Bluetooth module??

GabrielC191 (author)2016-10-18

Hi, I am a newbie with these stuffs. Very nice post. But I am a little bit confused: why using a raspberry pi and an arduino? I mean, why not to use only a raspberry pi? Thanks

aslater4 (author)GabrielC1912016-10-19

No reason really other than I am more comfortable with the platform! In theory you can use the GPIO pins on the RPi to achieve the same results!

MoniCris (author)2016-10-08

This is my project with RPi 2

MoniCris (author)2016-10-08

Nice project. I've done this project only with RPi 2, but not with arduino. As soon I can, i'l make it. Thanks.

Stoner221 (author)2016-09-24

Very well done. Works like a charm.

GalenW1 (author)2016-09-17

Ok i get Homebridge to show up in iOS Home app, but not the "Living Room Lamp" accessory, it is never listed. what am I missing? thanks

GalenW1 (author)GalenW12016-09-17

finally got the Living Room Lamp accessory to show on my iphone my recopying/pasting the text into BOTH /home/pi/.homebridge/config.json AND /var/homebridge/config.json

thx this is cool

andyman5002 (author)GalenW12016-09-19

Glad its working :)

poseido (author)2016-06-23

hello; manu thanks for the instructable!

All worked fine on my raspberry pi 3, except at the very end, after installing the plugin (no error there) and editin the config.json file.. I try to run again homebridge and get this errors:

[6/23/2016, 10:41:15 AM] No plugins found. See the README for information on installing plugins.

[6/23/2016, 10:41:15 AM] Loaded config.json with 1 accessories and 0 platforms.

[6/23/2016, 10:41:15 AM] ---

[6/23/2016, 10:41:15 AM] Loading 0 platforms...

[6/23/2016, 10:41:15 AM] Loading 1 accessories...

/usr/local/lib/node_modules/homebridge/lib/api.js:60

throw new Error("The requested accessory '" + name + "' was not registered by any plugin.");

^

Error: The requested accessory 'Http' was not registered by any plugin.

at API.accessory (/usr/local/lib/node_modules/homebridge/lib/api.js:60:13)

at Server._loadAccessories (/usr/local/lib/node_modules/homebridge/lib/server.js:233:42)

at Server.run (/usr/local/lib/node_modules/homebridge/lib/server.js:72:38)

at module.exports (/usr/local/lib/node_modules/homebridge/lib/cli.js:40:10)

at Object.<anonymous> (/usr/local/lib/node_modules/homebridge/bin/homebridge:17:22)

at Module._compile (module.js:434:26)

at Object.Module._extensions..js (module.js:452:10)

at Module.load (module.js:355:32)

at Function.Module._load (module.js:310:12)

at Function.Module.runMain (module.js:475:10)

any hint?

poseido (author)poseido2016-06-23

just needed to install npm install homebridge-http using sudo:

sudo npm install homebridge-http

andyman5002 (author)poseido2016-09-15

Glad you liked it and glad its working!

007falvaro (author)2016-03-21

I suppose that in order to add more devices you should add them to the array in the raspberry pi?

About This Instructable

114,733views

177favorites

License:

Bio: @arduinoblogger
More by andyman5002:Arduino and Apple HomeKit Integration - Control Your Home From Siri! IoT Is HereArduino Routing Protocol RIPv1 Spoofer / Network Jammer - Ethernet Shield Tutorial
Add instructable to: