Import blueprint from here
Introduction
This blueprint is able to execute any home assistant service (typically “turn on”, aka “homeassistant.turn_on”) on any target entity (typically switch/light/scene/script) based on a trigger entity’s state (typically a motion sensor, or a door/window sensor, or any entity with a state, e.g. sun/switch/light/group), then run an alternate home assistant service (typically “turn off”) after the trigger entity is no longer at expected state after given timeout.
It also supports using illuminance sensor and sun elevation as alternative triggers.
If you got confused about what this blueprint does, it basically does what this blueprint Turn on light, switch, scene, script or group based on motion, illuminance, sun (+ more conditions) does (I was inspired by it, kudos to the author!), but in a more generic way and with a few differences:
- This blueprint is more generic about the action you can execute with target entity as stated above.
- This blueprint handles home assistant restart. e.g. Your lights that were turned on before the home assistant will be turned off properly after the home assistant restart, following the same no motion (or other trigger entity state change) timeout.
- This blueprint handles automation changes. e.g. Your lights will be properly turned off after you edited an automation (which restarts all executing automations and resets their action status).
- This blueprint handles manual turn on/off of target entity. e.g. Your lights will be properly turned off following the same no motion timeout even if you manually turned them on using UI/App, or physical switch.
- This blueprint supports leveraging sun elevation. This is very useful if you do not have any illuminance sensor, or your illuminance sensor is installed under the light controlled by an automation (once the light is on, the illuminance sensor will no longer return an expected value).
- This blueprint provide a convenient way to select an alternative timeout in specific time range. In my case, I want the timeout to be longer during dinner time, since my family are mostly sitting still and the motion sensor may miss some of our motions. In some cases, I want the timeout to be shorted after middle night, since I may be just walking down the hallway to go to the bathroom, I don’t want my hallway light stay on for too long.
Use Cases & Examples
Turn on “Hallway Light” when any motion sensor in the “group.kitchen_hallway_motion_sensors” group detected a motion, and when illuminance sensor returned a value below 400. Turn off the light if all motion sensors are cleared for 10 seconds, or if all motion sensors are cleared for 300 seconds when the time is between 6pm and 9:40pm.
alias: Hallway Light
description: ''
use_blueprint:
path: ql-owo-lp/state_based_entity_control.yaml
input:
trigger_entity: group.kitchen_hallway_motion_sensors
target_entity: switch.kitchen_hallway_light
illuminance_sensor: sensor.illumination_1
illuminance_below: '400'
alt_trigger_timeouts: '18:00:00-21:40:00,300'
trigger_timeout: '10'
Turn on “Office Light” when “binary_sensor.motion_sensor_1” detected a motion, and when illuminance sensor returned a value below 400 or the Sun elevation is below 9. Turn off the light if the motion sensors are cleared for 15 seconds.
alias: Office Light
description: ''
use_blueprint:
path: ql-owo-lp/state_based_entity_control.yaml
input:
trigger_entity: binary_sensor.motion_sensor_1
target_entity: group.office_lights
trigger_timeout: '15'
illuminance_sensor: sensor.illumination_1
illuminance_below: '400'
sun_elevation_below: '9'
Turn on “Closet Light” when closet door is open, and when illuminance sensor returned a value below 400 or the Sun elevation is below 9. Turn off the light if the closet door is closed for 5 seconds.
alias: Closet Light
description: ''
use_blueprint:
path: ql-owo-lp/state_based_entity_control.yaml
input:
trigger_entity: group.closet_door_sensors
target_entity: group.closet_lights
trigger_timeout: '5'
illuminance_sensor: sensor.illumination_1
illuminance_below: '400'
sun_elevation_below: '9'
Change log:
- 2/1/2021: This blueprint supports multiple states and multiple alternate timeouts now. If you are updating to this new version from an older version, and you used the alternate timeout field, you will have to update the automation to follow the new format. The alternate timeout is now merged into one field instead of three fields. See the field documentation for details about the new format.
Enjoy the blueprint!