A few weeks back I made a RGB Light for my homebridge, now I wanted to see if I could make a NeoPixel Light.

First I needed a NeoPixel Led strip so I found this one.

For those who haven’t read my previous post, you must first install HomeBridge on a Raspberry Pi, and configure it as a HomeKit bridge device. For who did’t read my previous  post about the Raspian Pi update, there are a few thing changed! first read this post https://www.studiopieters.nl/raspberry-pi-a-security-update-for-raspbian-pixel/

So once again we have to alter a few things in the installation process. For a headless installation we need to add the ssh file to the root of the SD-Card. This in order to connect to the Raspberry Pi. After we have done this we can install Xrdp as described in this post https://www.studiopieters.nl/raspberry-pi-remote-desktop-connection/

But then I stumbled on a new problem.It has to do with the fact that the Raspbian Jessie with pixel, which officially stands for “Pi Improved Xwindows Environment, Lightweight”, now comes pre-packaged with RealVNC, which conflicts with both xrdp (which uses vnc4server) and tightvncserver.

So I needed a solution: Google me this google me that….

The fix:

Let’s assume you already did sudo apt-get update and sudo apt-get install xrdp.

Now, let’s disable the RealVNC install. I have tested this and followed these steps to disable the RealVNC install and allow xrdp to work:

sudo apt-get remove xrdp vnc4server tightvncserver

sudo apt-get install xrdp

Remote logins using xrdp now work. After this you can make a remote connection and follow the steps as described in this post https://www.studiopieters.nl/raspberry-pi-apple-homebridge/

When you have installed the homebridge you need to install the Homebridge-NeoPixel package in order to let the homebride communicate with your ESP8266 over http.

Edit the HomeBridge /var/homebridge/config.json file on the Raspberry Pi HomeBridge. the file may alternatively be in /home/.homebridge or /root/home/./homebridge.

add this code to the config.json file.

sudo nano ~/.homebridge/config.json

