Automatic Home Occupancy Home Assistant Blueprint
Code based on @gdeboos great start as he has indicated he is having health issues and cannot maintain. Please remove
Automatically turn on and off an occupancy input_boolean helper entity for a single room based on activity or non-activity (with timeout). Current “Activities” include:
- Motion Detection
- Media_Player state changes
- Presence detection (ie ESPresence or Room-Assistant) state changes
- Household Group/Guest state changes
------SETUP------
The following helper entities are required:
- input_boolean.[room]_occupancy (input_boolean that will be turned on/off with occupancy)
The following entities are optional for full automation functionality:
- group.household (A grouped set of people in your house. Logic to turn on occupancy will only run if state is “home”".)
- input_boolean.[room]_occupancy_disabled (input_boolean that disables the automation)
- input_boolean.guest (input_boolean that will enable the automation when household is away)
------LOGIC------
Occupied triggered when ANY of the following conditions are met (all are optional).
- door binary_sensor (or group) state to “off”/closed (for interior rooms eg. bathrooms)
- media player(s) state as specified (default: “playing”)
- motion binary_sensor (or group) state to “on”
- room presence sensor (eg. room-assistant) state as specified
Occupancy is cleared when ALL of the following conditions are met (all are optional):
- door binary_sensor (or group) state to “on”/open for specified time (default: 0 mins)
- any media player state to state as specified (default: “playing”)
- any motion binary_sensor (or group) state to “off” for specified time (default: 10 mins)
- presence sensor(s) all detected in different room or “not_home”
- group.household changes to “not_home” state AND input_boolean.guest is off
------OPTIONAL HELPERS------
Uses the following helpers to allow for front end control of timeouts. Defaults are as specified below:
- input_number.door_occupancy_timeout (in minutes, default: 0)
- input_number.media_occupancy_timeout (in minutes, default: 10)
- input_number.motion_occupancy_timeout (in minutes, default: 10)
------To-Do------
- Allow multiple entities to be selected for each category, for now groups can be created and selected. Waiting on Blueprint: Device/Entity Selector invalid with multiple: true · Issue #70122 · home-assistant/core · GitHub
- Turn off media_players and occupancy when group.household is not_home and guest is off?
- Add lighting to blueprint that is controlled based on occupancy on/off?
------Application------
I personally use this input_boolean for lighting control, so when the boolean goes off, I have an automation that calls service light.turn_off for that room’s lights IF the home is operating in “Home” mode (not Nap, Bedtime, Sleep, etc.). I also use it to turn on the lights immediately (transition: 0) when the boolean turns on. This can pre-emptively turn on the lights as I walk down the hallway and room-assistant detects my phone approaching via BLE, with the motion sensor as an immediate backup. Example:
alias: Master Bedroom Occupancy Lights
description: ''
trigger:
- platform: state
entity_id: input_boolean.master_bedroom_occupancy
condition:
- condition: state
entity_id: input_select.mode
state: Home
action:
- choose:
- conditions:
- condition: state
entity_id: input_boolean.master_bedroom_occupancy
state: 'on'
- condition: state
entity_id: light.master_bedroom_lights
state: 'off'
- condition: state
entity_id: input_select.mode
state: Home
sequence:
- service: light.turn_on
data:
transition: 0
target:
entity_id: light.master_bedroom_lights
- conditions:
- condition: state
entity_id: input_boolean.master_bedroom_occupancy
state: 'off'
- condition: state
entity_id: light.master_bedroom_lights
state: 'on'
sequence:
- service: light.turn_off
target:
entity_id: light.master_bedroom_lights
data:
transition: 5
default: []
mode: single