Bathroom 2-node automation

This can be used to automate a two-node switch [say a light and an exhaust fan] inside a bathroom based on a door sensor and a motion sensor.

Referred: Bathroom light and fan automation - Blueprints Exchange - Home Assistant Community (home-assistant.io)

blueprint:
  name: Bathroom 2-node automation
  description: Automate your bathroom
  domain: automation
  input:
    motion_sensor:
      name: Motion Sensor
      description: The motion sensor used as a trigger
      selector:
        entity:
          domain: binary_sensor
          device_class: motion
    door_sensor:
      name: Contact Sensor
      description: The door sensor used on the bathroom door
      selector:
        entity:
          domain: binary_sensor
    target_sw1:
      name: Target Switch1
      description: The first switch you want to control
      selector:
        entity:
          domain: switch
    target_sw2:
      name: Target Switch2
      description: The second switch you want to control
      selector:
        entity:
          domain: switch
    sw1_timer:
      name: Switch1 Timer
      description: This timer will control the first switch
      selector:
        entity:
          domain: timer
    sw2_timer:
      name: Switch2 Timer
      description: This timer will control the second switch
      selector:
        entity:
          domain: timer
    off_delay:
      name: Off Delay
      description: Time it takes for the switches to turn off after last motion
      default: 60
      selector:
        number:
          min: 0
          max: 3600
          unit_of_measurement: seconds
    on_delay:
      name: On Delay
      description: Time it takes for the switches to turn on after closing the door.
      default: 0
      selector:
        number:
          min: 1
          max: 3600
          unit_of_measurement: seconds
trigger:
#  - platform: event
#    event_type: timer.finished
#    event_data:
#      entity_id: !input sw2_timer
#    id: SW2 On
#  - platform: event
#    event_type: timer.finished
#    event_data:
#      entity_id: !input sw1_timer
#    id: SW1 Off
  - platform: state
    entity_id:
      - !input motion_sensor
    to: "off"
    id: Room exit
  - platform: state
    entity_id:
      - !input motion_sensor
    to: "on"
    id: Occupied
  - platform: state
    entity_id:
      - !input door_sensor
    to: "off"
    id: Door Close
  - platform: state
    entity_id:
      - !input door_sensor
    to: "on"
    id: Room exit
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: 
        sequence:
          - service: timer.start
            data:
              duration: !input off_delay
            target:
              entity_id: !input sw1_timer
          - service: switch.turn_on
            data: {}
            target:
              entity_id: !input target_sw1
      - conditions:
          - condition: trigger
            id: SW1 Off
          - condition: state
            entity_id: !input motion_sensor
            state: "off"
          - condition: state
            entity_id: !input door_sensor
            state: "on"
        sequence:
          - service: switch.turn_off
            data: {}
            target:
              entity_id: !input target_sw1
          - service: switch.turn_off
            data: {}
            target:
              entity_id: !input target_sw2
      - conditions:
          - condition: trigger
            id: SW2 On
          - condition: state
            entity_id: !input door_sensor
            state: "off"
        sequence:
          - service: switch.turn_on
            data: {}
            target:
              entity_id: !input target_sw2
      - conditions:
          - condition: trigger
            id: Door Close
        sequence:
          - service: timer.start
            data:
              duration: !input on_delay
            target:
              entity_id: !input sw2_timer
          - service: timer.start
            data:
              duration: !input off_delay
            target:
              entity_id: !input sw1_timer
      - conditions:
          - condition: trigger
            id: Room exit
        sequence:
          - service: timer.start
            data:
              duration: !input off_delay
            target:
              entity_id:
                - !input sw1_timer
    default: []
mode: restart
max_exceeded: silent