Ws2811 / ws2812 - ideas for christmas

Which effects do you use for led strings or strips?
I found the following configs quite nice, maybe somone else will find the code usefull, too :slight_smile:

    effects:
      - addressable_random_twinkle:
      - addressable_random_twinkle:
          name: Random Twinkle 20%
          twinkle_probability: 20%
          progress_interval: 32ms
      - addressable_random_twinkle:
          name: Random Twinkle 80%
          twinkle_probability: 80%
          progress_interval: 32ms
      - addressable_scan:
          scan_width: 4
      - addressable_color_wipe:
      - addressable_rainbow:
      - addressable_fireworks:
          name: "flash"
          update_interval: 32ms
          spark_probability: 30%
          use_random_color: false
          fade_out_rate: 120

random twinkle:

3 Likes

Red, Green, White Leds, pulsating

    effects:
      - addressable_lambda:
          name: "Christmas RedGreenWhite"
          lambda: |-
            static uint8_t *xLedInc=NULL;
            static int *xLedDim=NULL; // -255 ... 255
            static ESPColor *xLedColor=NULL;
            // ..... creates compiler warning .....
            #define getColor() \
                ESPColor color; \
                switch( (int) floor( random_uint32() / (double(UINT32_MAX)+1) * 3)) { \
                  case 0: color=light::ESPColor(255, 0, 18); break; \
                  case 1: color=light::ESPColor(0, 179, 44); break; \
                  default: color=light::ESPColor(255, 255, 255); break; \
                } \
                int dim=127+random_float()*128; \
                xLedColor[i]=color*dim;

            if(xLedInc==NULL) {
              xLedInc=new uint8_t[it.size()];
              xLedDim=new int[it.size()];
              xLedColor=new ESPColor[it.size()];
              for(int i=0; i < it.size(); i++) {
                xLedInc[i]=random_float()*8;
                xLedDim[i]=random_float()*511-255;
                getColor();
                // ESP_LOGD(TAG, "init [%d]=> b:%d %02x %02x %02x   => %02x %02x %02x", i, dim, color.red, color.green, color.blue,  xLedColor[i].red,  xLedColor[i].green,  xLedColor[i].blue);
              }
            }
            for (int i = 0; i <  it.size(); i++) {
              int dim=255 - abs(xLedDim[i]);
              ESPColor color=xLedColor[i] * dim;
              // if(i==0) ESP_LOGD(TAG, "[0]=> b:%d %02x %02x %02x",dim, color.red, color.green, color.blue);
              it[i] = color;
              xLedDim[i]+=xLedInc[i];
              if(xLedDim[i] > 255) {
                xLedDim[i]=-255;
                getColor();
              }
            }

color shift

    effects:
      - addressable_lambda:
          name: "random shift"
          update_interval: 16ms
          lambda: |-
            if(random_float() > 0.7)
              it[0] = ESPColor::random_color();
            else
               it[0] = ESPColor::BLACK;
            for (int i = it.size() -1 ; i > 0; i--) {
              it[i] = it[i - 1].get();
            }

slow color change:

    effects:
      - addressable_lambda:
          name: "color change"
          lambda: |-
            static ESPColor *xLedTargetColor=NULL;
            static ESPColor *xLedCurrColor=NULL;

            if(xLedTargetColor==NULL) {
              xLedTargetColor=new ESPColor[it.size()];
              xLedCurrColor=new ESPColor[it.size()];
              for(int i=0; i < it.size(); i++) {
                xLedCurrColor[i]=it[i].get();
                xLedTargetColor[i]=ESPColor::random_color();
                // ESPColor target= xLedTargetColor[i];
                // ESP_LOGD(TAG, "init [%d]=> %02x %02x %02x", i, target.red, target.green, target.blue);
              }
            }
            for (int i = 0; i <  it.size(); i++) {
              ESPColor &c=xLedCurrColor[i];
              ESPColor org=c;
              ESPColor target= xLedTargetColor[i];
              if(c.red == target.red && c.green == target.green && c.blue == target.blue) {
                xLedTargetColor[i]=ESPColor::random_color();
                // target= xLedTargetColor[i];
                // ESP_LOGD(TAG, "init [%d]=> %02x %02x %02x", i, target.red, target.green, target.blue);
              }
              if(c.red < target.red) {
                c.red++;
              } else if(c.red > target.red) {
                c.red--;
              }
              if(c.green < target.green) {
                c.green++;
              } else if(c.green > target.green) {
                c.green--;
              }
              if(c.blue < target.blue) {
                c.blue++;
              } else if(c.blue > target.blue) {
                c.blue--;
              }
              // ESP_LOGD(TAG, "change [%d]=> %02x %02x %02x  => %02x %02x %02x", i, c.red, c.green, c.blue, target.red, target.green, target.blue);
              it[i] = c;
              // if(i==0) ESP_LOGD(TAG, "change [%d]=> %02x %02x %02x  => %02x %02x %02x", i, org.red, org.green, org.blue,  it[i].get_red(), it[i].get_green(), it[i].get_blue());
            }

starry sky - random leds fading in/out slowly + comets

esphome:
[snip]
  includes:
    - colorTempToRGB.h
    - starsLambda.h

[snip]
    effects:
      - addressable_lambda:
          name: "starry sky"
          update_interval: 10ms
          lambda: |-
            starsLambda(it);

starsLambda.h: esphome starry sky lambda function Β· GitHub
colorTempToRGB.h: Color Temperature to RGB Β· GitHub

Feel free to use some of my code for more effects:
https://github.com/GlennGoddard/Lights
This is python but you can get the gist of it.
If you want to watch it (this is old, I have done updates since this video but get the idea across)
https://www.youtube.com/watch?v=RyhVeMgjnR4

It would be awesome if you could submit these effects as a PR to the ESPhome GitHub repo. The existing effects are pretty limited which is why I stopped using it for LED strips, switched to WLED. ESPhome has it’s benefit in that you can do more with a node than just the lights whereas WLED is purely for the LED strip so having extra effects would sway the decision a little more towards ESPhome.

Thanks for the ideas, I will have a look at it.
Another one, candle like flickering:

(imagine a colorfull yellow, orange, red video :smiley: )

      - addressable_lambda:
          name: "candles"
          update_interval: 16ms
          lambda: |-
            static int *target=NULL;
            static int *curr=NULL;
            static int *inc=NULL;
            static int *state=NULL;
            static int *startState=NULL;
            static int *stateLen=NULL;
            static ESPColor *targetColor=NULL;
            static ESPColor *currColor=NULL;
            
            if(state==NULL) {
              target=new int[it.size()];
              curr=new int[it.size()];
              inc=new int[it.size()];
              state=new int[it.size()];
              startState=new int[it.size()];
              stateLen=new int[it.size()];
              targetColor=new ESPColor[it.size()];
              currColor=new ESPColor[it.size()];
            }
            if(initial_run) {
              for(int i=0; i < it.size(); i++) {
                curr[i]=0; target[i]=0; // curr==target => init
                inc[i]=0; state[i]=0; startState[i]=0; stateLen[i]=0;
                currColor[i] = it[i].get();
                targetColor[i] = it[i].get();
              }
            }
            for (int i = 0; i < it.size() ; i++) {
              if(state[i] == 0 || state[i] > 500) {
                state[i] = random(500); // random delay till first flicker
                target[i] = curr[i]; // init new target
              }
              // set new target if target reached
              if(state[i] == 450 || (curr[i] == target[i] && state[i] > 450)) { // 10% is disturbed candle
                target[i]=random(50, 255);
                inc[i]=random(50)+1;
                currColor[i]=targetColor[i];
                targetColor[i]=current_color+ESPColor::random_color()*random(100);
                stateLen[i]=abs(target[i]-curr[i]) / inc[i];
                startState[i]=state[i];
              } else if(curr[i] == target[i]) { // slow changing candle
                target[i]=random(80, 160);
                inc[i]=random(10)+1;
                currColor[i]=targetColor[i];
                targetColor[i]=current_color+ESPColor::random_color()*random(40);
                stateLen[i]=abs(target[i]-curr[i]) / inc[i];
                startState[i]=state[i];
              }
              if(curr[i] > target[i]) {
                curr[i]-=min(inc[i], curr[i]-target[i]);
              } else {
                curr[i]+=min(inc[i], target[i]-curr[i]);
              }
              // ESP_LOGD(TAG, "candle [%d]3", i); delay(10);
              int factor=255;
              if(stateLen[i] > 0) factor = 255 * (state[i] - startState[i]) / (stateLen[i]);
              ESPColor c=currColor[i]*(factor*(curr[i]+1)/256) + targetColor[i]*((255-factor)*(curr[i]+1)/256);
              it[i]=c;
              // it[i]=it[i]*curr[i];
              state[i]++;
              // if(i==0) ESP_LOGD(TAG, "candle [0]=> t:%d c:%d inc:%d state:%d startState:%d stateLen:%d factor:%d cc:%02x tc:%02x out=%02x", 
              //  target[i], curr[i], inc[i], state[i], startState[i], stateLen[i], 
              //  factor, currColor[i].red, targetColor[i].red, c.red);
            }

depending on the random value in
targetColor[i]=current_color+ESPColor::random_color()*random(100);
you get more/less color change

The base color is depending on the choosen color from the color picker.

Hello! I recently added my 1st WLED set up and like it!
How or where do I upload these codes to use? Is it in HomeAssistant because I do not see anywhere to load them.

That is yaml for ESPhome, nothing to do with WLED. The effects in WLED are better than what you will find available for ESPhome.

2 Likes