Christmas RGB Animation

Cloe admiring my Christmas lights

My ESP8266 home control code contains not only RGB code for serial LEDs but also a complete programming setup to generate and loop sequences… and so with merely one wire and VERY  little work, we end up with some fancy animation.

Here we see an old, gutted plastic Christmas window decoration which WAS filled with old fashioned white lights but now has a string of 69 serial LEDs running animation around the inside.

I made one of these last year but when it came to trying out my animated LED Christmas lighting this year – nothing happened – dead. After wasting hours I remembered I’d changed the code earlier this year so for anyone using my ESP8266 software and wanting to knock up a quick Christmas animation – here it is…

My code lets you refer to a string of RGB lights - up to 300 of them and do things like -  make the first 10 LEDs RED and pause for a second, then make the second 20 LEDs GREEN and wait for 5 seconds, clear the lot wait 1 second. 

LED AnimationThat will then continue to do that forever in a loop – and that’s just a trivial example – here I set up a nice colourful display (the actual unit is white – no colour at all – the cat has nothing to do with anything.

This is now INCOMPATIBLE with earlier code so if you have something already running from last Christmas, you’ll need to add a new first parameter (1) to keep compatibility.

Here is how to make a Christmas light as above with yellow-white flashing tips…

if (msg.payload=="reset");

var steps=[


"{rgbadd:1,30,6,255,255,0,200}" ];

return msg;

Node-Red Flow

In the node-Red code above, I wait for the ESP to login as usual – and when it does I sent it a sequence of instructions, once, which will set up the display. Once set the code will do nothing more. Purple nodes are MQTT talking to the display unit which is called “xmas”

That function that says “Continue until end of array is merely this..

if (msg.payload!==undefined) return msg;

I’ve also included an “inject” mode for manual testing. It merely sends out text with the word “reset” in the payload.

Looking at the list above, the first command stops anything already running. The second sets up 94 LEDs on GPIO12 (count is the second parameter).

An example of a simple light up is the third instruction – code 1, from LED 8, light  up 15 LEDs in RED (255,0,0) for 5ms.

The other instructions are the same, lighting up segments of the display for X amount of time, I do the tips of the candles in white, wait a while then change them to yellow – the rest of the display is static – of course one could be a HELL of a lot cleverer than that. This is documented in the WORD document for the ESP8266 code.

There is also a command 4 which means END – you’d only use that if you wanted to perform a series of loops and then stop permanently. That has no parameters.

Assuming you’ve used the latter and have a sequence which does whatever and then stops – it might be nice to store this in FLASH and recall it when needed. There are four non-volatile buffers available to store this information.

{rgbstore:X} where X is 0-3

You can play back any of these as below, again assuming in this case GPIO12 and 12 LEDs. Set X to be 0-3


The above will play back a stored sequence immediately.

The code is in the usual place and available via the OTA. See Home Control blog.

As you can imagine – you could set up a LOT of this stuff as the code is only sent out once.  Limits are 1 strip of up to 300 RGB serial LEDs per ESP8266.


4 thoughts on “Christmas RGB Animation

  1. I might have missed something but I needed to make some changes to make this work. The "Continue to end of array" function needed this:
    if (msg.payload===undefined) msg.payload="reset";
    return msg;

    ... while the "check for powerup" needed this:
    if (msg.payload=="powerup") {msg.payload="reset"; return msg;}


  2. My bad, I didn't understand how the Home Control code was supposed to work and a faulty series of lights didn't help. With new LED lights, the original code works well.

    Didn't help that I was powering the ESP12 AND the lights from the USB socket on my lappy so I could send commands via YAT (a nice find by the way).

    Thanks Peter.

Leave a Reply

Your email address will not be published. Required fields are marked *