Step adjust brightness

Hi all! I’m trying to create a script that adjusts brightness up or down. This will be addressed from a Loxone Miniserver to turn brightness up or down from a switch.

I created this script similar to another one related to volume (Sending Jinja2 templates in an HTTP Request? - #8 by petro), but didn’t work. Probably because there is no “state_attr” called “brightness” for “light”. Anyone know what the “state_attr” would be to detect the brightness of a light bulb?

Thanks.

alias: Step Adjust Brightness
mode: parallel
description: |
  step adjust the brightness of any light
fields:
  entity_id:
    description: The Light Bulb
    required: true
    selector:
      entity:
        multiple: true
        domain: light
  direction:
    description: Brightness Up or Brightness Down
    required: true
    selector:
      select:
        options:
          - label: Brightness Up
            value: up
          - label: Brightness Down
            value: down
  brightness_step:
    description: Brightness Step (up or down)
    default: 0.05
    selector:
      number:
        min: 0
        max: 0
        step: 0.05
variables:
  light: "{{ entity_id if entity_id is list else [entity_id] }}"
  current: >-
    {{ light | map('state_attr', 'brightness') | select('is_number') | list |
    average }}
  step: "{{ brightness_step | default(0.05) }}"
  brightness: "{{ current + step if direction == 'up' else current - step }}"
sequence:
  - action: light.toggle
    target:
      entity_id: "{{ light }}"
    data:
      brightness_pct: "{{ brightness_pct }}"
icon: mdi:lightbulb-on-10

I don’t know exactly what’s the problem in your code, but are you aware the light actions support changing brightness by step by default? With brightness_step. You should be able to use that to simply adjust the brightness by a specific step.

Also brightness value goes from 0 to 255 and is an integer. Try adjusting it by an integer, not a value below 1.

You can find this and more info about the light actions in the documentation here:

Thank you! I was not aware of that… I assumed it was not possible given that it wasn’t for media_player…sorry I’m still a newbie! I’ll post my updated code when I have a working solution for future reference