HomeKit and Particle Photon integration


After viewing this great example by Nikita Leonov, I decided to work on HomeKit and Particle Photon. My plan was simulate Temperature, Humidity and Luminosity sensor and one Light. Here is the sample I completed.

Here in this sample, I am using Homebridge and HAP-NodeJS to emulate HomeKit API. Homebridge is a shim around HAP-NodeJS. HAP-NodeJS is a Node.js implementation of HomeKit Accessory Server.

Homebridge supports 2 types of shims, accessory and platforms. Accessory is a single or multiple accessory device. Platform a bridge to another system. In HAP-Node-JS each accessory has require Characteristics which must be implemented by the Accessory and some optional Characteristics which is optional. For this sample I created an accessory which emulates 4 devices, Temperature Sensor, Humidity Sensor, Luminosity Sensor and a Light. The Light supports brightness and hue characteristics. My Homebridge app is running on my Macbook Pro (you can Raspberry Pi or any Linux system also, I tried to compile Homebridge under Cygwin but failed).

DHT22 sensor is used to read Temperature and Humidity, TSL2561 sensor is
used for luminosity. To simulate light I am using a simple RGB Led. The Photon firmware reads Temperature, Humidity and Luminosity sensor values and publish an event at every 5 seconds.

The Particle Accessory listens for this events and whenever it is received, update the Characteristics. To control the light, the accessory calls Photon exposed functions to turn on/off, adjust brightness and set hue.


  1. DHT22 Vcc to Photon 3.3v
  2. DHT22 GND to Photon GND
  3. DHT22 Data to Photon D4
  4. TSL2561 3.3vto Photon 3.3v
  5. TSL2561 GND to Photon GND
  6. TSL2561 SDA to Photon D0
  7. TSL2561 SCL to Photon D1
  8. RGB Led R to Photon A4
  9. RGB Led G to Photon A5
  10. RGB Led B to Photon A7
  11. RGB Led GND to Photon GND

How to run

  1. Setup Particle Photon:- Wire the sensors as described above and compile the firmware source code and flash it to the Photon.

  2. Configure Homebridge:- Copy the Particle.js file to the Homebridge Accessory folder. Edit the config.json and add following under accessory section and replace the device id and access token.
    “accessory”: “Particle”,
    “name”: “Particle Sensors”,
    “cloud_url”: “https://api.spark.io/v1/devices/”,
    “deviceid”: “replace with your deviceid”,
    “accesstoken”: “replace with your access token”

  3. Open a terminal and run node app.js. If everything goes well you can see the Homebridge is up and running. Take a note of the PIN that is shown on the console. This is necessary to add the accessory to the iOS application. In every 5 seconds you can also see the sensor values received.

  4. Control/Monitor using iOS Device:- Install any HomeKit application. There are different HomeKit application on iOS device. Some of them are free and some are paid. I have Home, Elgato Eve and Insteon+ installed on my iPhone. Open the app and add the accessory, when the device scan for accessory you can see Homebridge, under this every accessories will be listed. While adding you have to enter the PIN. Enter the pin shown on the console while running the Homebridge.


Demo Video

Controlling a Light using HomeKit application

Using Siri to control light


This looks amazing! It’s exactly what I’m looking for as my next Particle project.

I’ve only got the Particle Core though, so I’ll give it a go on that. Has anyone else had luck on the Core?

@Jeff, it should work on Particle Core also, it does not have any Photon dependency. The Photon read sensor values from TSL2561 and DHT22, also connected to RGB LED.

So awesome!

1 Like

@krvarma Thanks! The code seems to work on the Core, but I’m having some trouble getting HomeBridge working. I’ve tried on Raspberry Pi (both 1 and 2) and Ubuntu in Parallels, but I’m getting stuck with different errors.

So far I’ve had the most luck in Ubuntu, but I’m just stuck on the Particle accessory… I’ll get back to it tomorrow, it’s time to call it a night.

@Jeff, I too had some issues installing on Ubuntu, but I managed it after manually installing some dependencies. I don’t exactly remember which are the dependencies. Even though I managed to install it on Ubuntu, I am not using. I am using my Macbook Pro and Raspberry Pi for development.

You can check this video explaining installation on RPi, may be that will be useful.

