Sun AND time condition

Hi,

I’m trying a condition where sun must be down AND between set time.

Does not work for me. Some expert has a solution? Thanks in advance!

condition: and
conditions:
  - condition: or
    conditions:
      - condition: sun
        after: sunset
      - condition: sun
        before: sunrise
  - condition: and
    conditions:
      - condition: time
        after: input_datetime.night
        before: input_datetime.morning
  - condition: device
    type: is_on
    device_id: e455490800c2a2a07b6f2f75f2286943
    entity_id: switch.window
    domain: switch
condition:
  - condition: or
    conditions:
      - condition: sun
        after: sunset
      - condition: sun
        before: sunrise
  - condition: time
    after: input_datetime.night
    before: input_datetime.morning
  - "{{ is_state('switch.window', 'on') }}"

If the above code fails, check your automation debug trace to find out which condition is not satisfied.

Note: By default, all specified conditions are AND-ed. All conditions must be satisfied in order for the automation to proceed to the action part.