Hi all,
I have the following challenge which I cannot seem to figure out myself;
I have NEOPixels underneath my staircase and currently I am using an Arduino with my own C++ code on it, works perfectly but everything is hard-coded. Which is why I am looking into ESPhome - this should make it easier to change the color of the neopixels for example.
Anyway, I want to do a “fade in” and “fade out” of the color of my choosing. The problem I am running into is that no matter what I try the fade-in is always FAST (<1s). Since I couldn’t do it using the default YAML options I tried to create a Lambda (as you can do anything).
First the light object:
light:
- platform: fastled_clockless
chipset: NEOPIXEL
pin: GPIO4
#num_leds: 384
num_leds: 60
name: "Staircase"
id: light1
default_transition_length: 1s
This is the lambda effect I created:
effects:
- addressable_lambda:
name: Fade-lambda
update_interval: 32ms
lambda: |-
static boolean initialized;
static ESPColor staircase_colors [60];
//first run, all too black
if (initialized == false) {
std::fill_n(staircase_colors, it.size(), ESPColor::BLACK);
initialized = true;
}
int color_red=255;
int color_green=0;
int color_blue=255;
// fade in old colors
for (int i = 0; i < it.size(); i++) {
ESPColor old_color = staircase_colors[i];
// fade in color
int amount = 5;
int red = old_color.red;
int green = old_color.green;
int blue = old_color.blue;
int white = old_color.white;
if (red < color_red) { red += amount; } else { red = color_red; }
if (green < color_green) { green += amount; } else { green = color_green; }
if (blue < color_blue) { blue += amount; } else { blue = color_blue; }
ESPColor new_color = ESPColor(red, green, blue, 0);
staircase_colors[i] = new_color;
//ESP_LOGD("custom", "RGB value: %i %i %i", red, green, blue);
}
// apply colors to light
for (int i = 0; i < it.size(); i++) {
it[i] = staircase_colors[i];
}
usleep(2000);
and a script calling this effect:
script:
- id: script_test
then:
- light.turn_on:
id: light1
brightness: 25%
red: 0
blue: 0
green: 0
effect: Fade-lambda
Even with the usleep of 2000 ms , this finishes in < 1sec and the fade in is completed… I am running out of ideas how to either slow it down or how to do this in default YAML (which I prefer)…
Is there anyone who has something similar? Or am I running into the limitations of ESPHome?