Close curtains only when I close the window

Hey together

When my window is closed, I want the curtain to close at sunset, this works. However, when it is open, I do not want the curtain to close, but only when I then close it. The curtain does not close when the Fesnter is open but also not as soon as I close it. I have no additional conditions in the automation. What am I doing wrong?

if:
  - condition: state
    entity_id: binary_sensor.aqara_fensterkontakt_wohnzimmer_contact
    state: "off"
then:
  - device_id: 83ce1f3a519858b6cc5b489dc215f5a2
    domain: cover
    entity_id: cover.aqara_vorhang_wohnzimmer_links
    type: set_position
    position: 0
else:
  - wait_for_trigger:
      - platform: state
        entity_id:
          - binary_sensor.aqara_fensterkontakt_wohnzimmer_contact
        to: "off"
        from: "on"
    continue_on_timeout: false
    timeout:
      hours: 0
      minutes: 0
      seconds: 0
      milliseconds: 0
  - device_id: 83ce1f3a519858b6cc5b489dc215f5a2
    domain: cover
    entity_id: cover.aqara_vorhang_wohnzimmer_links
    type: set_position
    position: 0
alias: Vorhang Wohnzimmer Fenster schliessen

Two separate automations:

Trigger: sunset
Condition: window closed
Action: close curtain

Trigger: close window
Condition: after sunset
Action: close curtain