Skip to content

Instantly share code, notes, and snippets.

@NOX73
Last active January 20, 2026 17:26
Show Gist options
  • Select an option

  • Save NOX73/eea37ff1173d7db5c306c1e6fc4f3bbd to your computer and use it in GitHub Desktop.

Select an option

Save NOX73/eea37ff1173d7db5c306c1e6fc4f3bbd to your computer and use it in GitHub Desktop.
blueprint:
name: Door + Motion Light Timer (40s / 20m after 2 motions / 1h manual, toggle by switch)
description: >
- Door open -> light on + 40s (motion refreshes).
- Door closed -> count motions; after N motions -> 20m (motion refreshes).
- Manual switch ANY change -> toggle light:
if light becomes ON -> manual mode 1h (motion refreshes)
if light becomes OFF -> reset + cancel timer
- Timer finished -> light off + reset.
domain: automation
input:
door_sensor:
name: Door sensor (binary_sensor)
selector:
entity:
domain: binary_sensor
motion_sensor:
name: Motion sensor (binary_sensor)
selector:
entity:
domain: binary_sensor
target_light:
name: Target light (single light entity)
selector:
entity:
domain: light
manual_switch:
name: Manual switch trigger (switch/light/binary_sensor)
description: >
Any state change will toggle the target light.
Use a wall switch entity, or a binary_sensor from a button/controller.
selector:
entity:
domain:
- switch
- light
- binary_sensor
helper_timer:
name: Helper Timer (auto-off)
selector:
entity:
domain: timer
helper_counter:
name: Helper Counter (motions while door closed)
selector:
entity:
domain: counter
helper_manual_mode:
name: Helper Input Boolean (manual mode flag)
selector:
entity:
domain: input_boolean
short_duration:
name: Short duration
default:
hours: 0
minutes: 0
seconds: 40
selector:
duration: {}
long_duration:
name: Long duration (door closed after N motions)
default:
hours: 0
minutes: 20
seconds: 0
selector:
duration: {}
manual_duration:
name: Manual duration
default:
hours: 1
minutes: 0
seconds: 0
selector:
duration: {}
motions_to_long:
name: Motions to switch into long duration
default: 2
selector:
number:
min: 1
max: 10
step: 1
mode: slider
mode: restart
max_exceeded: silent
trigger:
- platform: state
entity_id: !input manual_switch
id: manual_toggle
- platform: state
entity_id: !input door_sensor
to: "on"
id: door_open
- platform: state
entity_id: !input motion_sensor
to: "on"
id: motion
- platform: state
entity_id: !input target_light
to: "off"
id: light_off
- platform: event
event_type: timer.finished
event_data:
entity_id: !input helper_timer
id: timer_finished
variables:
short_dur: !input short_duration
long_dur: !input long_duration
manual_dur: !input manual_duration
to_long: !input motions_to_long
counter_entity: !input helper_counter
action:
- choose:
# 0) Manual switch toggled: ALWAYS toggle light, then set/cancel manual mode based on resulting state
- conditions:
- condition: trigger
id: manual_toggle
sequence:
- choose:
- conditions:
- condition: state
entity_id: !input target_light
state: "on"
sequence:
# Light is ON -> toggle OFF
- service: timer.cancel
target:
entity_id: !input helper_timer
- service: input_boolean.turn_off
target:
entity_id: !input helper_manual_mode
- service: counter.reset
target:
entity_id: !input helper_counter
- service: light.turn_off
target:
entity_id: !input target_light
default:
# Light is OFF -> toggle ON and start manual 1h
- service: light.turn_on
target:
entity_id: !input target_light
- service: input_boolean.turn_on
target:
entity_id: !input helper_manual_mode
- service: counter.reset
target:
entity_id: !input helper_counter
- service: timer.start
target:
entity_id: !input helper_timer
data:
duration: "{{ manual_dur }}"
# 1) Door opened: reset to short mode (40s), clear manual mode and counter
- conditions:
- condition: trigger
id: door_open
sequence:
- service: input_boolean.turn_off
target:
entity_id: !input helper_manual_mode
- service: counter.reset
target:
entity_id: !input helper_counter
- service: light.turn_on
target:
entity_id: !input target_light
- service: timer.start
target:
entity_id: !input helper_timer
data:
duration: "{{ short_dur }}"
# 2) Motion logic
- conditions:
- condition: trigger
id: motion
sequence:
- choose:
# 2a) If manual mode -> refresh 1 hour
- conditions:
- condition: state
entity_id: !input helper_manual_mode
state: "on"
sequence:
- service: timer.start
target:
entity_id: !input helper_timer
data:
duration: "{{ manual_dur }}"
# 2b) Door open -> short 40s (refresh) and reset counter
- conditions:
- condition: state
entity_id: !input door_sensor
state: "on"
sequence:
- service: counter.reset
target:
entity_id: !input helper_counter
- service: light.turn_on
target:
entity_id: !input target_light
- service: timer.start
target:
entity_id: !input helper_timer
data:
duration: "{{ short_dur }}"
default:
# 2c) Door closed, not manual: count motion, then decide short vs long
- service: counter.increment
target:
entity_id: !input helper_counter
- choose:
- conditions:
- condition: template
value_template: >
{{ states(counter_entity) | int(0) >= (to_long | int(2)) }}
sequence:
- service: light.turn_on
target:
entity_id: !input target_light
- service: timer.start
target:
entity_id: !input helper_timer
data:
duration: "{{ long_dur }}"
default:
- service: light.turn_on
target:
entity_id: !input target_light
- service: timer.start
target:
entity_id: !input helper_timer
data:
duration: "{{ short_dur }}"
# 3) Light turned off manually (e.g. UI): cancel timer and reset modes
- conditions:
- condition: trigger
id: light_off
sequence:
- service: timer.cancel
target:
entity_id: !input helper_timer
- service: input_boolean.turn_off
target:
entity_id: !input helper_manual_mode
- service: counter.reset
target:
entity_id: !input helper_counter
# 4) Timer finished: turn off light and reset modes
- conditions:
- condition: trigger
id: timer_finished
sequence:
- service: light.turn_off
target:
entity_id: !input target_light
- service: input_boolean.turn_off
target:
entity_id: !input helper_manual_mode
- service: counter.reset
target:
entity_id: !input helper_counter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment