Bathroom light and fan automation

I created this from an automation I have been using for awhile. Its not made in the traditional way most lighting automations are done. I prefer to use timers as they seem to be much more reliable especially if you are tinkering with automations alot. This method has proven to be pretty reliable in turning off the lights and fan.
This blueprint requires 2 sensors. A motion and a door/contact sensor.
It also requires 2 timers. One for the light and one for the fan.
It operates under the assumption that if the door is closed, the room is occupied. If it is occupied, we are assuming that you are doing something that may require the fan to be turned on. The light and fan will stay on as long as the door is closed.
You can set the time to turn on the fan after the door is closed. The fan timer will not activate until the door is closed.
The other timer selection is to choose the delay after last motion to when the lights turn off.
2 triggers can start the countdown trigger. Last motion, and opening the door. I did that for redundancy in case one trigger fails. Most of the time last motion wins out.
This is my first blueprint…
See the Gist

blueprint:
  name: Bathroom Light and Fan Controller
  description: Automate your bathroom light and fan
  domain: automation
  input:
    motion_sensor:
      name: Motion Sensor
      description: The motion sensor used to trigger the lights
      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_light:
      name: Target Light
      description: The light you want to control
      selector:
        entity:
          domain: light
    target_fan:
      name: Target Fan
      description: The fan you want to control
      selector:
        entity:
    light_timer:
      name: Light Timer
      description: This timer will control the light
      selector:
        entity:
          domain: timer
    fan_timer:
      name: Fan Timer
      description: This timer will control the fan
      selector:
        entity:
          domain: timer
    light_off_time:
      name: Lights out Time
      description: Time it takes for the light and fan to turn off after last motion
      default: 90
      selector:
        number:
          min: 0
          max: 3600
          unit_of_measurement: seconds
    fan_on_time:
      name: Fan on Delay
      description: Time it takes for the fan to turn on after closing the door.
      default: 90
      selector:
        number:
          min: 1
          max: 3600
          unit_of_measurement: seconds
trigger:
  - platform: event
    event_type: timer.finished
    event_data:
      entity_id: !input fan_timer
    id: Fan On
  - platform: event
    event_type: timer.finished
    event_data:
      entity_id: !input light_timer
    id: Light Off
  - platform: state
    entity_id:
      - !input motion_sensor
    to: "off"
    id: Room exit
  - platform: state
    entity_id:
      - !input motion_sensor
    to: "on"
    id: Light On
  - 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: Light On
        sequence:
          - service: timer.start
            data:
              duration: !input light_off_time
            target:
              entity_id: !input light_timer
          - service: light.turn_on
            data: {}
            target:
              entity_id: !input target_light
      - conditions:
          - condition: trigger
            id: Light Off
          - condition: state
            entity_id: !input motion_sensor
            state: "off"
          - condition: state
            entity_id: !input door_sensor
            state: "on"
        sequence:
          - service: light.turn_off
            data: {}
            target:
              entity_id: !input target_light
          - service: fan.turn_off
            data: {}
            target:
              entity_id: !input target_fan
      - conditions:
          - condition: trigger
            id: Fan On
          - condition: state
            entity_id: !input door_sensor
            state: "off"
        sequence:
          - service: fan.turn_on
            data: {}
            target:
              entity_id: !input target_fan
      - conditions:
          - condition: trigger
            id: Door Close
        sequence:
          - service: timer.start
            data:
              duration: !input fan_on_time
            target:
              entity_id: !input fan_timer
          - service: timer.start
            data:
              duration: !input light_off_time
            target:
              entity_id: !input light_timer
      - conditions:
          - condition: trigger
            id: Room exit
        sequence:
          - service: timer.start
            data:
              duration: !input light_off_time
            target:
              entity_id:
                - !input light_timer
    default: []
mode: restart
max_exceeded: silent
2 Likes

New to HA

The light timer and fan timer are drop down options after importing the blueprint. But only option I am getting for both is “no matching entities found”.

How do we go about setting up these entities?

Also, I have the Kasa Motion Dimmer switch, I wasn’t getting that in the drop down for the Motion Sensor part, but edited in YAML and pasted the product name manually over there and showed up now in the box, hopefully it’ll work!

You need to create those timers in the helpers menu.
Devices and services, then helpers at the top.