I am still pretty new to ESPHome, so I could easily be overlooking something, but I am having a lot of trouble with some simple code to set my led color/brightness. I’m using a simple RGB led bulb and want to change it’s color based on a value coming in from HA. It works great until I add a call for brightness, so it can be turned off if it doesn’t match any conditions.
on_value:
then:
- lambda: |-
auto call = id(xbox_light).make_call();
call.set_transition_length(500);
static int brightness = 1.0;
if (id(xbox_app).state == "Netflix") {
call.set_rgb(1.0, 0.0, 0.0);
} else if (id(xbox_app).state == "Hulu") {
call.set_rgb(0.0, 1.0, 0.0);
} else if (id(xbox_app).state == "Disney+") {
call.set_rgb(0.0, 0.0, 1.0);
} else if (id(xbox_app).state == "Plex for Xbox One") {
call.set_rgb(1.0, 0.0, 0.2);
} else {
call.set_rgb(0.0, 0.0, 0.0);
brightness = 0.0;
}
call.set_brightness(brightness);
call.perform();
The brightness
variable doesn’t have to be there, I also tried it as individual calls and it still does this. It doesn’t matter what I set it to, I tried setting different values and only setting them once. The light would be off every time. If I set it to something else, like 0.5, then it would go to that brightness after I manually turned the light on in HA.
I also tried .turn_on()
just to see if that was a command that I missed but it wasn’t a valid command and failed to compile.