Set max_brightness to slider value

Hi there,
I’m trying to be able to adjust the maximum brightness of my light effect, using a number slider. I’m a bit confused on how to get the right syntax for this, so help is appreciated

light:
  - platform: partition
    id: va_status
    segments:
      - id: led_light
        from: 1
        to: 6 
    effects:
      - pulse:
          name: "Slow Pulse"
          transition_length: 250ms
          update_interval: 250ms
          min_brightness: 0%
          max_brightness: !lambda 'return int(id(va_status_brightness).state)/100;' #100% <-- this doesn't work

And the number:

  - platform: template
    name: "Voice LED Brightness"
    id: va_status_brightness
    unit_of_measurement: "%"
    min_value: 0
    max_value: 100
    step: 1
    mode: slider
    update_interval: never
    optimistic: true
    restore_value: true
    initial_value: 100
    icon: "mdi:brightness-5"
    entity_category: config
!lambda return id(va_status_brightness).state) / 100.0;
1 Like

Thank you for your answer, but this I tried and get the error message
Expected percentage or float between -1.0 and 1.0.
This is what I tried:

  - platform: partition
    id: va_status
    name: "VA Status"
    segments:
      - id: led_light
        from: 1
        to: 6 
    effects:
      - pulse:
          name: "fast_pulse"
          transition_length: 100ms
          update_interval: 100ms
          min_brightness: 50%
          max_brightness: !lambda return id(va_status_brightness).state) / 100.0; # <-- Not working
          # max_brightness: !lambda return float(id(va_status_brightness).state) / 100.0); # <-- Not working
      - pulse:
          name: "slow_pulse"
          transition_length: 250ms
          update_interval: 250ms
          min_brightness: 50%
          max_brightness: 1.0 # <-- Working...

I thought the number entity returned a float by default…
It’s also got a syntax error, sorry I think I missed that. See the extra " ) " after state? It doesn’t go to anything. Remove that and try again. If it still doesn’t work, try this.

max_brightness: !lambda return float(id(va_status_brightness).state) / 100.0; # <-- Not working

or this…

max_brightness: !lambda 'return id(va_status_brightness).state) / 100.0;'

Theres an example of this in the Docs I just noticed.
Screenshot from 2024-02-20 10-06-39

Yes, this works with brightness, but not max_brightness… It sucks. :smiley:

well what the shit! Is there an error in the logs? Does it just not do anything?

I went and asked the gurus on Discord and they said max_brightness cant be changed at runtime. So, its like a gpio number, you have to change it then flash the board.
Sorry

Wow, thank you for your effort. To bad it’s not possible. I should submit a feature request then to make it more dynamic. :sweat_smile:

you know, I got another message about an hour ago from one of the more well known contributors. They said you can’t do it in a template but, it can probably be done in a lambda… I’ve been busy and havn’t been able to follow up on it.