Outdoor Light Automation

I’m trying to setup outdoor lighting as follows.

  1. The landscape lighting, front yard house lighting and back yard house lighting turn on at sunset.
  2. The back yard house lighting and landscape lighting turn off at midnight.
  3. The front yard house lighting turns off at sunrise (so they are the only lights on all night).
  4. The landscape lighting and back yard house lighting turn on if motion is detected between the hours of midnight and sunrise, and automatically turn off after 20 minutes of no motion detected. I also want a notification sent to my phone if this automation is triggered.

I’ve been able to successfully create automatons for items 1-3. Item 4 is not working correctly. The automation I created does work correctly during midnight and sunrise, but, it doesn’t stop at sunrise. It continues to be triggered during the day. It also doesn’t seem me a notification.

For context I have 6 Z-Wave motion detectors setup in the yard. They are integrated and working.

Please review my sequence below and let me know what I’ve done wrong. This automation is for one of the motion detectors. I’ve setup pretty much the exact same one for all 6 motion detectors (of course the motion devices are different).

type: motion
device_id: xxxxxxxxxxxxxxxx 
entity_id: xxxxxxxxxxxxxxxx 
domain: binary_sensor
trigger: device
id: Motion Detected

type: no_motion
device_id: xxxxxxxxxxxxxxxx 
entity_id: xxxxxxxxxxxxxxxx 
domain: binary_sensor
trigger: device
id: Detects No Motion
for:
  hours: 0
  minutes: 20
  seconds: 0
action: light.turn_on
metadata: {}
data: {}
target:
  area_id: backyard_house_lights
  device_id: xxxxxxxxxxxxxxxxxcxxx
choose:
  - conditions:
      - condition: trigger
        id:
          - Motion Detected
      - condition: time
        after: "00:00:02"
        weekday:
          - sun
          - mon
          - tue
          - wed
          - thu
          - fri
          - sat
      - condition: sun
        before: sunrise
    sequence:
      - action: light.turn_on
        metadata: {}
        data: {}
        target:
          area_id: backyard_house_lights
          device_id: xxxxxxxxxxxxxxxx 
      - action: notify.mobile_app_pixel_9_pro
        metadata: {}
        data:
          message: "Motion detected by the Back Patio outside motion detector "
          title: "Motion Detected "
  - conditions:
      - condition: trigger
        id:
          - Detects No Motion
      - condition: time
        after: "00:00:02"
        weekday:
          - sun
          - mon
          - tue
          - wed
          - thu
          - fri
          - sat
      - condition: sun
        before: sunrise
    sequence:
      - action: light.turn_off
        metadata: {}
        data: {}
        target:
          area_id:
            - backyard_house_lights
          device_id: xxxxxxxxxxxxxxxxx

Try:

choose:
  - conditions:
      - condition: trigger
        id:
          - Motion Detected
      - condition: state
        entity_id: sun.sun
        state: below_horizon
      - condition: time
        after: "00:00:05"
    sequence:
      - action: light.turn_on
        metadata: {}
        data: {}
        target:
          area_id: backyard_house_lights
          device_id: xxxxxxxxxxxxxxxx
      - action: notify.mobile_app_pixel_9_pro
        metadata: {}
        data:
          message: "Motion detected by the Back Patio outside motion detector "
          title: "Motion Detected "
  - conditions:
      - condition: trigger
        id:
          - Detects No Motion
      - condition: state
        entity_id: sun.sun
        state: below_horizon
      - condition: time
        after: "00:00:05"
    sequence:
      - action: light.turn_off
        metadata: {}
        data: {}
        target:
          area_id:
            - backyard_house_lights
          device_id: xxxxxxxxxxxxxxxxx

The sun.sun entity is