Brightness 255 help

Everything about this works except for the last hop from 191 to 255 so if I look at the group light settings, the brightness is at 191

  entity_id: light.family_lamps
  brightness: >-
    {% set current = state_attr('light.family_lamps', 'brightness') | default(0)
    | int %} {% set state = states('light.family_lamps') %} {{
    log.info("Up_Press: Current State: " ~ state ~ ", Current Brightness: " ~
    current) }} {% set new_brightness = 
        64 if state == 'off' 
        else 64 if current < 64 
        else 128 if current < 128 
        else 192 if current < 192 
        else 255 %}
    {{ log.info("Up_Press: New Brightness Calculated: " ~ new_brightness) }} {{
    new_brightness }}
  transition: 1.5
action: light.turn_on

I don’t know whether it was ChatGPT or some other bullshit engine… but that’s exactly what you’ve got.

You can’t print in the middle of a brightness template… that will make the output a long string something like:

log.info("Up_Press: Current State: on, Current Brightness: 100")
log.info("Up_Press: New Brightness Calculated: 250") 250

when it should just be an integer between 0-255 like:

250

Other issues:

  1. The default filter is not properly set to handle a none value.
  2. Missing data key.

Ok thank you

Ok I can get the lights to turn on when off with the up button, one click goes to 25%, then 50% then 75%, and nothing I have tried gets it to 100%. Maybe a different method is better? I dont really understand the default filter or missing data key. I’ll need to google some more. here is what I have from AI hehe but sitll no 100%.

Up_Press:
      - service: light.turn_on
        data_template:
          entity_id: light.family_lamps
          brightness: >-
            {% set current_brightness = state_attr('light.family_lamps', 'brightness') %}
            {% set state = states('light.family_lamps') %}
            {% set current = current_brightness | default(0) | int(0) %}
            {% if state == 'off' %}
              64
            {% elif current_brightness is none %}
              64
            {% elif current < 64 %}
              64
            {% elif current < 128 %}
              128
            {% elif current < 192 %}
              192
            {% else %}
              255
            {% endif %}
          transition: 1.5`

I did this for Down_Press and it works but wont go to 5% so I guess I just trick it and stop at 99% and 5% then put 100 and 5 after that if it all works but the last else.

    Down_Press:
      - service: light.turn_on
        data_template:
          entity_id: light.family_lamps
          brightness: >-
            {% set current_brightness = state_attr('light.family_lamps', 'brightness') %}
            {% set current = current_brightness | default(255) | int(255) %}
            {% if current > 192 %}
              192
            {% elif current > 128 %}
              128
            {% elif current > 64 %}
              64
            {% elif current > 25 %}
              25
            {% elif current > 10 %}
              10
            {% else %}
              5
            {% endif %}
          transition: 1.5
# Down_Press
  - action: light.turn_on
    data:
      entity_id: light.family_lamps
      brightness: >
        {% set current_brightness = state_attr('light.family_lamps', 'brightness')|int(255) %}
        {{ ([0, current_brightness - 64, 255]|sort)[1] }}
      transition: 1.5
# Up_Press
  - action: light.turn_on
    data:
      entity_id: light.family_lamps
      brightness: >
        {% set current_brightness = state_attr('light.family_lamps', 'brightness')|int(0) %}
        {{ ([0, current_brightness + 64, 255]|sort)[1] }}
      transition: 1.5

thank you works wonderfully and a lot more efficient and less code. amazing

1 Like