I’ve been struggling with the same 100% or 0% issue and a power cycle did nothing to help.
It seems to me that this is mostly a documentation issue since the pwm output is determined by relative values of RGB rather than the traditional measures of duty cycle of pwm. By changing the call.set_brightness(), you can achieve the accurate pwm output you’re looking for.
I have even broken out setting the colors individually.
ESPhome doesn’t respect the 50% settings. I tried with int after looking at the codebase under set_red() but that errored out so it has a conversion behind the scenes.
It is difficult to make much sense of the flow of the src code but I’ll list it at the bottom. It is the same as specified in the lambda function.
Lambda Code:
- lambda:
name: redflicker
update_interval: 10s
lambda: |-
static int state = 0;
auto call = id(h801_2_rgb).turn_on();
// Transtion of 1000ms = 1s
call.set_transition_length(1000);
if (state == 0) {
call.set_red(0.5);
call.set_green(0.5);
call.set_blue(0.5);
} else if (state == 1) {
call.set_red(1.0);
call.set_blue(0.5);
call.set_green(0.0);
} else if (state == 2) {
call.set_red(0.5);
call.set_blue(0.0);
call.set_green(0.0);
}
call.perform();
state += 1;
if (state == 3)
state = 0;
and log
[11:18:59][D][light:261]: 'H801_2_Light' Setting:
[11:18:59][D][light:283]: Red=100%, Green=0%, Blue=50%
[11:18:59][D][light:300]: Transition Length: 1.0s
[11:19:09][D][light:261]: 'H801_2_Light' Setting:
[11:19:09][D][light:283]: Red=100%, Green=0%, Blue=0%
[11:19:09][D][light:300]: Transition Length: 1.0s
[11:19:15][D][sensor:092]: 'h801_2_uptime_s': Sending state 35.77300 s with 0 decimals of accuracy
[11:19:19][D][light:261]: 'H801_2_Light' Setting:
[11:19:19][D][light:283]: Red=100%, Green=100%, Blue=100%
[11:19:19][D][light:300]: Transition Length: 1.0s
[11:19:29][D][light:261]: 'H801_2_Light' Setting:
[11:19:29][D][light:283]: Red=100%, Green=0%, Blue=50%
[11:19:29][D][light:300]: Transition Length: 1.0s
src
automation_2->add_actions({light_lightcontrolaction_2});
light_lambdalighteffect_3 = new light::LambdaLightEffect("redflicker", [=]() -> void {
static int state = 0;
auto call = h801_2_rgb->turn_on();
// Transtion of 1000ms = 1s
call.set_transition_length(1000);
if (state == 0) {
call.set_red(0.5);
call.set_green(0.5);
call.set_blue(0.5);
} else if (state == 1) {
call.set_red(1.0);
call.set_blue(0.5);
call.set_green(0.0);
} else if (state == 2) {
call.set_red(0.5);
call.set_blue(0.0);
call.set_green(0.0);
}
call.perform();
state += 1;
if (state == 3)
state = 0;
}, 10000);