Multiple Zones for Presence in Room

Hello, I have an Aqara FP2 that I am experimenting with multiple presence zones and need some assistance.

Scenario is if someone can’t sleep and gets up in middle of night, they exit the bedroom to the living room and there is a 5 sec delay then a small lamp turns on, if the person goes to the couch to lie down the lamp will turn off after 20 sec.

If the person leaves the couch the lamp turns back on again, and if they leave the living room and return to bedroom the lamp turns off.

I have muddled together an Automation that for the most part is doing what I need, but I can’t get the lamp to turn off when exiting the living room and returning to bedroom. I don’t know how to differentiate from the initial detection from bedroom to living room which I think is what stops the light turning off.

Any guidance would be greatly appreciated.

alias: "Overnight: Living Room Luminosity"
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.presence_sensor_fp2_c22b_presence_sensor_3
    id: Couch Clear
    enabled: true
    from: "on"
  - platform: state
    entity_id:
      - binary_sensor.presence_sensor_fp2_c22b_presence_sensor_3
    to: "on"
    id: Couch Detected
  - platform: state
    entity_id:
      - binary_sensor.presence_sensor_fp2_c22b_presence_sensor_2
    id: Bedroom Door Clear
    from: "on"
  - platform: state
    entity_id:
      - binary_sensor.presence_sensor_fp2_c22b_presence_sensor_2
    to: "on"
    id: Bedroom Door Detected
condition:
  - condition: state
    entity_id: input_boolean.vacation_mode
    state: "off"
  - condition: time
    after: "23:30:00"
    before: "06:00:00"
    enabled: true
  - condition: numeric_state
    entity_id: binary_sensor.presence_sensor_fp2_c22b_presence_sensor_1
    below: 45
    enabled: true
action:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - Bedroom Door Detected
        sequence:
          - delay:
              hours: 0
              minutes: 0
              seconds: 3
              milliseconds: 0
          - service: light.turn_on
            target:
              entity_id: light.dining_room
            data: {}
      - conditions:
          - condition: trigger
            id:
              - Couch Detected
        sequence:
          - delay:
              hours: 0
              minutes: 0
              seconds: 20
              milliseconds: 0
          - service: light.turn_off
            target:
              entity_id: light.dining_room
            data: {}
      - conditions:
          - condition: trigger
            id:
              - Couch Clear
        sequence:
          - alias: Turn on the light
            service: light.turn_on
            target:
              entity_id:
                - light.dining_room
            data: {}
          - alias: Wait until there is no motion from device
            wait_for_trigger:
              - platform: state
                entity_id:
                  - binary_sensor.presence_sensor_fp2_c22b_presence_sensor_1
                from: "on"
                to: "off"
            enabled: true
          - service: light.turn_off
            target:
              entity_id: light.dining_room
            data: {}
mode: restart
max_exceeded: silent

I’ll be honest, I didn’t read your entire post because since I got my first FP2 I bought 2 more - bedroom, living room and kitchen. The individual zones (couch occupied in living room FP2) or (dinette occupied in kitchen FP2) or (bed occupied in bedroom FP2) all work flawlessly. I have overall automations for “room occupied” and specific automations for the sub-zones occupied and they all work as expected.

Ok, I’ll try changing some stuff around with your approach. Maybe I don’t need the Bedroom Door zone?