Skip to content

Instantly share code, notes, and snippets.

@cobryan05
Last active May 6, 2022 18:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cobryan05/24f19bad93b642b7e0c5f8f1da0515d0 to your computer and use it in GitHub Desktop.
Save cobryan05/24f19bad93b642b7e0c5f8f1da0515d0 to your computer and use it in GitHub Desktop.
Blueprint - Turn off switch when no motion
blueprint:
name: Turn off unoccupied switches
source_url: https://gist.github.com/cobryan05/24f19bad93b642b7e0c5f8f1da0515d0
description: Turn off a switch that has been left on with no motion
domain: automation
input:
motion_entity:
name: Motion Sensor
selector:
entity:
domain: binary_sensor
device_class: motion
switch_entity:
name: Switch
selector:
entity:
domain: switch
wait_time_selector:
name: Stay On Time
description: Time to keep switch on with no motion
default: 30
selector:
number:
min: 1
max: 1440
unit_of_measurement: minutes
grace_period_selector:
name: Grace Period
description: After turning off the switch, turn it back on if motion is detected within grace period
default: 30
selector:
number:
min: 0
max: 1440
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 switch from triggering the sensor)
default: 2
selector:
number:
min: 0
max: 60
unit_of_measurement: seconds
mode: single
trigger:
- platform: state
entity_id: !input switch_entity
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 switch_entity
state: 'on'
for:
minutes: !input wait_time_selector
- condition: state
entity_id: !input motion_entity
state: 'off'
for:
minutes: !input wait_time_selector
action:
- service: switch.turn_off
entity_id: !input switch_entity
- delay:
seconds: !input grace_arm_delay_selector
- wait_for_trigger:
- platform: state
entity_id: !input motion_entity
to: 'on'
- platform: state
entity_id: !input switch_entity
to: 'on'
timeout:
minutes: !input grace_period_selector
continue_on_timeout: false
- service: switch.turn_on
entity_id: !input switch_entity
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment