Trouble with automation Ikea UPPATVIND

so I modded my UPPATVIND with esphome. Everything works perfectly, but I tryed to build an aumation for it. I wish that if it has been working for 30 min, it simply puts it off. Now the trouble it’s that it has 3 speed, so if I’m at speed 3, it only need to press once, but at speed 1 it needs to press 3 times. Also if the press are too quick, it doesn’t seem to work either, hence the delay. My current automation works sometimes, others not :frowning: most of the time it will click once or twice, so if I’m at speed 3 for example it will close the air purifier, but if I’m at speed 1, it will set it to speed 3, and let it go :frowning:

How can I make a better automation ?

alias: UPPATVIND Close after 30 min
description: ""
trigger:
  - platform: numeric_state
    entity_id:
      - sensor.uppatvind_fan_speed_led
    for:
      hours: 0
      minutes: 30
      seconds: 0
    above: 0
condition: []
action:
  - service: button.press
    metadata: {}
    data: {}
    target:
      entity_id: button.uppatvind_switch
  - delay:
      hours: 0
      minutes: 0
      seconds: 10
      milliseconds: 0
  - if:
      - condition: numeric_state
        entity_id: sensor.uppatvind_fan_speed_led
        above: 0
    then:
      - service: button.press
        metadata: {}
        data: {}
        target:
          entity_id: button.uppatvind_switch
  - delay:
      hours: 0
      minutes: 0
      seconds: 10
      milliseconds: 0
  - if:
      - condition: numeric_state
        entity_id: sensor.uppatvind_fan_speed_led
        above: 0
    then:
      - service: button.press
        metadata: {}
        data: {}
        target:
          entity_id: button.uppatvind_switch
mode: single