Light automation help please - 2 lights with motion and sunset timers

Hey all,
im trying to build an automation but cant quite get it working as expected!

What I want to happen:

  • Sunset to 11pm: Front door swan light (only) is always on, after 11pm it then goes off.
  • If there is ANY motion detected and the light level is below 30, then I want all the lights to come on for 5minutes and switch off again.
    So if its 1am then both lights on for 5pm and off again.
    If its 10pm, then the swan is already on and the front door would come on for 5min and then turn off again.

Issue: the lights dont seem to go off when the motion has expired, past 11pm

I have 2 lights at the front of my house:

  • light.front_door_swan
  • lightlight.front_door

these are then in a light group called:

  • light.porch_all_lights_outside

There is a motion sensor called:

  • binary_sensor.front_porch_outside_motion
- id: frontporchoutsidelightsonmotion
  alias: front porch outside lights on motion
  mode: restart
  trigger:
  - entity_id: binary_sensor.front_porch_outside_motion
    from: 'off'
    platform: state
    to: 'on'
  condition:
    condition: numeric_state
    entity_id: sensor.front_porch_outside_motion_lightlevel
    below: 30
  action:
  - service: light.turn_on
    entity_id: light.porch_all_lights_outside
  - service: timer.start
    data_template:
      entity_id: timer.timer_porch_outside_lights_on
      duration: "00:{{ states('input_number.timer_porch_outside_motion_slider') | int }}:00"
- id: frontporchoutsidelightsoffafterxminnomotion
  alias: front porch outside lights off no motion timer expired
  mode: restart
  trigger:
    platform: state
    entity_id: binary_sensor.front_porch_outside_motion
    to: 'off'
    for:
      minutes: "{{ states('input_number.timer_porch_outside_motion_slider') | int }}"
  action:
    service: light.turn_off
    entity_id: light.front_door
- id: frontporchoutsideswanlightsoffafterxminnomotionpast11
  alias: front porch outside swan lights off no motion timer expired past 11
  trigger:
    platform: state
    entity_id: binary_sensor.front_porch_outside_motion
    to: 'off'
    for:
      minutes: 2
  condition:
    after: "23:00:00"
    before: "06:00:00"
  action:
    service: light.turn_off
    entity_id: light.front_door_swan
- id: frontporchoutsidelightsonaftersunset
  alias: front porch outside swan lights on after sunset
  mode: restart
  trigger:
    platform: numeric_state
    entity_id: sun.sun
    value_template: '{{ state_attr(''sun.sun'', ''elevation'') }}'
    below: -3.0
  action:
    - service: light.turn_on
      data:
      entity_id:
        - light.front_door_swan

- alias: frontporchoutsidelightsofat11
  id: frontporchoutsidelightsoffafter11
  trigger:
    - platform: time
      at: "23:00:01"
  action:
    service: light.turn_off
    entity_id: light.front_door_swan