Last active
February 13, 2025 20:21
-
-
Save C0ntroller/3125650c07c30f9ca6de439a730e0a97 to your computer and use it in GitHub Desktop.
ESPHome RGB-LED Rainbow effect
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Import this effect in your light module to use it | |
# You have to change the id in line 15 and/or set an id for your LED module | |
# The time-variable exist to make multiple ESPs start from 0 even if they ran the effect before so they are in sync | |
# You can delete it if you only have one LED Strip | |
- lambda: | |
name: Rainbow | |
update_interval: 3s # If you change this, also have to edit line 11 for correct time handling | |
lambda: |- | |
static int state = 0; | |
static uint32_t time = millis(); | |
if(millis() - time > 3200){ | |
ESP_LOGD("main", "Rainbow effect resumed after break!"); | |
state = 0; | |
} | |
auto call = id(ledlight).turn_on(); | |
call.set_transition_length(3000); | |
switch (state) { | |
default: | |
case 0: call.set_rgb(1.0, 0.0, 0.0); | |
break; | |
case 1: call.set_rgb(1.0, 1.0, 0.0); | |
break; | |
case 2: call.set_rgb(0.0, 1.0, 0.0); | |
break; | |
case 3: call.set_rgb(0.0, 1.0, 1.0); | |
break; | |
case 4: call.set_rgb(0.0, 0.0, 1.0); | |
break; | |
case 5: call.set_rgb(1.0, 0.0, 1.0); | |
break; | |
} | |
call.set_publish(false); | |
call.set_save(false); | |
call.perform(); | |
state += 1; | |
state %= 6; | |
time = millis(); |
@Phando There are multiple ways:
- Using a header file would work.
- If it's just two lights, you could directly include it in their definitions I guess.
- I have multiple files with this content like the one above (but other effects of course) in a directory (
led/effects
) in esphome. On my light definition I do
light:
- platform: rgb
# other naming and stuff
effects: !include_dir_merge_list led/effects/
That way all my effects are available on all my RGB light strips.
Thanks for the info! I am new to esphome. I have one light that is two light sections. 36 leds in total. Your other rainbow code is beautiful (on device). I can’t wait to see this one.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When you say "Import this effect in your light module" do I copy and pate the code into an addressable_lambda section, or can I take your file and put it in a folder and then reference it by name? I have two strips I would like to use with this rainbow.