Skip to content

Instantly share code, notes, and snippets.

@alexdetsch
Last active February 8, 2026 18:07
Show Gist options
  • Select an option

  • Save alexdetsch/486d5e4d96aa53350cc37aea19b933d0 to your computer and use it in GitHub Desktop.

Select an option

Save alexdetsch/486d5e4d96aa53350cc37aea19b933d0 to your computer and use it in GitHub Desktop.
Homeassistant Blueprint Advanced Motion activated light
blueprint:
name: Advanced Motion-Activated Lighting (Fixed & Enhanced)
description: Turn lights on when motion is detected and off after a delay. Features include manual override detection, illuminance checks, night mode brightness, and configurable blocking conditions.
domain: automation
source_url: https://gist.github.com/alexdetsch/486d5e4d96aa53350cc37aea19b933d0
input:
motion_sensors:
name: Motion Sensors
selector:
entity:
filter:
- domain: binary_sensor
device_class: motion
multiple: true
target_lights:
name: Target Lights
selector:
target:
entity:
- domain: light
no_motion_wait:
name: Wait Time
default: 120
selector:
number:
min: 0
max: 3600
unit_of_measurement: seconds
blocking_entities:
name: Blocking Entities (Optional)
default: []
selector:
entity:
multiple: true
turn_off_conditions:
name: Turn OFF Required Conditions (Optional)
default: []
selector:
entity:
multiple: true
illuminance_sensor:
name: Illuminance Sensor (Optional)
default: []
selector:
entity:
filter:
- device_class: illuminance
illuminance_threshold:
name: Illuminance Threshold
default: 100
selector:
number:
min: 0
max: 1000
unit_of_measurement: lux
night_mode_enabled:
name: Enable Night Mode
default: false
selector:
boolean:
night_mode_start:
name: Night Mode Start Time
default: "22:00:00"
selector:
time:
night_mode_end:
name: Night Mode End Time
default: "06:00:00"
selector:
time:
night_mode_brightness:
name: Night Mode Brightness
default: 20
selector:
number:
min: 1
max: 100
unit_of_measurement: "%"
day_brightness:
name: Day Brightness
default: 0
selector:
number:
min: 0
max: 100
unit_of_measurement: "%"
mode: restart
variables:
# All inputs must be mapped here to be used in Jinja templates below
blocking: !input blocking_entities
off_conditions: !input turn_off_conditions
lux_sensor: !input illuminance_sensor
lux_threshold: !input illuminance_threshold
target_entities: !input target_lights
night_enabled: !input night_mode_enabled
night_start: !input night_mode_start
night_end: !input night_mode_end
night_brightness: !input night_mode_brightness
day_brightness: !input day_brightness
trigger:
- platform: state
entity_id: !input motion_sensors
to: "on"
id: "motion_on"
- platform: state
entity_id: !input motion_sensors
to: "off"
for: !input no_motion_wait
id: "motion_off"
condition:
- condition: template
value_template: >
{% set ns = namespace(blocked=false) %}
{% for entity in blocking if is_state(entity, 'on') or is_state(entity, 'true') %}
{% set ns.blocked = true %}
{% endfor %}
{{ not ns.blocked }}
action:
- choose:
- conditions:
- condition: trigger
id: "motion_on"
- condition: template
value_template: >
{% if lux_sensor != none and lux_sensor | length > 0 and states(lux_sensor) not in ['unknown', 'unavailable'] %}
{{ states(lux_sensor) | float(0) < lux_threshold }}
{% else %}
true
{% endif %}
sequence:
- service: light.turn_on
target: !input target_lights
data:
brightness_pct: >
{% set hr = now().strftime('%H:%M:%S') %}
{% if night_enabled %}
{% if night_start > night_end %}
{{ night_brightness if hr >= night_start or hr < night_end else (day_brightness if day_brightness > 0 else 100) }}
{% else %}
{{ night_brightness if hr >= night_start and hr < night_end else (day_brightness if day_brightness > 0 else 100) }}
{% endif %}
{% else %}
{{ day_brightness if day_brightness > 0 else 100 }}
{% endif %}
- conditions:
- condition: trigger
id: "motion_off"
- condition: template
value_template: >
{% set ns = namespace(ok=true) %}
{% for entity in off_conditions %}
{% if not (is_state(entity, 'on') or is_state(entity, 'home') or is_state(entity, 'true')) %}
{% set ns.ok = false %}
{% endif %}
{% endfor %}
{{ ns.ok }}
sequence:
- service: light.turn_off
target: !input target_lights
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment