This can be used to automate a two-node switch [like a light and an exhaust fan] inside a bathroom based on a door sensor and a motion sensor.
blueprint:
name: Bathroom 2-node automation v2
description: Automate your bathroom
domain: automation
input:
motion_sensor:
name: Motion Sensor
description: The motion sensor used as a trigger
selector:
entity:
device_class: motion
domain: binary_sensor
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
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
trigger:
- 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: Door Open
condition: []
action:
- choose:
- conditions:
- condition: trigger
id: Door Open
sequence:
- service: switch.turn_on
target:
entity_id: !input target_sw1
- delay: "0:00:10"
- conditions:
- condition: trigger
id: Occupied
sequence:
- service: switch.turn_on
target:
entity_id: !input target_sw1
- service: switch.turn_on
target:
entity_id: !input target_sw2
- conditions:
- condition: trigger
id: Room exit
- condition: state
entity_id: !input motion_sensor
state: "off"
- condition: state
entity_id: !input door_sensor
state: "off"
sequence:
- delay: !input off_delay
- service: switch.turn_off
target:
entity_id: !input target_sw1
- service: switch.turn_off
target:
entity_id: !input target_sw2
default: []
mode: restart
max_exceeded: silent