Skip to content

Instantly share code, notes, and snippets.

@garanda21
Last active December 13, 2022 13:07
Show Gist options
  • Save garanda21/39fa86b1d2e107f2ffdd243e32041c52 to your computer and use it in GitHub Desktop.
Save garanda21/39fa86b1d2e107f2ffdd243e32041c52 to your computer and use it in GitHub Desktop.
Turn a light on based on detected motion and turn light off after a delay
blueprint:
name: Motion Light
description: Turn a light on based on detected motion and turn light off after a
delay
domain: automation
input:
motion_sensor:
name: Motion Sensor
description: This sensor will be synchronized with the light.
selector:
entity:
domain: binary_sensor
device_class: motion
multiple: false
target_light:
name: Lights or Switchs
description: The lights or switch to keep in sync.
selector:
target:
entity:
domain:
- light
- switch
delay_off:
name: Delay
description: Time to wait before turn lights off after motion stops detection.
default: 120
selector:
number:
min: 0.0
max: 3600.0
unit_of_measurement: seconds
mode: slider
step: 1.0
source_url: https://gist.github.com/garanda21/39fa86b1d2e107f2ffdd243e32041c52
variables:
lights: !input target_light
trigger:
- platform: state
entity_id: !input motion_sensor
from: 'off'
to: 'on'
id: START
- platform: state
entity_id: !input motion_sensor
from: 'on'
to: 'off'
id: STOP
for: !input delay_off
action:
- choose:
- conditions:
- condition: template
value_template: '{{trigger.id == ''START''}}'
- condition: template
value_template: '{{ expand(lights.entity_id) | selectattr(''state'', ''=='',
''on'') | list | count == 0 }}'
sequence:
- service: homeassistant.turn_on
target: !input target_light
- conditions:
- condition: template
value_template: '{{trigger.id == ''STOP''}}'
sequence:
- service: homeassistant.turn_off
target: !input target_light
mode: single
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment