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(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.