2023-07-28 20:29:37 -07:00
|
|
|
|
|
|
|
|
2023-10-10 06:46:35 -07:00
|
|
|
########################
|
|
|
|
### Blueprint definition
|
|
|
|
########################
|
|
|
|
|
2023-07-28 20:29:37 -07:00
|
|
|
blueprint:
|
|
|
|
|
|
|
|
name: "Mike's Motion Activated Light"
|
|
|
|
description: "Turn lights on or off based on motion, plus an increasing delay when motion is continuously detected."
|
|
|
|
domain: automation
|
|
|
|
input:
|
|
|
|
|
|
|
|
motion_sensor:
|
2023-10-10 06:46:35 -07:00
|
|
|
name: "Motion Sensor"
|
|
|
|
description: "Entity ID of the motion sensor"
|
2023-07-28 20:29:37 -07:00
|
|
|
selector:
|
|
|
|
entity:
|
|
|
|
domain: binary_sensor
|
|
|
|
|
|
|
|
delay_seconds_helper:
|
2023-10-10 06:46:35 -07:00
|
|
|
name: "Delay seconds (helper)"
|
|
|
|
description: "The delay before the motion-off sequence will be initiated. Must be a helper so it can persist across activations."
|
2023-07-28 20:29:37 -07:00
|
|
|
selector:
|
|
|
|
entity:
|
|
|
|
domain: input_number
|
|
|
|
|
|
|
|
delay_seconds_default:
|
2023-10-10 06:46:35 -07:00
|
|
|
name: "Default delay seconds"
|
|
|
|
description: "The default delay before the motion-off sequence begins. Will be used to reset the running delay."
|
2023-07-28 20:29:37 -07:00
|
|
|
default: 30
|
|
|
|
selector:
|
|
|
|
number:
|
|
|
|
min: 1
|
|
|
|
max: 86400
|
|
|
|
step: 1
|
|
|
|
mode: box
|
|
|
|
|
|
|
|
notice_seconds:
|
2023-10-10 06:46:35 -07:00
|
|
|
name: "Notice seconds"
|
2023-07-28 20:29:37 -07:00
|
|
|
description: "The number of seconds to wait in the Prep1 (Notice) scene."
|
|
|
|
default: 15
|
|
|
|
selector:
|
|
|
|
number:
|
|
|
|
min: 1
|
|
|
|
max: 86400
|
|
|
|
step: 1
|
|
|
|
mode: box
|
|
|
|
|
|
|
|
warning_seconds:
|
2023-10-10 06:46:35 -07:00
|
|
|
name: "Warning seconds"
|
2023-07-28 20:29:37 -07:00
|
|
|
description: "The number of seconds to wait in the Prep2 (Warning) scene."
|
|
|
|
default: 15
|
|
|
|
selector:
|
|
|
|
number:
|
|
|
|
min: 1
|
|
|
|
max: 86400
|
|
|
|
step: 1
|
|
|
|
mode: box
|
|
|
|
|
|
|
|
scene_on:
|
2023-10-10 06:46:35 -07:00
|
|
|
name: "On Scene"
|
|
|
|
description: "The scene to activate when motion is detected"
|
2023-07-28 20:29:37 -07:00
|
|
|
selector:
|
|
|
|
entity:
|
|
|
|
domain: scene
|
|
|
|
|
|
|
|
scene_off_prep_1:
|
2023-10-10 06:46:35 -07:00
|
|
|
name: "Off Prep Scene 1 (Notice)"
|
|
|
|
description: "The first scene to activate when motion is no longer detected (notice phase)."
|
2023-07-28 20:29:37 -07:00
|
|
|
selector:
|
|
|
|
entity:
|
|
|
|
domain: scene
|
|
|
|
|
|
|
|
scene_off_prep_2:
|
2023-10-10 06:46:35 -07:00
|
|
|
name: "Off Prep Scene 2 (Warning)"
|
|
|
|
description: "The second scene to activate when motion is no longer detected (warning phase)."
|
2023-07-28 20:29:37 -07:00
|
|
|
selector:
|
|
|
|
entity:
|
|
|
|
domain: scene
|
|
|
|
|
|
|
|
scene_off:
|
2023-10-10 06:46:35 -07:00
|
|
|
name: "Off Scene"
|
2023-07-28 20:29:37 -07:00
|
|
|
description: "The scene to activate when the user has failed to produce motion, and the light should be considered \"off\"."
|
|
|
|
selector:
|
|
|
|
entity:
|
|
|
|
domain: scene
|
|
|
|
|
2023-10-10 06:46:35 -07:00
|
|
|
|
|
|
|
#############
|
|
|
|
### Variables
|
|
|
|
#############
|
|
|
|
|
2023-07-28 20:29:37 -07:00
|
|
|
variables:
|
|
|
|
|
|
|
|
motion_sensor: !input motion_sensor
|
|
|
|
delay_seconds: !input delay_seconds_helper
|
|
|
|
delay_seconds_default: !input delay_seconds_default
|
|
|
|
notice_seconds: !input notice_seconds
|
|
|
|
warning_seconds: !input warning_seconds
|
|
|
|
|
2023-10-10 06:46:35 -07:00
|
|
|
############
|
|
|
|
### Triggers
|
|
|
|
############
|
|
|
|
|
2023-07-28 20:29:37 -07:00
|
|
|
trigger:
|
|
|
|
|
|
|
|
- platform: state
|
|
|
|
entity_id:
|
|
|
|
- !input motion_sensor
|
|
|
|
to:
|
|
|
|
- "on"
|
|
|
|
- "off"
|
|
|
|
|
2023-10-10 06:46:35 -07:00
|
|
|
###########
|
|
|
|
### Actions
|
|
|
|
###########
|
|
|
|
|
2023-07-28 20:29:37 -07:00
|
|
|
action:
|
|
|
|
|
|
|
|
- service: logbook.log
|
|
|
|
data:
|
2023-10-10 06:46:35 -07:00
|
|
|
name: "First log"
|
|
|
|
message: "Motion automation has started. Delay counter is: {{ states[delay_seconds].state }}"
|
2023-07-28 20:29:37 -07:00
|
|
|
|
|
|
|
- if:
|
|
|
|
- condition: state
|
|
|
|
entity_id: !input motion_sensor
|
|
|
|
state: "on"
|
|
|
|
|
|
|
|
# Take actions based on Motion being detected!
|
|
|
|
then:
|
|
|
|
|
2023-10-10 06:46:35 -07:00
|
|
|
- alias: "Log that motion was detected."
|
2023-07-28 20:29:37 -07:00
|
|
|
service: logbook.log
|
|
|
|
data:
|
2023-10-10 06:46:35 -07:00
|
|
|
name: "Motion On"
|
|
|
|
message: "Motion was detected."
|
2023-07-28 20:29:37 -07:00
|
|
|
|
|
|
|
- alias: "Activate the ON scene"
|
|
|
|
service: scene.turn_on
|
|
|
|
target:
|
|
|
|
entity_id: !input scene_on
|
2023-10-10 06:46:35 -07:00
|
|
|
- delay:
|
|
|
|
seconds: 1
|
|
|
|
- alias: "Activate the ON scene again, after a delay (to help laggy setups)"
|
|
|
|
service: scene.turn_on
|
|
|
|
target:
|
|
|
|
entity_id: !input scene_on
|
|
|
|
|
2023-07-28 20:29:37 -07:00
|
|
|
|
|
|
|
# Take actions based on Motion being undetected
|
|
|
|
else:
|
|
|
|
|
2023-10-10 06:46:35 -07:00
|
|
|
- alias: "Log that the motion-off sequence will run, due to motion no longer detected."
|
2023-07-28 20:29:37 -07:00
|
|
|
service: logbook.log
|
|
|
|
data:
|
2023-10-10 06:46:35 -07:00
|
|
|
name: "Motion Off"
|
|
|
|
message: "Initiating motion-off sequence, because motion no longer detected."
|
2023-07-28 20:29:37 -07:00
|
|
|
|
|
|
|
|
2023-10-10 06:46:35 -07:00
|
|
|
- alias: "Delay appropriately before doing anything"
|
|
|
|
wait_template: "{{ states[motion_sensor].state == 'on' }}"
|
2023-07-28 20:29:37 -07:00
|
|
|
timeout: "{{ states[delay_seconds].state }}"
|
|
|
|
- if:
|
|
|
|
- condition: state
|
|
|
|
entity_id: !input motion_sensor
|
|
|
|
state: "on"
|
|
|
|
then:
|
2023-10-10 06:46:35 -07:00
|
|
|
- stop: "Motion detected again during initial delay."
|
|
|
|
- alias: "Log that the initial delay has finished."
|
|
|
|
service: logbook.log
|
2023-07-28 20:29:37 -07:00
|
|
|
data:
|
2023-10-10 06:46:35 -07:00
|
|
|
name: "Motion Off"
|
|
|
|
message: "Finished initial no-motion delay"
|
2023-07-28 20:29:37 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
2023-10-10 06:46:35 -07:00
|
|
|
- alias: "Log that the notice period has begun."
|
|
|
|
service: logbook.log
|
|
|
|
data:
|
|
|
|
name: "Begin notice period"
|
|
|
|
message: "Begin notice period; Waiting while motion is still off."
|
2023-07-28 20:29:37 -07:00
|
|
|
- alias: "Activate Scene: Off Prep 1 (Notice)"
|
|
|
|
service: scene.turn_on
|
|
|
|
target:
|
|
|
|
entity_id: !input scene_off_prep_1
|
|
|
|
- alias: "Delay during the notice period"
|
2023-10-10 06:46:35 -07:00
|
|
|
wait_template: "{{ states[motion_sensor].state == 'on' }}"
|
|
|
|
timeout: "{{ notice_seconds }}"
|
2023-07-28 20:29:37 -07:00
|
|
|
- if:
|
|
|
|
- condition: state
|
|
|
|
entity_id: !input motion_sensor
|
|
|
|
state: "on"
|
|
|
|
then:
|
|
|
|
- alias: "Activate Scene: On"
|
|
|
|
service: scene.turn_on
|
|
|
|
target:
|
|
|
|
entity_id: !input scene_on
|
|
|
|
- alias: "Double countdown timer when user interrupts the notice period."
|
|
|
|
service: input_number.set_value
|
|
|
|
data:
|
|
|
|
entity_id: !input delay_seconds_helper
|
|
|
|
value: "{{ states[delay_seconds].state | int * 2 }}"
|
|
|
|
- stop: "Motion detected during notice period."
|
|
|
|
- service: logbook.log
|
|
|
|
data:
|
2023-10-10 06:46:35 -07:00
|
|
|
name: "Notice period finished."
|
|
|
|
message: "Notice period has finished (motion is still off)."
|
2023-07-28 20:29:37 -07:00
|
|
|
|
2023-10-10 06:46:35 -07:00
|
|
|
- alias: "Log that the warning period has begun."
|
|
|
|
service: logbook.log
|
|
|
|
data:
|
|
|
|
name: "Begin warning period"
|
|
|
|
message: "Begin warning period; Waiting while motion is still off."
|
2023-07-28 20:29:37 -07:00
|
|
|
- alias: "Activate Scene: Off Prep 2 (Warning)"
|
|
|
|
service: scene.turn_on
|
|
|
|
target:
|
|
|
|
entity_id: !input scene_off_prep_2
|
|
|
|
- alias: "Delay during the warning period"
|
|
|
|
wait_template: "{{ states[motion_sensor].state == 'on' }}"
|
2023-10-10 06:46:35 -07:00
|
|
|
timeout: "{{ warning_seconds }}"
|
2023-07-28 20:29:37 -07:00
|
|
|
- if:
|
|
|
|
- condition: state
|
|
|
|
entity_id: !input motion_sensor
|
|
|
|
state: "on"
|
|
|
|
then:
|
|
|
|
- alias: "Activate Scene: On"
|
|
|
|
service: scene.turn_on
|
|
|
|
target:
|
|
|
|
entity_id: !input scene_on
|
|
|
|
- alias: "Double countdown timer when user interrupts the warning period."
|
|
|
|
service: input_number.set_value
|
|
|
|
data:
|
|
|
|
entity_id: !input delay_seconds_helper
|
|
|
|
value: "{{ states[delay_seconds].state | int * 2 }}"
|
|
|
|
- stop: "Motion detected during the warning period."
|
|
|
|
- service: logbook.log
|
|
|
|
data:
|
2023-10-10 06:46:35 -07:00
|
|
|
name: "Warning period finished."
|
|
|
|
message: "Warning period has finished and motion is still off."
|
|
|
|
|
2023-07-28 20:29:37 -07:00
|
|
|
|
|
|
|
- alias: "Activate Scene: Off (Done)"
|
|
|
|
service: scene.turn_on
|
|
|
|
target:
|
|
|
|
entity_id: !input scene_off
|
|
|
|
|
2023-10-10 06:46:35 -07:00
|
|
|
- alias: "Reset countdown timer after turning off lights."
|
2023-07-28 20:29:37 -07:00
|
|
|
service: input_number.set_value
|
|
|
|
data:
|
|
|
|
entity_id: !input delay_seconds_helper
|
|
|
|
value: "{{ delay_seconds_default }}"
|
|
|
|
|
|
|
|
- service: logbook.log
|
|
|
|
data:
|
2023-10-10 06:46:35 -07:00
|
|
|
name: "Turning off light, due to motion off."
|
|
|
|
message: "Activated off-scene and reset delay."
|
2023-07-28 20:29:37 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|