Skip to content

Instantly share code, notes, and snippets.

@lukasjakobi
Last active July 19, 2025 10:54
Show Gist options
  • Save lukasjakobi/2a8c2c7086713bc6e98ca3b273075b1d to your computer and use it in GitHub Desktop.
Save lukasjakobi/2a8c2c7086713bc6e98ca3b273075b1d to your computer and use it in GitHub Desktop.
Home Assistant Motion Sensor Blurprint (by Lukas Jakobi)
blueprint:
name: Time-based Light Scenes with Motion, Blocker, and Sun Elevation
description: >
Dimmt nach Inaktivität erst sanft runter und schaltet dann ab.
Bei neuer Bewegung wird das Licht sofort eingeschaltet, aber nur wenn der Sonnenstand unter dem konfigurierten Wert liegt.
Szenen können abhängig von Tageszeiten festgelegt werden.
Optionaler Blocker verhindert Aktionen.
domain: automation
input:
motion_sensor:
name: Bewegungsmelder
selector:
entity:
domain: binary_sensor
light:
name: Zu steuerndes Licht
selector:
entity:
domain: light
blocker:
name: Automationsblocker
selector:
entity:
domain: input_boolean
no_motion_delay:
name: Dauer ohne Bewegung
default: 00:05:00
selector:
time:
dim_brightness:
name: Zielhelligkeit beim Dimmen (%)
default: 20
selector:
number:
min: 0
max: 100
unit_of_measurement: '%'
dim_transition:
name: Dauer des Dimm-Übergangs (Sekunden)
default: 00:00:30
selector:
time:
off_transition:
name: Dauer des Ausschalt-Übergangs (Sekunden)
default: 00:00:15
selector:
time:
sun_elevation:
name: Sonnenstand-Schwelle
default: 0
selector:
number:
min: -90
max: 90
step: 1
unit_of_measurement: "°"
morning_scene:
name: Morning Scene
selector:
entity:
domain: scene
morning_from:
name: Morning from time
default: "06:00:00"
selector:
time:
day_scene:
name: Day Scene
selector:
entity:
domain: scene
day_from:
name: Day from time
default: "09:00:00"
selector:
time:
evening_scene:
name: Evening Scene
selector:
entity:
domain: scene
evening_from:
name: Evening from time
default: "17:00:00"
selector:
time:
night_scene:
name: Night Scene
selector:
entity:
domain: scene
night_from:
name: Night from time
default: "21:00:00"
selector:
time:
trigger:
- platform: state
id: motion_off
entity_id: !input motion_sensor
to: 'off'
for: !input no_motion_delay
- platform: state
id: motion_on
entity_id: !input motion_sensor
to: 'on'
condition:
- condition: state
entity_id: !input blocker
state: 'on'
action:
- variables:
light_entity: !input light
dim_transition_input: !input dim_transition
off_transition_input: !input off_transition
no_motion_delay_input: !input no_motion_delay
dim_transition_seconds: >
{% set t = strptime(dim_transition_input, '%H:%M:%S') %}
{{ t.hour * 3600 + t.minute * 60 + t.second }}
off_transition_seconds: >
{% set t = strptime(off_transition_input, '%H:%M:%S') %}
{{ t.hour * 3600 + t.minute * 60 + t.second }}
no_motion_delay_seconds: >
{% set t = strptime(no_motion_delay_input, '%H:%M:%S') %}
{{ t.hour * 3600 + t.minute * 60 + t.second }}
- choose:
- conditions:
- condition: template
value_template: >
{{ trigger.id == 'motion_off' and states[light_entity].state == 'on' }}
sequence:
- service: light.turn_on
target:
entity_id: !input light
data:
brightness_pct: !input dim_brightness
transition: "{{ dim_transition_seconds }}"
- delay:
seconds: "{{ off_transition_seconds }}"
- service: light.turn_off
target:
entity_id: !input light
- conditions:
- condition: template
value_template: "{{ trigger.id == 'motion_on' }}"
- condition: numeric_state
entity_id: sun.sun
attribute: elevation
below: !input sun_elevation
sequence:
- choose:
- conditions:
- condition: time
after: !input morning_from
before: !input day_from
sequence:
- service: scene.turn_on
target:
entity_id: !input morning_scene
- conditions:
- condition: time
after: !input day_from
before: !input evening_from
sequence:
- service: scene.turn_on
target:
entity_id: !input day_scene
- conditions:
- condition: time
after: !input evening_from
before: !input night_from
sequence:
- service: scene.turn_on
target:
entity_id: !input evening_scene
- conditions:
- condition: or
conditions:
- condition: time
after: !input night_from
- condition: time
before: !input morning_from
sequence:
- service: scene.turn_on
target:
entity_id: !input night_scene
mode: restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment