Push button swicht event - long press to increase brightness

Hello all

i want to create an automation to turn the lights on/off and increase/decrease brigthness with a switch.
I have one switch to turn the lights on / increase the brightness for long press and another switch for turning the lights off / decrease the brightess.
Events:
Push the button switch and release
1000, 1002

Push the button switch and holding it down, release:
1000, 1001, 1003

I dont know how to implement the long press function to increase/decrease the brightness

This is my automation to turn the light on

alias: Light on
description: ''
trigger:
  - platform: event
    event_type: deconz_event
    event_data:
      id: taster_windfang_flurtuer
      event: 1000
    id: '1000'
  - platform: event
    event_type: deconz_event
    event_data:
      id: taster_windfang_flurtuer
      event: 1002
    id: '1002'
condition:
  - condition: trigger
    id: '1000'
action:
  - service: light.turn_on
    target:
      entity_id: light.buero_deckenlampe
    data:
      brightness_pct: 100
mode: single

Any ideas why the light keeps flashing. If i release the button switch, the automation normally should stop?

alias: Light on
description: ''
trigger:
  - platform: event
    event_type: deconz_event
    event_data:
      id: taster_windfang_flurtuer
      event: 1001
    id: '1001'
condition: []
action:
  - repeat:
      while:
        - condition: trigger
          id: '1001'
      sequence:
        - service: light.turn_on
          target:
            entity_id: light.buero_deckenlampe
          data:
            brightness: >
              {% set bri = state_attr('light.buero_deckenlampe', 'brightness') |
              int %} {{ [bri+15, 255] | min }}
mode: single

I tried another method but its not stopping the automation?

Should stop the “Lighton” automation

- id: '1641551831908'
  alias: Light increase stop
  description: ''
  trigger:
  - platform: event
    event_type: deconz_event
    event_data:
      id: taster_windfang_flurtuer
      event: 1003
    id: '1003'
  condition: []
  action:
  - service: homeassistant.turn_off
    target:
      entity_id:
      - automation.Lighton
  mode: single

Increase brightness

- id: '1641539208950'
  alias: Lighton
  description: ''
  trigger:
  - platform: event
    event_type: deconz_event
    event_data:
      id: taster_windfang_flurtuer
      event: 1001
    id: '1001'
  condition: []
  action:
  - service: light.turn_on
    data:
      transition: 20
      brightness: 255
    target:
      entity_id: light.buero_deckenlampe
  mode: single