Tutorial:: Christmas Lights

Hi there,

I created a small rule which can be used for this Christmas season :slightly_smiling_face:
Trigger this rule to create a real Christmas lightshow, ho ho ho.

I have some pixel led strings bought from aliexpress. These are ws2812 leds and can be any rgb color. It works with any ws2811 or ws2812 using the neopixel item in easyesp.

You just have to use a esp8266 (I use: wemos d1 mini pro) and flash the rom with easyesp software.
In openhab you have to configure a MQTT server to communicate to this esp8266. There are plenty of tutorials for this…

After setting up this properly this is the setting for NeoPixel in easyesp:

In Openhab Items I created this items:
NOTE: You can use KitchenLedColor to directly switch color, or KitchenLed to use it with another rule in order to use it within an openhab sitemap. If you are interested I can post this rule as well.

/* IoTCage104 */
Number   SystemInfo_104 "SystemInfo_104 Uptime [%s]"        <qualityofservice>      (Keuken)                {mqtt="<[broker:/IoTCage104/SystemInfo/Uptime:state:default]"}
Color    KitchenLed  "Kitchen Led [%s]"                       <colorlight>            (Keuken)  
String   KitchenLedColor                                                            (Keuken)                {mqtt=">[broker:/IoTCage104/cmd:command:*:default]"}

/* IoTCage105 */
Number   SystemInfo_105 "SystemInfo_105 Uptime [%s]"        <qualityofservice>      (Woonkamer)                {mqtt="<[broker:/IoTCage105/SystemInfo/Uptime:state:default]"}
Color    LivingLed1  "Livingroom Led1 [%s]"                       <colorlight>            (Woonkamer)  
String   LivingLedColor1                                                            (Woonkamer)                {mqtt=">[broker:/IoTCage105/cmd:command:*:default]"}

/* IoTCage106 */
Number   SystemInfo_106 "SystemInfo_106 Uptime [%s]"        <qualityofservice>      (Woonkamer)                {mqtt="<[broker:/IoTCage106/SystemInfo/Uptime:state:default]"}
Color    LivingLed2  "Livingroom Led2 [%s]"                       <colorlight>            (Woonkamer)  
String   LivingLedColor2                                                            (Woonkamer)                {mqtt=">[broker:/IoTCage106/cmd:command:*:default]"}

From a MQTT client you can test if it all works by:

// List of commands:
// (1) NeoPixel,<led nr>,<red 0-255>,<green 0-255>,<blue 0-255>
// (2) NeoPixelAll,<red 0-255>,<green 0-255>,<blue 0-255>
// (3) NeoPixelLine,<start led nr>,<stop led nr>,<red 0-255>,<green 0-255>,<blue 0-255>

// Usage:
// (1): Set RGB Color to specified LED number (eg. NeoPixel,5,255,255,255)
// (2): Set all LED to specified color (eg. NeoPixelAll,255,255,255)
// If you use ‘NeoPixelAll’ this will off all LED (like NeoPixelAll,0,0,0)
// (3): Set color LED between <start led nr> and <stop led nr> to specified color (eg. NeoPixelLine,1,6,255,255,255)

Now the magic stuff begins…

In openhab I created a rule named christmastime.rules

rule "christmas time"
when
    Item KitchenLight changed 
