Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- light:
- - platform: neopixelbus
- power_supply: power
- variant: WS2813
- pin: GPIO23
- num_leds: ${num_leds}
- type: RGB
- color_correct: [50%, 50%, 50%]
- default_transition_length: 1s
- restore_mode: always_off
- name: "Striplight"
- id: "Striplight"
- effects:
- - addressable_lambda:
- name: "Exit"
- update_interval: 10ms
- lambda: |-
- static Color led[${num_leds}];
- static uint16_t progress = 0;
- static int middle = ${num_leds} / 2;
- const uint8_t speed = 4;
- const uint8_t steps = 30;
- const bool revers = false;
- const bool twoside = false;
- const bool fade = false;
- if (initial_run)
- {
- ESP_LOGD("effect", "Rise and Fade x%i / %i", speed, steps);
- for (int i = 0; i < it.size(); i++)
- {
- led[i] = fade ? current_color : Color::BLACK;
- }
- progress = 0;
- }
- uint8_t r = max(1, current_color.r / steps);
- uint8_t g = max(1, current_color.g / steps);
- uint8_t b = max(1, current_color.b / steps);
- // Let's light up the ones who got their turn.
- for (int i = 0; i < speed; i++)
- {
- Color color = fade ? Color(current_color.r - r, current_color.g - g, current_color.b - b) : Color(r, g, b);
- if (twoside)
- {
- if (progress < middle)
- {
- if ((revers && progress == middle - 1) || (progress == 0 && !revers))
- {
- led[middle] = color;
- }
- led[revers ? max(0, (int) progress) : min((int) (middle + progress + 1), (int) it.size())] = color;
- led[revers ? max(0, (int) (it.size() - progress - 1)) : max(0, (int) (middle - progress - 1))] = color;
- }
- }
- else
- {
- if (progress < it.size())
- {
- led[revers ? max(0, (int) (it.size() - progress - 1)) : min((int) progress, (int) it.size())] = color;
- }
- }
- progress++;
- }
- bool complete = true;
- // Increase or Decrease the brightness of those already in action.
- for (int i = 0; i < it.size(); i++)
- {
- if ( !(led[i].r == 0 && led[i].g == 0 && led[i].b == 0) &&
- !(led[i].r == current_color.r && led[i].g == current_color.g && led[i].b == current_color.b) )
- {
- if (fade)
- {
- led[i].r = max(0, led[i].r - r);
- led[i].g = max(0, led[i].g - g);
- led[i].b = max(0, led[i].b - b);
- }
- else
- {
- led[i].r = min(led[i].r + r, (int) current_color.r);
- led[i].g = min(led[i].g + g, (int) current_color.g);
- led[i].b = min(led[i].b + b, (int) current_color.b);
- }
- complete = false;
- }
- }
- // Everyone's already on burn, mission over
- if (complete)
- {
- if (fade)
- {
- auto call = id(Striplight).turn_off();
- call.perform();
- }
- else
- {
- it.all() = current_color;
- auto call = id(Striplight).turn_on();
- call.set_effect("None");
- call.perform();
- }
- ESP_LOGD("effect", "Rise and Fade x%i / %i - Complete", speed, steps);
- }
- else // Transfer the current state to the led strip
- {
- for (int i = 0; i < it.size(); i++)
- {
- it[i] = led[i];
- }
- }
- - addressable_lambda:
- name: "Enter"
- update_interval: 10ms
- lambda: |-
- static Color led[${num_leds}];
- static uint16_t progress = 0;
- static int middle = ${num_leds} / 2;
- const uint8_t speed = 4;
- const uint8_t steps = 30;
- const bool revers = true;
- const bool twoside = false;
- const bool fade = false;
- if (initial_run)
- {
- ESP_LOGD("effect", "Rise and Fade x%i / %i", speed, steps);
- for (int i = 0; i < it.size(); i++)
- {
- led[i] = fade ? current_color : Color::BLACK;
- }
- progress = 0;
- }
- uint8_t r = max(1, current_color.r / steps);
- uint8_t g = max(1, current_color.g / steps);
- uint8_t b = max(1, current_color.b / steps);
- // Let's light up the ones who got their turn.
- for (int i = 0; i < speed; i++)
- {
- Color color = fade ? Color(current_color.r - r, current_color.g - g, current_color.b - b) : Color(r, g, b);
- if (twoside)
- {
- if (progress < middle)
- {
- if ((revers && progress == middle - 1) || (progress == 0 && !revers))
- {
- led[middle] = color;
- }
- led[revers ? max(0, (int) progress) : min((int) (middle + progress + 1), (int) it.size())] = color;
- led[revers ? max(0, (int) (it.size() - progress - 1)) : max(0, (int) (middle - progress - 1))] = color;
- }
- }
- else
- {
- if (progress < it.size())
- {
- led[revers ? max(0, (int) (it.size() - progress - 1)) : min((int) progress, (int) it.size())] = color;
- }
- }
- progress++;
- }
- bool complete = true;
- // Increase or Decrease the brightness of those already in action.
- for (int i = 0; i < it.size(); i++)
- {
- if ( !(led[i].r == 0 && led[i].g == 0 && led[i].b == 0) &&
- !(led[i].r == current_color.r && led[i].g == current_color.g && led[i].b == current_color.b) )
- {
- if (fade)
- {
- led[i].r = max(0, led[i].r - r);
- led[i].g = max(0, led[i].g - g);
- led[i].b = max(0, led[i].b - b);
- }
- else
- {
- led[i].r = min(led[i].r + r, (int) current_color.r);
- led[i].g = min(led[i].g + g, (int) current_color.g);
- led[i].b = min(led[i].b + b, (int) current_color.b);
- }
- complete = false;
- }
- }
- // Everyone's already on burn, mission over
- if (complete)
- {
- if (fade)
- {
- auto call = id(Striplight).turn_off();
- call.perform();
- }
- else
- {
- it.all() = current_color;
- auto call = id(Striplight).turn_on();
- call.set_effect("None");
- call.perform();
- }
- ESP_LOGD("effect", "Rise and Fade x%i / %i - Complete", speed, steps);
- }
- else // Transfer the current state to the led strip
- {
- for (int i = 0; i < it.size(); i++)
- {
- it[i] = led[i];
- }
- }
- - addressable_lambda:
- name: "Side"
- update_interval: 10ms
- lambda: |-
- static Color led[${num_leds}];
- static uint16_t progress = 0;
- static int middle = ${num_leds} / 2;
- const uint8_t speed = 3.2;
- const uint8_t steps = 30;
- const bool revers = false;
- const bool twoside = true;
- const bool fade = false;
- if (initial_run)
- {
- ESP_LOGD("effect", "Rise and Fade x%i / %i", speed, steps);
- for (int i = 0; i < it.size(); i++)
- {
- led[i] = fade ? current_color : Color::BLACK;
- }
- progress = 0;
- }
- uint8_t r = max(1, current_color.r / steps);
- uint8_t g = max(1, current_color.g / steps);
- uint8_t b = max(1, current_color.b / steps);
- // Let's light up the ones who got their turn.
- for (int i = 0; i < speed; i++)
- {
- Color color = fade ? Color(current_color.r - r, current_color.g - g, current_color.b - b) : Color(r, g, b);
- if (twoside)
- {
- if (progress < middle)
- {
- if ((revers && progress == middle - 1) || (progress == 0 && !revers))
- {
- led[middle] = color;
- }
- led[revers ? max(0, (int) progress) : min((int) (middle + progress + 1), (int) it.size())] = color;
- led[revers ? max(0, (int) (it.size() - progress - 1)) : max(0, (int) (middle - progress - 1))] = color;
- }
- }
- else
- {
- if (progress < it.size())
- {
- led[revers ? max(0, (int) (it.size() - progress - 1)) : min((int) progress, (int) it.size())] = color;
- }
- }
- progress++;
- }
- bool complete = true;
- // Increase or Decrease the brightness of those already in action.
- for (int i = 0; i < it.size(); i++)
- {
- if ( !(led[i].r == 0 && led[i].g == 0 && led[i].b == 0) &&
- !(led[i].r == current_color.r && led[i].g == current_color.g && led[i].b == current_color.b) )
- {
- if (fade)
- {
- led[i].r = max(0, led[i].r - r);
- led[i].g = max(0, led[i].g - g);
- led[i].b = max(0, led[i].b - b);
- }
- else
- {
- led[i].r = min(led[i].r + r, (int) current_color.r);
- led[i].g = min(led[i].g + g, (int) current_color.g);
- led[i].b = min(led[i].b + b, (int) current_color.b);
- }
- complete = false;
- }
- }
- // Everyone's already on burn, mission over
- if (complete)
- {
- if (fade)
- {
- auto call = id(Striplight).turn_off();
- call.perform();
- }
- else
- {
- it.all() = current_color;
- auto call = id(Striplight).turn_on();
- call.set_effect("None");
- call.perform();
- }
- ESP_LOGD("effect", "Rise and Fade x%i / %i - Complete", speed, steps);
- }
- else // Transfer the current state to the led strip
- {
- for (int i = 0; i < it.size(); i++)
- {
- it[i] = led[i];
- }
- }
- - addressable_lambda:
- name: "Side_fade"
- update_interval: 10ms
- lambda: |-
- static Color led[${num_leds}];
- static uint16_t progress = 0;
- static int middle = ${num_leds} / 2;
- const uint8_t speed = 3.2;
- const uint8_t steps = 30;
- const bool revers = false;
- const bool twoside = true;
- const bool fade = true;
- if (initial_run)
- {
- ESP_LOGD("effect", "Rise and Fade x%i / %i", speed, steps);
- for (int i = 0; i < it.size(); i++)
- {
- led[i] = fade ? current_color : Color::BLACK;
- }
- progress = 0;
- }
- uint8_t r = max(1, current_color.r / steps);
- uint8_t g = max(1, current_color.g / steps);
- uint8_t b = max(1, current_color.b / steps);
- // Let's light up the ones who got their turn.
- for (int i = 0; i < speed; i++)
- {
- Color color = fade ? Color(current_color.r - r, current_color.g - g, current_color.b - b) : Color(r, g, b);
- if (twoside)
- {
- if (progress < middle)
- {
- if ((revers && progress == middle - 1) || (progress == 0 && !revers))
- {
- led[middle] = color;
- }
- led[revers ? max(0, (int) progress) : min((int) (middle + progress + 1), (int) it.size())] = color;
- led[revers ? max(0, (int) (it.size() - progress - 1)) : max(0, (int) (middle - progress - 1))] = color;
- }
- }
- else
- {
- if (progress < it.size())
- {
- led[revers ? max(0, (int) (it.size() - progress - 1)) : min((int) progress, (int) it.size())] = color;
- }
- }
- progress++;
- }
- bool complete = true;
- // Increase or Decrease the brightness of those already in action.
- for (int i = 0; i < it.size(); i++)
- {
- if ( !(led[i].r == 0 && led[i].g == 0 && led[i].b == 0) &&
- !(led[i].r == current_color.r && led[i].g == current_color.g && led[i].b == current_color.b) )
- {
- if (fade)
- {
- led[i].r = max(0, led[i].r - r);
- led[i].g = max(0, led[i].g - g);
- led[i].b = max(0, led[i].b - b);
- }
- else
- {
- led[i].r = min(led[i].r + r, (int) current_color.r);
- led[i].g = min(led[i].g + g, (int) current_color.g);
- led[i].b = min(led[i].b + b, (int) current_color.b);
- }
- complete = false;
- }
- }
- // Everyone's already on burn, mission over
- if (complete)
- {
- if (fade)
- {
- auto call = id(Striplight).turn_off();
- call.perform();
- }
- else
- {
- it.all() = current_color;
- auto call = id(Striplight).turn_on();
- call.set_effect("None");
- call.perform();
- }
- ESP_LOGD("effect", "Rise and Fade x%i / %i - Complete", speed, steps);
- }
- else // Transfer the current state to the led strip
- {
- for (int i = 0; i < it.size(); i++)
- {
- it[i] = led[i];
- }
- }
- - addressable_lambda:
- name: "ColorScan"
- update_interval: 10ms
- lambda: |-
- // it.size() - Number of LEDs
- // it[num] - Access the LED at index num.
- // Set the LED at num to the given r, g, b values
- // it[num] = Color(r, g, b);
- // Get the color at index num (Color instance)
- // it[num].get();
- static uint16_t num1 = 0;
- static uint16_t red = 255;
- static uint16_t green = 3;
- static uint16_t blue = 3;
- static bool dir = false;
- uint16_t num = num1;
- uint16_t numled = ${num_leds};
- if(red > 251 && blue < 4 && green < 252){
- green+=5;
- } else if (red > 3 && green > 251 && blue < 4){
- red-=5;
- } else if (red < 4 && green > 251 && blue < 252){
- blue+=5;
- } else if (red < 4 && green > 3 && blue > 251){
- green-=5;
- } else if (red < 252 && green < 4 && blue > 251){
- red+=5;
- } else if (red > 251 && green < 4 && blue > 3){
- blue-=5;
- }
- it[num] = Color(red, green, blue);
- if(dir) {
- if(num1 == numled){
- dir = false;
- } else{
- num1++;
- }
- } else {
- if(num1 == 0){
- dir = true;
- } else{
- num1--;
- }
- }
- - pulse:
- - pulse:
- name: "Fast Pulse"
- transition_length: 0.5s
- update_interval: 0.5s
- min_brightness: 0%
- max_brightness: 100%
- - pulse:
- name: "Slow Pulse"
- # transition_length: 1s # defaults to 1s
- update_interval: 2s
- - strobe:
- - strobe:
- name: Strobe Effect With Custom Values
- colors:
- - state: true
- brightness: 100%
- red: 100%
- green: 90%
- blue: 0%
- duration: 500ms
- - state: false
- duration: 250ms
- - state: true
- brightness: 100%
- red: 0%
- green: 100%
- blue: 0%
- duration: 500ms
- - flicker:
- - flicker:
- name: Flicker Effect With Custom Values
- alpha: 95%
- intensity: 1.5%
- - addressable_lambda:
- name: Gold Glitter
- update_interval: 18ms
- lambda:
- static int state = 0;
- if (initial_run){
- state = 0;
- it.all() = ESPColor(218,165,32);
- ESP_LOGD("custom", "Gold Glitter");
- } else {
- it.all() = ESPColor(218,165,32);
- if(state==0){
- int i = rand() % it.size();
- it[i] = ESPColor::WHITE;
- state += 1;
- } else {
- state += 1;
- state = state % 10;
- }
- }
- # from reddit user thedoctor___
- # https://www.reddit.com/r/homeassistant/comments/bua3u8/esphome_what_custom_addressable_lambda_effects/
- - addressable_lambda:
- name: "Fire"
- update_interval: 15ms
- lambda: |-
- int Cooling = 55;
- int Sparking = 110;
- static byte heat[188];
- int cooldown;
- // Step 1. Cool down every cell a little
- for( int i = 0; i < it.size(); i++) {
- cooldown = random(0, ((Cooling * 10) / it.size()) + 2);
- if(cooldown>heat[i]) {
- heat[i]=0;
- } else {
- heat[i]=heat[i]-cooldown;
- }
- }
- // Step 2. Heat from each cell drifts 'up' and diffuses a little
- for( int k= it.size() - 1; k >= 2; k--) {
- heat[k] = (heat[k - 1] + heat[k - 2] + heat[k - 2]) / 3;
- }
- // Step 3. Randomly ignite new 'sparks' near the bottom
- if( random(255) < Sparking ) {
- int y = random(7);
- heat[y] = heat[y] + random(160,255);
- }
- // Step 4. Convert heat to LED colors
- for( int Pixel = 0; Pixel < it.size(); Pixel++) {
- // Scale 'heat' down from 0-255 to 0-191
- byte t192 = round((heat[Pixel]/255.0)*191);
- // calculate ramp up from
- byte heatramp = t192 & 0x3F; // 0..63
- heatramp <<= 2; // scale up to 0..252
- // figure out which third of the spectrum we're in:
- //this is where you can reverse the effect by switching the commented out lines in all 3 places.
- if( t192 > 0x80) { // hottest
- //it[it.size() - Pixel - 1] = ESPColor(255, 255, heatramp);
- it[Pixel] = ESPColor(255, 255, heatramp);
- } else if( t192 > 0x40 ) { // middle
- //it[it.size() - Pixel - 1] = ESPColor(255, heatramp, 0);
- it[Pixel] = ESPColor(255, heatramp, 0);
- } else { // coolest
- //it[it.size() - Pixel - 1] = ESPColor(heatramp, 0, 0);
- it[Pixel] = ESPColor(heatramp, 0, 0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment