Automation Condition Sun

Hi,

Recently I created an automation that needs to do the following switch the light on before Sunrise and after Sunset only if motion is detected.
So for testing I used the following script turn the light on after Sunrise and before Sunset if motion is detected leave the lights on for 20 seconds.

This seem to work just fine, but when I switch back to before Sunrise and after Sunset the lights won’t turn on!?

What am I overlooking?

alias: Licht Zolder
description: Spotjes Zolder Motion Sensor
trigger:
  - type: motion
    platform: device
    device_id: 7f54b57bf0ba1fee8ed9a7363372af64
    entity_id: binary_sensor.lidl_zolder
    domain: binary_sensor
  - platform: state
    entity_id: binary_sensor.lidl_zolder
    from: 'off'
    to: 'on'
condition:
  - condition: sun
    before: sunset
    after: sunrise
action:
  - service: switch.turn_on
    data: {}
    target:
      entity_id: switch.tasmota_6
  - wait_for_trigger:
      - platform: state
        entity_id: binary_sensor.lidl_zolder
        from: 'on'
        to: 'off'
        for: '00:00:20'
    continue_on_timeout: false
  - service: switch.turn_off
    data: {}
    target:
      entity_id:
        - switch.tasmota_6
mode: single
alias: Licht Zolder
description: Spotjes Zolder Motion Sensor
trigger:
  - type: motion
    platform: device
    device_id: 7f54b57bf0ba1fee8ed9a7363372af64
    entity_id: binary_sensor.lidl_zolder
    domain: binary_sensor
  - platform: state
    entity_id: binary_sensor.lidl_zolder
    from: 'off'
    to: 'on'
condition:
  - condition: sun
    before: sunrise
    after: sunset
action:
  - service: switch.turn_on
    data: {}
    target:
      entity_id: switch.tasmota_6
  - wait_for_trigger:
      - platform: state
        entity_id: binary_sensor.lidl_zolder
        from: 'on'
        to: 'off'
        for: '00:00:20'
    continue_on_timeout: false
  - service: switch.turn_off
    data: {}
    target:
      entity_id:
        - switch.tasmota_6
mode: single

is an impossible situation. We had a recent discussion here.

Additionally: WTH - sunrise/sunset

Hmm, thanks for referring to these articles.

This is from the documentation:

Note that if only before key is used, the condition will be true from midnight until sunrise/sunset. If only after key is used, the condition will be true from sunset/sunrise until midnight. Therefore, to cover time between sunset and sunrise one need to use after: sunset and before: sunrise as 2 separate conditions and combine them using or.


condition:
  condition: or
  conditions:
    - condition: sun
      after: sunset
    - condition: sun
      before: sunrise