Skip to content

Instantly share code, notes, and snippets.

@zollak
Last active June 2, 2025 10:33
Show Gist options
  • Save zollak/d5250551e8a806e269c261dc30f2f67d to your computer and use it in GitHub Desktop.
Save zollak/d5250551e8a806e269c261dc30f2f67d to your computer and use it in GitHub Desktop.
Custom Home Assistant blueprint YAML that improves on the built-in "Motion-activated Light" automation by allowing multiple triggers: presence sensor, door/window sensor, and door cover. It also includes a check for ambient light level (illuminance) before turning on the ceiling light, and it retains the built-in delay before turning the light off.
blueprint:
name: Motion + Door Activated Light with Illuminance Check
description: >
Turns on the light when occupancy is detected, door/window opens,
or the cover starts opening, but only if it's dark enough.
Turns off after no presence is detected for the specified time.
domain: automation
source_url: https://gist.github.com/zollak/d5250551e8a806e269c261dc30f2f67d
author: zollak
input:
light_target:
name: Light
selector:
target:
entity:
domain: light
presence_sensor:
name: Presence Sensor
selector:
entity:
filter:
- device_class: occupancy
domain: binary_sensor
- device_class: motion
domain: binary_sensor
door_sensor:
name: Door/Window Sensor
selector:
entity:
domain: binary_sensor
device_class: door
cover_entity:
name: Cover
selector:
entity:
domain: cover
illuminance_sensor:
name: Illuminance Sensor
selector:
entity:
domain: sensor
device_class: illuminance
illuminance_threshold:
name: Max Ambient Light (lx)
description: Light will only turn on if illuminance is below this value.
default: 100
selector:
number:
min: 0
max: 1000
unit_of_measurement: lx
mode: slider
no_motion_wait:
name: Wait Time After No Presence (seconds)
description: Time to leave the light on after last motion is detected.
default: 120
selector:
number:
min: 10
max: 3600
unit_of_measurement: seconds
mode: slider
# If motion is detected within the delay,
# we restart the script.
mode: restart
max_exceeded: silent
trigger:
- alias: "Occupancy detected"
platform: state
entity_id: !input presence_sensor
from: "off"
to: "on"
- alias: "Door/window opened"
platform: state
entity_id: !input door_sensor
from: "off"
to: "on"
- alias: "Cover is opening"
platform: state
entity_id: !input cover_entity
to: "opening"
condition:
- alias: "Check if illuminance is low enough"
condition: numeric_state
entity_id: !input illuminance_sensor
below: !input illuminance_threshold
action:
- alias: "Turn on the light"
service: light.turn_on
target: !input light_target
- alias: "Wait until presence sensor is off"
wait_for_trigger:
- platform: state
entity_id: !input presence_sensor
from: "on"
to: "off"
continue_on_timeout: false
- alias: "Wait the number of seconds that has been set"
delay:
seconds: !input no_motion_wait
- alias: "Turn off the light"
service: light.turn_off
target: !input light_target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment