Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save np/122ed99b13b4ba3fec5c7c469f5674fd to your computer and use it in GitHub Desktop.
Save np/122ed99b13b4ba3fec5c7c469f5674fd to your computer and use it in GitHub Desktop.
scene-after-n-minutes-after-last-motion-detected
blueprint:
name: Scene after n minutes after last motion detected
domain: automation
input:
motion_entity_group:
name: Motion Sensor
selector:
entity:
domain: binary_sensor
device_class: motion
scene_target:
name: Scene to turn on
description: The scene to turn on when the automation is triggered.
selector:
entity:
domain: scene
no_motion_wait:
name: Wait time
description: Time to leave the light on after last motion is detected.
default: 3
selector:
number:
min: 0.0
max: 60.0
step: 1.0
unit_of_measurement: minutes
mode: slider
no_motion_wait_at_night:
name: Wait time at night
description: Time to leave the light on after last motion is detected at night.
default: 1
selector:
number:
min: 0.0
max: 20.0
step: 1.0
unit_of_measurement: minutes
mode: slider
source_url: https://community.home-assistant.io/t/entity-light-switch-off-after-n-minutes-after-last-motion-detected/360129
mode: restart
max_exceeded: silent
trigger:
- platform: state
entity_id: !input 'scene_target'
to: 'on'
from: 'off'
condition: []
action:
- choose:
- conditions:
- condition: state
entity_id: !input 'motion_entity_group'
state: 'on'
sequence:
- choose:
- conditions:
- condition: time
after: 00:00
before: 06:00
sequence:
- wait_for_trigger:
- platform: state
entity_id: !input 'motion_entity_group'
from: 'on'
to: 'off'
for:
minutes: !input 'no_motion_wait_at_night'
default:
- wait_for_trigger:
- platform: state
entity_id: !input 'motion_entity_group'
from: 'on'
to: 'off'
for:
minutes: !input 'no_motion_wait'
default:
- choose:
- conditions:
- condition: time
after: 00:00
before: 06:00
sequence:
- wait_for_trigger:
- platform: state
entity_id: !input 'motion_entity_group'
from: 'off'
to: 'on'
timeout:
minutes: !input 'no_motion_wait_at_night'
default:
- wait_for_trigger:
- platform: state
entity_id: !input 'motion_entity_group'
from: 'off'
to: 'on'
timeout:
minutes: !input 'no_motion_wait'
- choose:
- conditions:
- condition: state
entity_id: !input 'motion_entity_group'
state: 'on'
sequence:
- choose:
- conditions:
- condition: time
after: 00:00
before: 06:00
sequence:
- wait_for_trigger:
- platform: state
entity_id: !input 'motion_entity_group'
from: 'on'
to: 'off'
for:
minutes: !input 'no_motion_wait_at_night'
default:
- wait_for_trigger:
- platform: state
entity_id: !input 'motion_entity_group'
from: 'on'
to: 'off'
for:
minutes: !input 'no_motion_wait'
default: []
- delay: 00:00:01
- service: homeassistant.turn_on
data: {}
entity_id: !input 'scene_target'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment