Integrating a 5V dual white led strip

No, I have not tried it at first, because by calculation that would yield too low resolution in the lower areas and too high a starting value.
(0.0001 + 0.9999 * 0.01) * 16383 = 165.451917

Strangely though, it somewhat works. Could you explain why? I guess, I misunderstood something…

What’s also a bit confusing is that I only get 14 bits resolution at 1000 Hz frequency. Here, it’s written, that with frequencies up to 1220 Hz, I should get 16 bits resolution. Meanwhile I also tried it with GPIOs 0 and 1. With that, resolution even goes down to 13 bits. With GPIOs 0 and 2, I’m back to 14 bits.

Because at brightness 1% template output doesn’t receive 0.01, it receives 0
so it’s
0.0001 + 0.9999 * 0) * 16383 = 2

Esphome choose the resolution for you :wink:
Honestly, no idea how…

Ahhh, so the calculation with the gamma is already done before the template? I assumed, the template would get the value set in the UI. So, basically, it’s
0.0001 + 0.9999 * (x ^ 2.8) where x is the UI value.

Template output gets what ledc output would get without template in the middle.
That way you get tiny “boost” for next to 0 duty, but it doesn’t have any effect on higher values.

hmm, but ledc should not know anything about gamma, because that’s part of light… I still don’t understand how ledc output is computed.

Exactly, light calculates the duty cycle. Ledc doesn’t care/know about gamma, it could drive a motor instead…

An issue with your suggested function is that 1% and 2% still had the same duty cycle which is a bit unexpected from am UX perspective. So, I’ve decided to define the function piecewise and am quite happy with the gradient that way :slight_smile:

The mapping is now as follows:
1 → 1
2 → 2


3…8 → (x-1) * 2
3 → 4
4 → 6
5 → 8
6 → 10
7 → 12
8 → 14


9… → x ^ 2.8
9 → 19
10 → 27

To achieve that, I had to pull the gamma correction function into the template.

Here’s the config for reference:

yaml config
output:
  - platform: ledc
    pin: GPIO0
    id: gpio_cw
  - platform: ledc
    pin: GPIO2
    id: gpio_ww
  - platform: template
    id: cw_calibrated
    type: float
    write_action:
      - output.set_level:
          id: gpio_cw
          level: !lambda |-
            if (state==0) {
              return 0;
            }
            else if (state<=0.02) {
              return state / 16363 * 100;
            }
            else if (state>0.02 and state<=0.08) {
              return (state - 0.01) / 16363 * 200;
            }
            else {
              return pow(state, 2.8);
            }
  - platform: template
    id: ww_calibrated
    type: float
    write_action:
      - output.set_level:
          id: gpio_ww
          level: !lambda |-
            if (state==0) {
              return 0;
            }
            else if (state<=0.02) {
              return state / 16363 * 100;
            }
            else if (state>0.02 and state<=0.08) {
              return (state - 0.01) / 16363 * 200;
            }
            else {
              return pow(state, 2.8);
            }
light:
  - platform: cwww
    name: "Dev Light"
    cold_white: cw_calibrated
    warm_white: ww_calibrated
    cold_white_color_temperature: 6000 K
    warm_white_color_temperature: 3000 K
    constant_brightness: true
    restore_mode: RESTORE_DEFAULT_OFF
    gamma_correct: 1

Yep, play with gamma function (or whatever other fine tuning) on template sensor. That way you keep the light component untouched.

Lot of time and posts for “cosmetic” reasons. But lot of learning as well. I never thought how non-linear brightness is from pwm. Now I wonder if speed fan component has some “functions” built in as well… I expect that it’s not perfectly linear with pwm either

1 Like

Changing the solution you should change the title as well, O.P. was handled long time ago, 95% of this topic is about cosmetic brightness fine tuning.

You’re right. The actual topic was solved many posts ago. I set the solution to one of your posts. Got sidetracked just a little after that :smiley: But as you said, we all learned something from it :slight_smile:

Seems, I can no longer edit the title. Probably too old a topic - just a guess. Anyways, it’s got the checkmark, so it’s clearly visible solved

Don’t worry I’m not getting paid for solutions :frowning_face:
Maybe you can’t edit the title if there is solution marked.
You could un-mark that and try to modify title. Never tried though.