Skip to content

Instantly share code, notes, and snippets.

@spf13
Last active December 5, 2021 05:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spf13/94ab32ed57a765ef83363a428e0a6ab4 to your computer and use it in GitHub Desktop.
Save spf13/94ab32ed57a765ef83363a428e0a6ab4 to your computer and use it in GitHub Desktop.
Turn off light after timeout with no motion
blueprint:
name: Turn off unoccupied lights
source_url: https://gist.github.com/spf13/94ab32ed57a765ef83363a428e0a6ab4
description: Turn off a light that has been left on with no motion
domain: automation
input:
motion_entity:
name: Motion Sensor
selector:
entity:
domain: binary_sensor
device_class: motion
target_light:
name: Light
description: "The lights to turn off"
selector:
target:
entity:
domain: light
wait_time_selector:
name: Stay On Time
description: Time to keep light on with no motion
default: 30
selector:
number:
min: 1
max: 120
unit_of_measurement: minutes
grace_period_selector:
name: Grace Period
description: After turning off the light, turn it back on if motion is detected within grace period
default: 30
selector:
number:
min: 0
max: 120
unit_of_measurement: minutes
grace_arm_delay_selector:
name: Grace Arm Delay Period
description: Delay before starting grace period (to prevent the act of turning off the light from triggering the sensor)
default: 2
selector:
number:
min: 0
max: 60
unit_of_measurement: seconds
mode: single
trigger:
- platform: state
entity_id: !input target_light
to: 'on'
for:
minutes: !input wait_time_selector
- platform: state
entity_id: !input motion_entity
to: 'off'
for:
minutes: !input wait_time_selector
condition:
- condition: state
entity_id: !input target_light
state: 'on'
for:
minutes: !input wait_time_selector
- condition: state
entity_id: !input motion_entity
state: 'off'
for:
minutes: !input wait_time_selector
action:action:
- service: light.turn_off
target: !input target_light
- delay:
seconds: !input grace_arm_delay_selector
- wait_for_trigger:
- platform: state
entity_id: !input motion_entity
to: 'on'
- platform: state
entity_id: !input target_light
to: 'on'
timeout:
minutes: !input grace_period_selector
continue_on_timeout: false
- service: light.turn_on
entity_id: !input target_light
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment