Another Ikea z2m Styrbar Programmable Dimmer

Made this because there wasn’t one solution for my needs. Had to use several automations to dim lights or use Styrbar for different tasks.

Version 1.0
This blueprint integrates and controls the IKEA E2001/E2002 Styrbar remote control.
The primary light entity handles on/off and dim controls via the main buttons,
while a separate dimmable entity can be controlled using the hold functions of right
and left buttons. Customizable settings allow fine-tuning of button behavior.

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

blueprint:
  name: Another Styrbar Dimmer
  description: |
    **Version 1.0**   
    This blueprint integrates and controls the IKEA E2001/E2002 Styrbar remote control. 
    The primary light entity handles on/off controls via the main buttons, 
    while a separate dimmable entity can be controlled using the hold functions of right 
    and left buttons. Customizable settings allow fine-tuning of button behavior.
  source_url: https://github.com/Routout/Blueprints/blob/067db840e71c32d245a94d693968c6b0798eba16/another_styrbar_dimmer.yaml
  domain: automation
  input:
    light_entity:
      name: Primary Light Entity
      description: The main light to control for on/off controls.
      selector:
        entity:
          domain: light
          multiple: false
    enable_hold_dimming:
      name: Enable Hold Arrow Button Dimming
      description: Enable dimming functionality for hold buttons (left = dim down, right = dim up).
      default: true
      selector:
        boolean: {}
    dimmable_entity:
      name: Dimmable Light Entity
      description: The light to control when holding left/right buttons (can be same as primary light).
      selector:
        entity:
          domain: light
          multiple: false
    mqtt_device:
      name: Styrbar Remote Control
      description: The IKEA E2001/E2002 remote control.
      selector:
        device:
          integration: mqtt
    button_left_click:
      name: Left button - short press
      description: Action when SHORT press on LEFT arrow button
      default: []
      selector:
        action: {}
    button_left_hold:
      name: Left button - hold
      description: Action when HOLD press on LEFT arrow button (will be overridden if dimming is enabled)
      default: []
      selector:
        action: {}
    button_left_release:
      name: Left button - release
      description: Action when RELEASE press on LEFT arrow button
      default: []
      selector:
        action: {}
    button_right_click:
      name: Right button - short press
      description: Action when SHORT press on RIGHT arrow button
      default: []
      selector:
        action: {}
    button_right_hold:
      name: Right button - hold
      description: Action when HOLD press on RIGHT arrow button (will be overridden if dimming is enabled)
      default: []
      selector:
        action: {}
    button_right_release:
      name: Right button - release
      description: Action when RELEASE press on RIGHT arrow button
      default: []
      selector:
        action: {}
trigger:
  - platform: device
    device_id: !input mqtt_device
    domain: mqtt
    type: action
    subtype: 'on'
    id: light_on
  - platform: device
    device_id: !input mqtt_device
    domain: mqtt
    type: action
    subtype: 'off'
    id: light_off
  - platform: device
    device_id: !input mqtt_device
    domain: mqtt
    type: action
    subtype: brightness_move_down
    id: dim_down
  - platform: device
    device_id: !input mqtt_device
    domain: mqtt
    type: action
    subtype: brightness_move_up
    id: dim_up
  - platform: device
    device_id: !input mqtt_device
    domain: mqtt
    type: action
    subtype: brightness_stop
    id: dim_stop
  - platform: device
    device_id: !input mqtt_device
    domain: mqtt
    type: action
    subtype: arrow_left_click
    id: button_left_click
  - platform: device
    device_id: !input mqtt_device
    domain: mqtt
    type: action
    subtype: arrow_left_hold
    id: button_left_hold
  - platform: device
    device_id: !input mqtt_device
    domain: mqtt
    type: action
    subtype: arrow_left_release
    id: button_left_release
  - platform: device
    device_id: !input mqtt_device
    domain: mqtt
    type: action
    subtype: arrow_right_click
    id: button_right_click
  - platform: device
    device_id: !input mqtt_device
    domain: mqtt
    type: action
    subtype: arrow_right_hold
    id: button_right_hold
  - platform: device
    device_id: !input mqtt_device
    domain: mqtt
    type: action
    subtype: arrow_right_release
    id: button_right_release
variables:
  enable_hold_dimming: !input enable_hold_dimming
action:
  - choose:
      - conditions:
          - condition: trigger
            id: light_on
        sequence:
          - service: light.turn_on
            target:
              entity_id: !input light_entity
      - conditions:
          - condition: trigger
            id: light_off
        sequence:
          - service: light.turn_off
            target:
              entity_id: !input light_entity
      # Brightness Adjustments for primary light
      - conditions:
          - condition: trigger
            id: dim_down
        sequence:
          - repeat:
              sequence:
                - service: light.turn_on
                  target:
                    entity_id: !input light_entity
                  data:
                    brightness_step_pct: -10
                - delay:
                    milliseconds: 500
              until:
                - condition: trigger
                  id: dim_stop
      - conditions:
          - condition: trigger
            id: dim_up
        sequence:
          - repeat:
              sequence:
                - service: light.turn_on
                  target:
                    entity_id: !input light_entity
                  data:
                    brightness_step_pct: 10
                - delay:
                    milliseconds: 500
              until:
                - condition: trigger
                  id: dim_stop
      # Left Button Actions
      - conditions:
          - condition: trigger
            id: button_left_click
        sequence: !input button_left_click
      - conditions:
          - condition: trigger
            id: button_left_hold
          - condition: template
            value_template: "{{ enable_hold_dimming }}"
        sequence:
          - repeat:
              sequence:
                - service: light.turn_on
                  target:
                    entity_id: !input dimmable_entity
                  data:
                    brightness_step_pct: -10
                - delay:
                    milliseconds: 500
              until:
                - condition: trigger
                  id: button_left_release
      - conditions:
          - condition: trigger
            id: button_left_hold
          - condition: template
            value_template: "{{ not enable_hold_dimming }}"
        sequence: !input button_left_hold
      - conditions:
          - condition: trigger
            id: button_left_release
        sequence: !input button_left_release
      # Right Button Actions
      - conditions:
          - condition: trigger
            id: button_right_click
        sequence: !input button_right_click
      - conditions:
          - condition: trigger
            id: button_right_hold
          - condition: template
            value_template: "{{ enable_hold_dimming }}"
        sequence:
          - repeat:
              sequence:
                - service: light.turn_on
                  target:
                    entity_id: !input dimmable_entity
                  data:
                    brightness_step_pct: 10
                - delay:
                    milliseconds: 500
              until:
                - condition: trigger
                  id: button_right_release
      - conditions:
          - condition: trigger
            id: button_right_hold
          - condition: template
            value_template: "{{ not enable_hold_dimming }}"
        sequence: !input button_right_hold
      - conditions:
          - condition: trigger
            id: button_right_release
        sequence: !input button_right_release
mode: restart

Help needed if someone have an idea how to reduce delay for arrow button dimming and better behaviour. It works, but could be better.