ESPHome Neopixel fade in and fade out

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:

  - 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:

      - 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 =;
              int green =;
              int 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];

and a script calling this effect:

  - id: script_test
      - 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?

I’m running into an identical problem… I really wish there was a way to specify two color/brightness settings and just fade between the two over a specified time period.

Same problem here.
The lights fade on in around 1 second. Similar results with fade off.
I’ve tried with the neopixelbus and fastled_clockless platforms, but either fading on, off or between colours won’t work smoothly unless the default 1 second is used.

The default_transition_length doesn’t appear to be working properly. It has some influence, but its undesirable.

Hoping someone has the answer.

Kind regards,

I really think that we are running into a limitation of ESPHome. Even with the lambda option you can not actually do this in a way we would like.

The transition_length only works for ‘supported’ lights (such as Hue). :frowning:

It isn’t exactly what was asked here, but I would suggest using WLED. The only reason not using it I can think of is that you have other things connected to your esp. However, I think that in this case the advantages of WLED far exceed the price of a second ESP. But please tell me other reasons if you have any.

Transitions are for the most part handled by the control firmware. You can tell it how fast to transition but in the end the firmware will determine the steps. Some bulbs like hue are better than others at handling transitions.

Wled will give you better control over dimming and fading with out having to write code. There are also ways to run a motion detectors/switch if it’s absolutely necessary with wled. It’s a little more complicated than esphome, you can use standard arduino code.