Rainbow (colorwheel) light effect for non-addressable RGB LED strip

Hi.
I’ve been searching for a rainbow or colorwheel effect recently, but only found for addressable strips.
I’ve made one for myself and share with you. It works for any RGB led strip (3 pwm pins).

light:
  - platform: rgb
    id: backlight
    ...
    effects:
      - lambda:
          name: Slow Rainbow
          update_interval: 16s
          lambda: |-
            static int state = 0;
            auto call = id(backlight).turn_on();
            call.set_transition_length(15000);
            if (state == 0) {
              call.set_rgb(1.0, 0.0, 0.0);
            } else if (state == 1) {
              call.set_rgb(1.0, 0.5, 0.0);
            } else if (state == 2) {
              call.set_rgb(1.0, 1.0, 0.0);
            } else if (state == 3) {
              call.set_rgb(0.5, 1.0, 0.0);
            } else if (state == 4) {
              call.set_rgb(0.0, 1.0, 0.0);
            } else if (state == 5) {
              call.set_rgb(0.0, 1.0, 0.5);
            } else if (state == 6) {
              call.set_rgb(0.0, 1.0, 1.0);
            } else if (state == 7) {
              call.set_rgb(0.0, 0.5, 1.0);
            } else if (state == 8) {
              call.set_rgb(0.0, 0.0, 1.0);
            } else if (state == 9) {
              call.set_rgb(0.5, 0.0, 1.0);
            } else if (state == 10) {
              call.set_rgb(1.0, 0.0, 1.0);
            } else if (state == 11) {
              call.set_rgb(1.0, 0.0, 0.5);
            }
            call.perform();
            state++;
            if (state == 12)
              state = 0;

You can adjust set_transition_length(15000) and update_interval to change the speed.
docs: https://esphome.io/components/light/index.html#lambda-effect

7 Likes

Hi,

Thanks for this. I’ve been searching as well.

I don’t suppose you’d know how to call a set brightness for this?

If I understood you correctly, you need a brightness slide in UI? It is in settings modal (click on light name) and works with my effect well.
If you need it for automation in Developer Tools you can find available options