then
    
    sendCommand(Alexa_Speak, "Let's go, it's chrismas time")

    val redValue = "255,0,0"
    val greenValue = "0,255,0"
    val strip1_7 = "1,20,"
    val strip2_7 = "21,40,"
    val strip3_7 = "41,60,"
    val strip4_7 = "61,80,"
    val strip5_7 = "81,100,"
    val strip6_7 = "101,120,"
    val strip7_7 = "121,140,"
    
    var i = 1
    while ((i=i+1) < 30) {

        sendCommand( KitchenLedColor, "NeoPixelLine," + strip1_7 + redValue )
        sendCommand( KitchenLedColor, "NeoPixelLine," + strip2_7 + greenValue )
        sendCommand( KitchenLedColor, "NeoPixelLine," + strip3_7 + redValue )
        sendCommand( KitchenLedColor, "NeoPixelLine," + strip4_7 + greenValue )
        sendCommand( KitchenLedColor, "NeoPixelLine," + strip5_7 + redValue )
        sendCommand( KitchenLedColor, "NeoPixelLine," + strip6_7 + greenValue )
        sendCommand( KitchenLedColor, "NeoPixelLine," + strip7_7 + redValue )

        sendCommand( LivingLedColor1, "NeoPixelLine," + strip1_7 + redValue )
        sendCommand( LivingLedColor1, "NeoPixelLine," + strip2_7 + greenValue )
        sendCommand( LivingLedColor1, "NeoPixelLine," + strip3_7 + redValue )
        sendCommand( LivingLedColor1, "NeoPixelLine," + strip4_7 + greenValue )
        sendCommand( LivingLedColor1, "NeoPixelLine," + strip5_7 + redValue )
        
        sendCommand( LivingLedColor2, "NeoPixelLine," + strip1_7 + greenValue )
        sendCommand( LivingLedColor2, "NeoPixelLine," + strip2_7 + redValue )
        sendCommand( LivingLedColor2, "NeoPixelLine," + strip3_7 + greenValue )
        sendCommand( LivingLedColor2, "NeoPixelLine," + strip4_7 + redValue )
        sendCommand( LivingLedColor2, "NeoPixelLine," + strip5_7 + greenValue )
        Thread::sleep(800)

        sendCommand( KitchenLedColor, "NeoPixelLine," + strip1_7 + greenValue )
        sendCommand( KitchenLedColor, "NeoPixelLine," + strip2_7 + redValue )
        sendCommand( KitchenLedColor, "NeoPixelLine," + strip3_7 + greenValue )
        sendCommand( KitchenLedColor, "NeoPixelLine," + strip4_7 + redValue )
        sendCommand( KitchenLedColor, "NeoPixelLine," + strip5_7 + greenValue )
        sendCommand( KitchenLedColor, "NeoPixelLine," + strip6_7 + redValue )
        sendCommand( KitchenLedColor, "NeoPixelLine," + strip7_7 + greenValue )
        
        sendCommand( LivingLedColor1, "NeoPixelLine," + strip1_7 + greenValue )
        sendCommand( LivingLedColor1, "NeoPixelLine," + strip2_7 + redValue )
        sendCommand( LivingLedColor1, "NeoPixelLine," + strip3_7 + greenValue )
        sendCommand( LivingLedColor1, "NeoPixelLine," + strip4_7 + redValue )
        sendCommand( LivingLedColor1, "NeoPixelLine," + strip5_7 + greenValue )
        
        sendCommand( LivingLedColor2, "NeoPixelLine," + strip1_7 + redValue )
        sendCommand( LivingLedColor2, "NeoPixelLine," + strip2_7 + greenValue )
        sendCommand( LivingLedColor2, "NeoPixelLine," + strip3_7 + redValue )
        sendCommand( LivingLedColor2, "NeoPixelLine," + strip4_7 + greenValue )
        sendCommand( LivingLedColor2, "NeoPixelLine," + strip5_7 + redValue )
        Thread::sleep(800)

    }

    Thread::sleep(200)
    sendCommand(KitchenLed, "0,0,0")
    sendCommand(LivingLed1, "0,0,0")
    sendCommand(LivingLed2, "0,0,0")

    Thread::sleep(500)
    sendCommand(KitchenLed, "16,85,84")
    sendCommand(LivingLed1, "20,90,38")
    sendCommand(LivingLed2, "20,90,38")

end

So to sum it all up. When I switch the KitchenLight (for example) Alexa speaks and the led strips and pixels are flickering red and green. Merry Christmas!

2 Likes