mind the last comma, you may or may not need it if you have other accessories, or Homebridge is crashing on load.

   "bridge": {
      "name": "Homebridge",
      "username": "CC:22:3D:E3:CE:30",
      "port": 51826,
      "pin": "031-45-154"

"description": "Example configuration file for Apple Homebridge - NeoPixel",

"platforms": [


"accessories": [
{    "accessory": "HTTP-NEO",
"name": "Neo Lamp",

"switch": {
"status": "",
"powerOn": "",
"powerOff": ""

"color": {
"status": "",
"url": ""

"brightness": {
"status": "",
"url": ""


The Hardware

Now we can make our setup so we can see if everything is working. In the fritting digram below you can see that now I have added a NeoPixel Strip plus a external power supply 5V 1A.
We are keeping the RX and TX connected so we can see in the monitor from the Arduino IDE if everything is working as we want to.

Upload the program below to your ESP8266-12E

/* Project name: Apple Homebridge - NeoPixel  
*  Project URI: https://www.studiopieters.nl/apple-homebridge-neopixel-light 
*  Description: Apple Homebridge - NeoPixel Light
*  Version: 6.0.3 
*  License: GNU General Public License V2 or later  */

#include <ESP8266WiFi.h>
#include <Adafruit_NeoPixel.h>
#include <math.h>

// Which pin On which pin is the ESP8266-12E connected to the NeoPixels
#define PIN 13

// How many NeoPixels are attached to the ESP8266-12E
#define NUMPIXELS      144
// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
//   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMPIXEL, PIN, NEO_GRB + NEO_KHZ800);


WiFiServer server(80); //Set server port

String readString;           //String to hold incoming request
String hexString = "000000"; //Define inititial color here (hex value)

int state;

int r;
int g;
int b;

float R;
float G;
float B;

int x;
int V;

///// WiFi SETTINGS - Replace with your values /////////////////
const char* ssid = "YOUR_ROUTER_SSID";
const char* password = "YOUR_ROUTER_PASSWORD";
IPAddress ip(192,168,1,10);      // set a fixed IP for the NodeMCU
IPAddress gateway(192,168,1,1);  // Your router IP
IPAddress subnet(255,255,255,0); // Subnet mask

void WiFiStart() {
  Serial.print("Connecting to ");
  WiFi.begin(ssid, password);
  WiFi.config(ip, gateway, subnet);
  while (WiFi.status() != WL_CONNECTED) {
  Serial.print("IP address: ");


void allOff() {
  for(int i=0;i<NUMPIXELS;i++)
  strip.setPixelColor(i, 0, 0, 0);

//Write requested hex-color to the pins
void setHex() {
  state = 1;
  long number = (long) strtol( &hexString[0], NULL, 16);
  r = number >> 16;
  g = number >> 8 & 0xFF;
  b = number & 0xFF;

  for(int i=0;i<NUMPIXELS;i++)
  strip.setPixelColor (i, r, g, b);

//Compute current brightness value
void getV() {
  R = roundf(r/2.55);
  G = roundf(g/2.55);
  B = roundf(b/2.55);
  x = _max(R,G);
  V = _max(x, B);

//For serial debugging only
void showValues() {
  Serial.print("Status on/off: ");
  Serial.print("RGB color: ");
  Serial.print("Hex color: ");
  Serial.print("Brightness: ");

void setup(){
  setHex(); //Set initial color after booting. Value defined above
  showValues(); //Uncomment for serial output

  strip.show(); // Initialize all pixels to 'off'

void loop() {
  //Reconnect on lost WiFi connection
  if (WiFi.status() != WL_CONNECTED) {
  WiFiClient client = server.available();
  if (!client) {
  while(client.connected() && !client.available()) {
  //Respond on certain Homebridge HTTP requests
  if (client) {
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        if (readString.length() < 100) {
          readString += c;
        if (c == '\n') {
          Serial.print("Request: "); //Uncomment for serial output
          Serial.println(readString); //Uncomment for serial output
          //Send reponse
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          if(readString.indexOf("on") >0) {
          if(readString.indexOf("off") >0) {

          //Set color
          if(readString.indexOf("set") >0) {
            hexString = "";
            hexString = (readString.substring(9,15));
          //Status on/off
          if(readString.indexOf("status") >0) {

          //Status color (hex)
          if(readString.indexOf("color") >0) {

          //Status brightness (%)
          if(readString.indexOf("bright") >0) {

Now we have to connect our iPhone to the home bridge and add the new accesoires.

Hooray! It works!

Smug GIF - Find & Share on GIPHY

Download all Files for this project on github

Do you have any questions? Leave a comment down below!

Pin on Pinterest1Share on Facebook0Share on Google+1Tweet about this on TwitterShare on LinkedIn0Buffer this pageDigg thisEmail this to someone
Flattr the authorShare on Reddit0Share on StumbleUpon0Share on Tumblr0Share on VKShare on Yummly0
  • Should this work with neopixel ring as well?

  • Yes, this should work with a NeoPixel Ring as well!
    I would recommend reading Adafruit NeoPixel Überguide for more information.

  • Thanks! Will try tonight!

  • Great! Let me know how it worked out!

  • Should the URLs be pointed towards a server or to the ESP8266’s static IP?
    I’ve only been using MQTT before.

  • The IP address has to correspond with the ESP8266’s static IP. This way the homebridge server and your ESP can communicate.

  • Got it working with a 16-diode ring! looks great! Thanks for the tutorial

  • You’re welcome!

  • Please share my post on your social media, so more people can enjoy this post!

  • Jimmy Patrick

    Can this work at the same time as ‘homebridge-better-http-rgb’? It doesn’t on my system. everything gets stuck with a status of “Updating.”

  • As far as I know it should work, The error you describe is sounding familiar, make shore your hardware is connected properly. This error appears when there something wrong with the power supply, your ESP wil reset. Therefor make shore you have the right capacitors and your power supply is sufficient (5V, 1A). This should resolve your problem.

  • Jimmy Patrick

    I see. So is each homebridge-neopixel blocking? So if one of my ESPs goes down it will stop my entire hombridge from updating? Is there a timeout, where I there is no response, that can be noted for that fixture, and homebridge can carry on? I’m not sure how to see the source of an NPM, and I don’t understand much about javascript, but I’ll take a look. Thanks for the response!

  • Lethegrin

    Is there a way to add options when selecting the light to trigger a custom light pattern? These are neopixels after all! i.e. could I add a “rainbow chase” option which would activate a rainbow animation that I added to the flashed program?

  • That should be possible you need to add code: https://learn.adafruit.com/multi-tasking-the-arduino-part-3/recycling-the-rainbow to the Arduino Part, then you need to add the option to the plugin so that when you want the “rainbow” to show, Siri knows that when you ask for the “rainbow” it has to excute this code.

    if you want it always, when you turn it on or of, to show the “rainbow”just replace:

    //Write requested hex-color to the pins

    void setHex() {

    state = 1;

    long number = (long) strtol( &hexString[0], NULL, 16);

    r = number >> 16;

    g = number >> 8 & 0xFF;

    b = number & 0xFF;

    for(int i=0;i<NUMPIXELS;i++)

    strip.setPixelColor (i, r, g, b);



    with the rainbow code, so it will execute 😉

    Good luck, and let us know when you have it working!

  • Lethegrin

    Hey, thanks for the reply. I’m not looking to replace any of the RGB functionality. I would simply like to add for example “rainbow” as an option as you suggested. Could you give me an example of what I would need to add to your plugin to get siri to recognize it as an option? I’m not familiar with it.

  • Well there isn’t a out of the box solution for that. You need to know how to program in C or C++, JavaScript Object Notation. if you have this knowledge, then i would recommend reading the information that the founder of homebridge added regarding plugins (https://github.com/nfarina/homebridge) the plugins are based upon a NPM package using HAP-NodeJS. It took me also some time gathering all information needed to setup this plugin in and hardware. As I’m sharing this information for free, there are somethings you need to figure out yourself.

  • Lethegrin

    I see. Well I’ll do some research.