@krvarma I don’t think your video link posted :no_mouth:

Oh… extremely sorry :frowning:, here it is

1 Like

Thanks @krvarma – I’ve almost got it working! Now I am just stuck on this error:

Loading 1 accessories...
    throw err;
Error: Cannot find module 'eventsource'
    at Function.Module._resolveFilename (module.js:336:15)
    at Function.Module._load (module.js:278:25)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at Object.<anonymous> (/home/pi/homebridge/accessories/Particle.js:4:19)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)

I have looked at the configuration files but I just can’t seem to figure out what these error message mean (I’m pretty new to node, this is my first foray into it…)

Hi @Jeff,

If it’s a node app, make sure you run npm install to install any missing modules :slight_smile:


Another option is to run npm install eventsource

Aha! That got it working.

I had some trouble with my Core, and it seems like it might also be having some issues with the lower amount of memory available to it.

I don’t need the Lux or RGB for my relay, so I’m going to try to remove those bits and work on adding a IR output instead to turn on my air conditioner.

The other thing I can’t quite work out is why Siri will happily turn the light on or off but can’t tell me the temperature or humidity using the particle readings.

can someone help me with following error please?

Loading 0 platforms…
Loading 1 accessories…
[Particle Sensors] Initializing Particle accessory…
https://api.spark.io/v1/devices/(mydevice)/events/HKSValues?access_token= my access token)

if (!UUID) throw new Error(“Services must be created with a valid UUID.”);
Error: Services must be created with a valid UUID.
at new Service (/Users/ritchyromero/Documents/homebridge/node_modules/hap-nodejs/lib/Service.js:38:20)
at parseServiceJSON (/Users/ritchyromero/Documents/homebridge/node_modules/hap-nodejs/lib/AccessoryLoader.js:114:17)
at /Users/ritchyromero/Documents/homebridge/node_modules/hap-nodejs/lib/AccessoryLoader.js:63:19
at Array.forEach (native)
at Object.parseAccessoryJSON (/Users/ritchyromero/Documents/homebridge/node_modules/hap-nodejs/lib/AccessoryLoader.js:62:17)
at createAccessory (/Users/ritchyromero/Documents/homebridge/app.js:153:28)
at loadAccessories (/Users/ritchyromero/Documents/homebridge/app.js:89:25)
at startup (/Users/ritchyromero/Documents/homebridge/app.js:60:29)
at Object. (/Users/ritchyromero/Documents/homebridge/app.js:223:1)
at Module._compile (module.js:456:26)

(edited out access token)

@ritch, which OS you are using? Also I assume you have replaced your deviceid and access token in config.js

@krvarma tnx for the fast reply… And sorry for the lack of information given in my previous post.

I’m using a mac with OSX…
Because i’m not familiar with js i can only follow the steps given by the tutorial :frowning:

I did move (and edit with my tokens) the config file to the homebridge directory and i did move the particle file to the homebridge/accessories directory…

The error talks about the service not having a correct uuid?

Tnx for any help !!!

@ritch, just to make sure that your installation is correct, can you use the default config.js file and try?

Also you can try changing the "username": "CC:22:3D:E3:CE:67" in the config.js file, just to make sure to use a new username.

I know this thread was closed some time ago, but as it was the original one around Homebridge, I post my link also here:

Yesterday I have received an RPi3 B+ and I’m in the middle of setting up Homebridge now.
But right now I’m stuck!

=> Continued in this new thread:

1 Like

FINALLY, we have a breakthrough!

Lukas Jezny developed an application for a Photon, in which he implements a HAP (Homekit Access Point) on the device itself. So, you don’t need a Homebridge or an OpenHAB server to control a Photon with Siri… :star_struck:

See this new thread: LINK

It works beautifully: You compile a sketch and flash it to any Particle device and then it can be directly paired with Homekit on any iPad, iPhone… Currently, you can only control the Particle’s RGB LED ON/OFF state.

I was hoping that Lukas would also show us how we could access Particle.function s and Particle.variable s from Homekit. But, fair enough, he apologised because he can’t make the time for it. Pity…
He shared also the Apple document explaining how to expand the functionality, but it goes over my head!
If some of you, professional programmers, would be interested to try and expand his work, I believe many Particle users would be very happy! I would… :bow:

1 Like