Cant seem to automate lights based on door condition

Hi all.

I have the following automation

alias: guest light automation
description: guest automation for lights on/off
trigger:
  - type: motion
    platform: device
    device_id: bf4f40f0e5729debfffc56ddd7e5f576
    entity_id: binary_sensor.guest_motion
    domain: binary_sensor
    id: motion-detected
  - type: no_motion
    platform: device
    device_id: bf4f40f0e5729debfffc56ddd7e5f576
    entity_id: binary_sensor.guest_motion
    domain: binary_sensor
    id: motion-stopped
condition:
  - condition: state
    entity_id: input_boolean.guest_autoswitch
    state: "on"
action:
  - choose:
      - conditions:
          - condition: trigger
            id: motion-detected
          - condition: time
            before: "22:30:00"
            weekday:
              - sun
              - sat
              - fri
              - thu
              - wed
              - tue
              - mon
            after: "07:00:00"
        sequence:
          - service: light.turn_on
            data:
              brightness: 255
              color_temp: 337
            target:
              entity_id: light.guest
      - conditions:
          - condition: trigger
            id: motion-detected
          - condition: time
            after: "22:30:00"
            before: "07:00:00"
            weekday:
              - sun
              - sat
              - fri
              - thu
              - wed
              - tue
              - mon
        sequence:
          - service: light.turn_on
            data:
              brightness: 40
              rgb_color:
                - 58
                - 136
                - 254
            target:
              entity_id: light.guest
      - conditions:
          - condition: trigger
            id: motion-stopped
          - condition: state
            entity_id: binary_sensor.guest_contact
            state: "off"
            for:
              hours: 0
              minutes: 10
              seconds: 0
        sequence:
          - service: light.turn_off
            data: {}
            target:
              entity_id: light.guest
      - conditions:
          - condition: trigger
            id: motion-stopped
          - condition: state
            entity_id: binary_sensor.guest_contact
            state: "on"
            for:
              hours: 0
              minutes: 3
              seconds: 0
        sequence:
          - service: light.turn_off
            data: {}
            target:
              entity_id: light.guest
mode: single

the lights coming on do work out reliably but im struggling with the turn off part. I cant seem to get it to work to turn off based on the condition of the door being closed/open. if the door is open I want it to count 3:00 minutes and then turn off and when the door is closed count 10:00 and then turn off.
clearly im doing something wrong in the automation :slight_smile: any help would be very appreciated!

best

Z