2023-07-28 20:29:37 -07:00
|
|
|
|
|
|
|
|
2023-10-10 06:46:35 -07:00
|
|
|
########################
|
|
|
|
### Blueprint definition
|
|
|
|
########################
|
|
|
|
|
2023-12-08 17:26:27 -08:00
|
|
|
mode: queued
|
2023-12-08 18:34:22 -08:00
|
|
|
max: 25
|
2023-07-28 20:29:37 -07:00
|
|
|
blueprint:
|
|
|
|
|
2023-12-19 23:34:56 -08:00
|
|
|
name: "Mike's Motion Activated Scenes"
|
|
|
|
description: "Activate scenes based on motion with notice and warning phases, plus an increasing delay when motion is continuously detected."
|
2023-07-28 20:29:37 -07:00
|
|
|
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:
|
2023-11-15 06:01:26 -08:00
|
|
|
domain: binary_sensor
|
2023-11-10 23:18:32 -08:00
|
|
|
# for some reason, using a device_class of motion_sensor ends up hiding the actual motion sensors
|
|
|
|
# device_class: motion_sensor
|
|
|
|
|
2023-07-28 20:29:37 -07:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2023-11-10 23:18:32 -08:00
|
|
|
|
2023-07-28 20:29:37 -07:00
|
|
|
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
|
|
|
|
|
2023-11-10 23:18:32 -08:00
|
|
|
|
2023-11-15 05:00:36 -08:00
|
|
|
delay_seconds_multiplier:
|
|
|
|
name: "Delay seconds multiplier"
|
|
|
|
description: "When the off sequence gets interrupted by new motion, multiply the delay seconds by this number. A decent value might be 2."
|
|
|
|
default: 2.0
|
|
|
|
selector:
|
|
|
|
number:
|
|
|
|
min: 1.0
|
|
|
|
max: 1000.0
|
2023-11-15 05:53:03 -08:00
|
|
|
step: 0.1
|
2023-11-15 05:00:36 -08:00
|
|
|
mode: box
|
|
|
|
|
|
|
|
|
|
|
|
delay_seconds_max:
|
|
|
|
name: "Maximum delay seconds"
|
|
|
|
description: "The maximum delay during no motion before the motion-off sequence begins."
|
|
|
|
default: 3600
|
|
|
|
selector:
|
|
|
|
number:
|
|
|
|
min: 5
|
|
|
|
max: 3000000
|
|
|
|
step: 1
|
|
|
|
mode: box
|
|
|
|
|
|
|
|
|
2023-07-28 20:29:37 -07:00
|
|
|
notice_seconds:
|
2023-10-10 06:46:35 -07:00
|
|
|
name: "Notice seconds"
|
2023-12-08 18:37:24 -08:00
|
|
|
description: "The number of seconds to wait in the Notice scene."
|
2023-07-28 20:29:37 -07:00
|
|
|
default: 15
|
|
|
|
selector:
|
|
|
|
number:
|
|
|
|
min: 1
|
|
|
|
max: 86400
|
|
|
|
step: 1
|
|
|
|
mode: box
|
|
|
|
|
2023-11-10 23:18:32 -08:00
|
|
|
|
2023-07-28 20:29:37 -07:00
|
|
|
warning_seconds:
|
2023-10-10 06:46:35 -07:00
|
|
|
name: "Warning seconds"
|
2023-12-08 18:37:24 -08:00
|
|
|
description: "The number of seconds to wait in the Warning scene."
|
2023-07-28 20:29:37 -07:00
|
|
|
default: 15
|
|
|
|
selector:
|
|
|
|
number:
|
|
|
|
min: 1
|
|
|
|
max: 86400
|
|
|
|
step: 1
|
|
|
|
mode: box
|
|
|
|
|
2023-11-10 23:18:32 -08:00
|
|
|
|
2023-07-28 20:29:37 -07:00
|
|
|
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
|
|
|
|
|
2023-11-10 23:18:32 -08:00
|
|
|
|
2023-12-08 18:37:24 -08:00
|
|
|
scene_notice:
|
|
|
|
name: "Notice Scene"
|
2023-10-10 06:46:35 -07:00
|
|
|
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
|
|
|
|
|
2023-11-10 23:18:32 -08:00
|
|
|
|
2023-12-08 18:37:24 -08:00
|
|
|
scene_warning:
|
|
|
|
name: "Warning Scene"
|
2023-10-10 06:46:35 -07:00
|
|
|
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
|
|
|
|
|
2023-11-10 23:18:32 -08:00
|
|
|
|
2023-07-28 20:29:37 -07:00
|
|
|
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-12-27 21:59:46 -08:00
|
|
|
scene_repeat_count:
|
|
|
|
name: "Scene repeat/retry count"
|
2023-11-15 05:53:03 -08:00
|
|
|
description: >
|
2023-12-27 22:07:21 -08:00
|
|
|
When activating a scene, try this many times in a row.
|
2023-12-27 21:59:46 -08:00
|
|
|
This is sometimes useful when the network seems buggy or laggy,
|
|
|
|
or for certain lights that fail to correctly apply brightness/color when first turning on.
|
2024-01-02 01:58:22 -08:00
|
|
|
|
2023-11-15 05:53:03 -08:00
|
|
|
default: 1
|
2023-11-10 23:18:32 -08:00
|
|
|
selector:
|
2023-11-15 05:00:36 -08:00
|
|
|
number:
|
|
|
|
min: 1
|
2023-12-27 21:59:46 -08:00
|
|
|
max: 60
|
2023-11-15 05:00:36 -08:00
|
|
|
step: 1
|
|
|
|
mode: box
|
2023-11-10 23:18:32 -08:00
|
|
|
|
|
|
|
|
2023-12-27 21:59:46 -08:00
|
|
|
# on_just_before_off_seconds:
|
|
|
|
# name: "\"On\" just before \"Off\""
|
|
|
|
# description: >
|
|
|
|
# When the "Off" scene is about to be shown, you may wish to quickly show the "On" scene for a number of seconds just before.
|
|
|
|
# This is sometimes helpful to mitigate an issue where the "On" scene doesn't apply all colors and settings correctly from an "Off" state.
|
|
|
|
# Set this to a value greater than 0 to enable.
|
|
|
|
# A value of 0 will disable this feature.
|
|
|
|
# Note that sometimes, a value that is too short (e.g., 1) may also cause issues.
|
|
|
|
#
|
|
|
|
# default: 1
|
|
|
|
# selector:
|
|
|
|
# number:
|
|
|
|
# min: 1
|
|
|
|
# max: 86400
|
|
|
|
# step: 1
|
|
|
|
# mode: box
|
|
|
|
|
|
|
|
|
2023-12-08 17:27:24 -08:00
|
|
|
enabled_helper:
|
|
|
|
name: "Enabled helper"
|
|
|
|
description: >
|
|
|
|
Helper variable that will control whether motion activation is enabled or disabled.
|
2023-12-27 21:59:46 -08:00
|
|
|
This will allow the automation to correctly select the "On" or "Off" scene, based on whether motion is currently detected when disabled.
|
2023-12-08 17:27:24 -08:00
|
|
|
An example would be a "Toggle" helper.
|
|
|
|
default: # Allows no selection
|
|
|
|
selector:
|
|
|
|
entity:
|
|
|
|
domain: input_boolean
|
|
|
|
|
|
|
|
|
2023-12-08 18:34:22 -08:00
|
|
|
disabled_scene:
|
|
|
|
name: "Disabled scene"
|
|
|
|
description: >
|
|
|
|
Choose the scene that will be activated when the "enabled_helper" is set to off.
|
|
|
|
In the "auto" mode, the "on" or "off" scene will be chosen based on whether motion is currently detected.
|
|
|
|
selector:
|
|
|
|
select:
|
|
|
|
options:
|
|
|
|
- "auto"
|
|
|
|
- "on"
|
|
|
|
- "off"
|
|
|
|
- "notice"
|
|
|
|
- "warning"
|
|
|
|
|
|
|
|
|
2023-11-15 05:00:36 -08:00
|
|
|
debug_mode:
|
|
|
|
name: "Debug mode."
|
|
|
|
description: "Enable debug mode, which increases logging."
|
2023-11-15 05:53:03 -08:00
|
|
|
default: false
|
2023-11-15 05:00:36 -08:00
|
|
|
selector:
|
|
|
|
boolean: {}
|
|
|
|
|
2023-11-15 05:53:03 -08:00
|
|
|
|
2023-10-10 06:46:35 -07:00
|
|
|
#############
|
|
|
|
### Variables
|
|
|
|
#############
|
|
|
|
|
2023-07-28 20:29:37 -07:00
|
|
|
variables:
|
|
|
|
|
2023-11-15 05:00:36 -08:00
|
|
|
motion_sensor: !input motion_sensor
|
2023-12-08 17:27:24 -08:00
|
|
|
delay_seconds_helper: !input delay_seconds_helper
|
2023-11-15 05:00:36 -08:00
|
|
|
delay_seconds_default: !input delay_seconds_default
|
|
|
|
delay_seconds_multiplier: !input delay_seconds_multiplier
|
|
|
|
delay_seconds_max: !input delay_seconds_max
|
|
|
|
notice_seconds: !input notice_seconds
|
|
|
|
warning_seconds: !input warning_seconds
|
2023-12-27 21:59:46 -08:00
|
|
|
# on_just_before_off_seconds: !input on_just_before_off_seconds
|
2023-12-08 17:27:24 -08:00
|
|
|
enabled_helper: !input enabled_helper
|
2023-12-08 18:34:22 -08:00
|
|
|
disabled_scene: !input disabled_scene
|
2023-11-15 05:00:36 -08:00
|
|
|
debug_mode: !input debug_mode
|
2023-11-10 23:18:32 -08:00
|
|
|
|
2023-12-27 21:59:46 -08:00
|
|
|
scene_repeat_count: !input scene_repeat_count
|
2023-07-28 20:29:37 -07:00
|
|
|
|
2023-12-08 17:27:24 -08:00
|
|
|
trigger_variables:
|
|
|
|
enabled_helper: !input enabled_helper
|
|
|
|
|
|
|
|
|
2023-10-10 06:46:35 -07:00
|
|
|
############
|
|
|
|
### Triggers
|
|
|
|
############
|
|
|
|
|
2023-07-28 20:29:37 -07:00
|
|
|
trigger:
|
|
|
|
|
|
|
|
- platform: state
|
2023-12-08 17:27:24 -08:00
|
|
|
id: Motion changed
|
2023-07-28 20:29:37 -07:00
|
|
|
entity_id:
|
|
|
|
- !input motion_sensor
|
|
|
|
to:
|
|
|
|
- "on"
|
|
|
|
- "off"
|
|
|
|
|
2023-12-08 17:27:24 -08:00
|
|
|
- platform: template
|
|
|
|
id: "Enabled helper is on"
|
|
|
|
value_template: "{{ (enabled_helper != None) and is_state( enabled_helper, 'on' ) }}"
|
|
|
|
|
|
|
|
- platform: template
|
|
|
|
id: "Enabled helper is off"
|
|
|
|
value_template: "{{ (enabled_helper != None) and is_state( enabled_helper, 'off' ) }}"
|
|
|
|
|
|
|
|
|
2023-10-10 06:46:35 -07:00
|
|
|
###########
|
|
|
|
### Actions
|
|
|
|
###########
|
|
|
|
|
2023-07-28 20:29:37 -07:00
|
|
|
action:
|
|
|
|
|
2023-12-08 18:34:22 -08:00
|
|
|
# Action #0
|
2023-12-27 21:09:03 -08:00
|
|
|
- alias: "Initial debug logging"
|
2023-12-08 17:27:24 -08:00
|
|
|
if:
|
|
|
|
- condition: template
|
2023-12-08 18:34:22 -08:00
|
|
|
value_template: "{{ debug_mode == true }}"
|
2023-12-08 17:27:24 -08:00
|
|
|
then:
|
2023-12-27 21:09:03 -08:00
|
|
|
|
|
|
|
- alias: "Debug log whether the enabled_helper was set"
|
|
|
|
if:
|
|
|
|
- condition: template
|
|
|
|
value_template: "{{ not enabled_helper == None }}"
|
2023-12-08 17:27:24 -08:00
|
|
|
then:
|
|
|
|
- service: logbook.log
|
|
|
|
data:
|
|
|
|
name: "Enabled helper"
|
|
|
|
message: "Enabled helper is: {{ enabled_helper }}"
|
|
|
|
else:
|
|
|
|
- service: logbook.log
|
|
|
|
data:
|
|
|
|
name: "Enabled helper"
|
|
|
|
message: "Enabled helper is not set."
|
|
|
|
|
2023-12-27 21:09:03 -08:00
|
|
|
- alias: "Debug log the enabled_helper name"
|
|
|
|
service: logbook.log
|
2023-12-08 17:27:24 -08:00
|
|
|
data:
|
|
|
|
name: "Enabled helper"
|
|
|
|
message: "Enabled helper name is: {{ enabled_helper }}"
|
|
|
|
|
2023-12-27 21:09:03 -08:00
|
|
|
- alias: "Debug log the current delay_seconds value"
|
|
|
|
service: logbook.log
|
2023-12-08 17:27:24 -08:00
|
|
|
data:
|
|
|
|
name: "Delay seconds"
|
|
|
|
message: "Delay seconds is: {{ states[delay_seconds_helper].state }}"
|
2023-07-28 20:29:37 -07:00
|
|
|
|
2023-12-27 21:59:46 -08:00
|
|
|
# - alias: "Debug log the on_just_before_off_seconds value"
|
|
|
|
# service: logbook.log
|
|
|
|
# data:
|
|
|
|
# name: "Debug: On just before off seconds"
|
|
|
|
# message: "On just before off is: {{ on_just_before_off_seconds }} "
|
2023-12-08 17:27:24 -08:00
|
|
|
|
|
|
|
# Take actions based on whether the "Enabled helper" was just toggled on or off
|
2023-12-27 21:09:03 -08:00
|
|
|
# Action #1
|
2023-07-28 20:29:37 -07:00
|
|
|
- if:
|
2023-12-08 17:27:24 -08:00
|
|
|
- condition: trigger
|
|
|
|
id:
|
|
|
|
- Enabled helper is on
|
|
|
|
- Enabled helper is off
|
|
|
|
then:
|
2023-12-19 23:33:39 -08:00
|
|
|
|
2023-12-08 17:27:24 -08:00
|
|
|
# Debug log
|
2023-12-27 21:59:46 -08:00
|
|
|
- if:
|
|
|
|
- condition: template
|
|
|
|
value_template: "{{ debug_mode == true }}"
|
2023-12-08 17:27:24 -08:00
|
|
|
then:
|
2023-12-27 21:59:46 -08:00
|
|
|
- alias: "Debug log that the enabled helper is toggled"
|
|
|
|
service: logbook.log
|
2023-12-08 17:27:24 -08:00
|
|
|
data:
|
|
|
|
name: "Debug: Trigger"
|
|
|
|
message: "Enabled helper was toggled, and has triggered this automation"
|
2023-12-27 21:59:46 -08:00
|
|
|
- alias: "Debug log the disabled scene"
|
|
|
|
service: logbook.log
|
2023-12-08 18:34:22 -08:00
|
|
|
data:
|
|
|
|
name: "Debug: Disabled scene"
|
|
|
|
message: "Disabled scene is currently set to: {{ disabled_scene }}"
|
|
|
|
|
2024-01-02 01:58:22 -08:00
|
|
|
# If the enabled helper is OFF, we should start by resetting
|
|
|
|
# the countdown timer to default
|
|
|
|
- alias: "Reset countdown timer when enabled helper is switched OFF."
|
|
|
|
service: input_number.set_value
|
|
|
|
data:
|
|
|
|
entity_id: !input delay_seconds_helper
|
|
|
|
value: "{{ delay_seconds_default }}"
|
|
|
|
|
2023-12-08 18:34:22 -08:00
|
|
|
# In "auto" mode, activate the ON or OFF scene based on whether motion is currently detected
|
|
|
|
# Also use "auto" mode if motion activation is ENABLED.
|
|
|
|
- alias: "auto mode: Activate ON scene, if motion is currently detected, otherwise activate the OFF scene"
|
|
|
|
if:
|
|
|
|
- condition: template
|
2023-12-19 23:33:39 -08:00
|
|
|
value_template: "{{ disabled_scene == 'auto' or (enabled_helper != None and is_state( enabled_helper, 'on' )) }}"
|
2023-12-08 18:34:22 -08:00
|
|
|
then:
|
|
|
|
- if:
|
|
|
|
- condition: state
|
|
|
|
entity_id: !input motion_sensor
|
|
|
|
state: "on"
|
|
|
|
then:
|
2023-12-27 20:59:20 -08:00
|
|
|
- alias: "Activate the ON scene"
|
|
|
|
service: scene.turn_on
|
|
|
|
target:
|
|
|
|
entity_id: !input scene_on
|
2023-12-08 18:34:22 -08:00
|
|
|
else:
|
2023-12-27 20:59:20 -08:00
|
|
|
- alias: "Activate the OFF scene"
|
|
|
|
service: scene.turn_on
|
|
|
|
target:
|
|
|
|
entity_id: !input scene_off
|
2023-12-08 18:34:22 -08:00
|
|
|
- stop: ""
|
|
|
|
|
|
|
|
# In ON mode, just activate the ON scene
|
|
|
|
- alias: "on mode: just activate the ON scene"
|
2023-12-08 17:27:24 -08:00
|
|
|
if:
|
2023-12-08 18:34:22 -08:00
|
|
|
- condition: template
|
|
|
|
value_template: "{{ disabled_scene == 'on' }}"
|
2023-12-08 17:27:24 -08:00
|
|
|
then:
|
2023-12-27 21:59:46 -08:00
|
|
|
- repeat:
|
|
|
|
count: "{{ scene_repeat_count }}"
|
|
|
|
sequence:
|
|
|
|
- service: scene.turn_on
|
|
|
|
target:
|
|
|
|
entity_id: !input scene_on
|
|
|
|
- delay:
|
2023-12-27 22:07:21 -08:00
|
|
|
milliseconds: 500
|
2023-12-08 18:34:22 -08:00
|
|
|
- stop: ""
|
|
|
|
|
2023-12-27 21:59:46 -08:00
|
|
|
# In OFF mode, just activate the OFF scene
|
2023-12-08 18:34:22 -08:00
|
|
|
- alias: "off mode: just activate the ON scene"
|
|
|
|
if:
|
|
|
|
- condition: template
|
|
|
|
value_template: "{{ disabled_scene == 'off' }}"
|
|
|
|
then:
|
2023-12-27 21:59:46 -08:00
|
|
|
- repeat:
|
|
|
|
count: "{{ scene_repeat_count }}"
|
|
|
|
sequence:
|
|
|
|
- service: scene.turn_on
|
|
|
|
target:
|
|
|
|
entity_id: !input scene_off
|
|
|
|
- delay:
|
2023-12-27 22:07:21 -08:00
|
|
|
milliseconds: 500
|
2023-12-08 18:34:22 -08:00
|
|
|
- stop: ""
|
|
|
|
|
|
|
|
# In notice mode, just activate the NOTICE scene
|
|
|
|
- alias: "notice mode: just activate the NOTICE scene"
|
|
|
|
if:
|
|
|
|
- condition: template
|
|
|
|
value_template: "{{ disabled_scene == 'notice' }}"
|
|
|
|
then:
|
2023-12-27 21:59:46 -08:00
|
|
|
- repeat:
|
|
|
|
count: "{{ scene_repeat_count }}"
|
|
|
|
sequence:
|
|
|
|
- service: scene.turn_on
|
|
|
|
target:
|
|
|
|
entity_id: !input scene_notice
|
|
|
|
- delay:
|
2023-12-27 22:07:21 -08:00
|
|
|
milliseconds: 500
|
2023-12-08 18:34:22 -08:00
|
|
|
- stop: ""
|
|
|
|
|
|
|
|
# In warning mode, just activate the WARNING scene
|
|
|
|
- alias: "warning mode: just activate the WARNING scene"
|
|
|
|
if:
|
|
|
|
- condition: template
|
|
|
|
value_template: "{{ disabled_scene == 'warning' }}"
|
|
|
|
then:
|
2023-12-27 21:59:46 -08:00
|
|
|
- repeat:
|
|
|
|
count: "{{ scene_repeat_count }}"
|
|
|
|
sequence:
|
|
|
|
- service: scene.turn_on
|
|
|
|
target:
|
|
|
|
entity_id: !input scene_warning
|
|
|
|
- delay:
|
2023-12-27 22:07:21 -08:00
|
|
|
milliseconds: 500
|
2023-12-08 18:34:22 -08:00
|
|
|
- stop: ""
|
|
|
|
|
|
|
|
# Don't do anything after processing the enabled_helper triggers
|
2023-12-08 17:27:24 -08:00
|
|
|
- stop: "Done handling enabled helper"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Take actions based on whether Motion is detected
|
2023-12-27 21:09:03 -08:00
|
|
|
# Action #2
|
2023-12-08 17:27:24 -08:00
|
|
|
- alias: "Refuse to do anything if the enabled-helper says we're OFF."
|
2023-12-19 23:33:39 -08:00
|
|
|
if:
|
2023-12-08 17:27:24 -08:00
|
|
|
- condition: template
|
|
|
|
value_template: "{{ enabled_helper != None }}"
|
|
|
|
- condition: template
|
|
|
|
value_template: "{{ not is_state( enabled_helper, 'on' ) }}"
|
|
|
|
then:
|
|
|
|
stop: "Refusing to continue because the enabled-helper is OFF."
|
|
|
|
|
|
|
|
- if:
|
|
|
|
- condition: state
|
|
|
|
entity_id: !input motion_sensor
|
|
|
|
state: "on"
|
|
|
|
|
2023-07-28 20:29:37 -07:00
|
|
|
|
2023-12-08 17:27:24 -08:00
|
|
|
# Motion is detected
|
2023-07-28 20:29:37 -07:00
|
|
|
then:
|
|
|
|
|
2023-12-08 18:34:22 -08:00
|
|
|
- alias: "Debug Log that motion was detected."
|
|
|
|
if:
|
|
|
|
- condition: template
|
|
|
|
value_template: "{{ debug_mode == true }}"
|
|
|
|
then:
|
|
|
|
service: logbook.log
|
|
|
|
data:
|
|
|
|
name: "Motion On"
|
|
|
|
message: "Motion was detected."
|
2023-07-28 20:29:37 -07:00
|
|
|
|
2023-12-27 20:59:20 -08:00
|
|
|
- alias: "Activate the ON scene"
|
2023-12-27 21:59:46 -08:00
|
|
|
repeat:
|
|
|
|
count: "{{ scene_repeat_count }}"
|
|
|
|
sequence:
|
|
|
|
- service: scene.turn_on
|
|
|
|
target:
|
|
|
|
entity_id: !input scene_on
|
|
|
|
- delay:
|
2023-12-27 22:07:21 -08:00
|
|
|
milliseconds: 500
|
2023-10-10 06:46:35 -07:00
|
|
|
|
2023-07-28 20:29:37 -07:00
|
|
|
|
2023-12-08 17:27:24 -08:00
|
|
|
# Motion is not detected
|
2023-07-28 20:29:37 -07:00
|
|
|
else:
|
|
|
|
|
2023-12-27 21:59:46 -08:00
|
|
|
# Debug log
|
2023-12-08 18:34:22 -08:00
|
|
|
- alias: "Debug Log that the motion-off sequence will run, due to motion no longer detected."
|
|
|
|
if:
|
|
|
|
- condition: template
|
|
|
|
value_template: "{{ debug_mode == true }}"
|
|
|
|
then:
|
|
|
|
service: logbook.log
|
|
|
|
data:
|
|
|
|
name: "Motion Off"
|
|
|
|
message: "Initiating motion-off sequence, because motion no longer detected."
|
2023-07-28 20:29:37 -07:00
|
|
|
|
2023-11-15 05:00:36 -08:00
|
|
|
# Initial period where nothing happens
|
2023-10-10 06:46:35 -07:00
|
|
|
- alias: "Delay appropriately before doing anything"
|
|
|
|
wait_template: "{{ states[motion_sensor].state == 'on' }}"
|
2023-12-19 23:33:39 -08:00
|
|
|
timeout: "{{ states[delay_seconds_helper].state or (enabled_helper != None and is_state(enabled_helper, 'off') ) }}"
|
|
|
|
|
|
|
|
- alias: "Quit now if the enabled-helper went OFF"
|
|
|
|
if:
|
|
|
|
- condition: template
|
|
|
|
value_template: "{{ enabled_helper != None }}"
|
|
|
|
- condition: template
|
|
|
|
value_template: "{{ is_state( enabled_helper, 'off' ) }}"
|
|
|
|
then:
|
|
|
|
stop: "Quitting early because the enabled-helper went OFF."
|
|
|
|
|
2023-07-28 20:29:37 -07:00
|
|
|
- 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."
|
2023-12-08 18:34:22 -08:00
|
|
|
if:
|
|
|
|
- condition: template
|
|
|
|
value_template: "{{ debug_mode == true }}"
|
|
|
|
then:
|
|
|
|
service: logbook.log
|
|
|
|
data:
|
|
|
|
name: "Motion Off"
|
|
|
|
message: "Finished initial no-motion delay"
|
2023-07-28 20:29:37 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
2023-11-10 23:18:32 -08:00
|
|
|
# Notice period, where the notice scene is shown
|
2023-10-10 06:46:35 -07:00
|
|
|
- alias: "Log that the notice period has begun."
|
2023-12-08 18:34:22 -08:00
|
|
|
if:
|
|
|
|
- condition: template
|
|
|
|
value_template: "{{ debug_mode == true }}"
|
|
|
|
then:
|
|
|
|
service: logbook.log
|
|
|
|
data:
|
|
|
|
name: "Begin notice period"
|
|
|
|
message: "Begin notice period; Waiting while motion is still off."
|
2023-12-27 20:59:20 -08:00
|
|
|
|
|
|
|
- alias: "Activate Scene: Notice"
|
2023-12-27 21:59:46 -08:00
|
|
|
repeat:
|
|
|
|
count: "{{ scene_repeat_count }}"
|
|
|
|
sequence:
|
|
|
|
- service: scene.turn_on
|
|
|
|
target:
|
|
|
|
entity_id: !input scene_notice
|
|
|
|
- delay:
|
2023-12-27 22:07:21 -08:00
|
|
|
milliseconds: 500
|
2023-12-27 20:59:20 -08:00
|
|
|
|
2023-07-28 20:29:37 -07:00
|
|
|
- alias: "Delay during the notice period"
|
2023-12-19 23:33:39 -08:00
|
|
|
wait_template: "{{ states[motion_sensor].state == 'on' or (enabled_helper != None and is_state('enabled_helper', 'off') ) }}"
|
2023-10-10 06:46:35 -07:00
|
|
|
timeout: "{{ notice_seconds }}"
|
2023-12-19 23:33:39 -08:00
|
|
|
|
|
|
|
- alias: "Quit now if the enabled-helper went OFF"
|
|
|
|
if:
|
|
|
|
- condition: template
|
|
|
|
value_template: "{{ enabled_helper != None }}"
|
|
|
|
- condition: template
|
|
|
|
value_template: "{{ is_state( enabled_helper, 'off' ) }}"
|
|
|
|
then:
|
|
|
|
stop: "Quitting early because the enabled-helper went OFF."
|
|
|
|
|
|
|
|
|
2023-07-28 20:29:37 -07:00
|
|
|
- if:
|
|
|
|
- condition: state
|
|
|
|
entity_id: !input motion_sensor
|
|
|
|
state: "on"
|
|
|
|
then:
|
2023-12-27 20:59:20 -08:00
|
|
|
|
|
|
|
- alias: "Activate Scene: On"
|
|
|
|
service: scene.turn_on
|
|
|
|
target:
|
|
|
|
entity_id: !input scene_on
|
|
|
|
|
2023-11-15 05:00:36 -08:00
|
|
|
- alias: "Increase countdown timer when user interrupts the notice period."
|
2023-07-28 20:29:37 -07:00
|
|
|
service: input_number.set_value
|
|
|
|
data:
|
|
|
|
entity_id: !input delay_seconds_helper
|
2023-12-08 17:27:24 -08:00
|
|
|
value: "{{ states[delay_seconds_helper].state | int * delay_seconds_multiplier }}"
|
2023-11-15 05:53:03 -08:00
|
|
|
- alias: "Limit delay seconds to its defined maximum"
|
|
|
|
if:
|
|
|
|
- condition: template
|
2023-12-08 17:27:24 -08:00
|
|
|
value_template: "{{ states[delay_seconds_helper].state | int > delay_seconds_max | int }}"
|
2023-11-15 05:53:03 -08:00
|
|
|
then:
|
|
|
|
- service: input_number.set_value
|
|
|
|
data:
|
|
|
|
entity_id: !input delay_seconds_helper
|
|
|
|
value: "{{ delay_seconds_max | int }}"
|
|
|
|
- if:
|
|
|
|
- condition: template
|
|
|
|
value_template: "{{ debug_mode == true }}"
|
|
|
|
then:
|
|
|
|
- service: logbook.log
|
|
|
|
data:
|
|
|
|
name: "Limiting delay seconds"
|
2023-12-08 17:27:24 -08:00
|
|
|
message: "Delay limited to max: {{ states[delay_seconds_helper].state }}"
|
2023-11-15 05:00:36 -08:00
|
|
|
- alias: "Log new delay"
|
|
|
|
if:
|
|
|
|
- condition: template
|
|
|
|
value_template: "{{ debug_mode == true }}"
|
|
|
|
then:
|
|
|
|
- service: logbook.log
|
|
|
|
data:
|
|
|
|
name: "New delay"
|
2023-12-08 17:27:24 -08:00
|
|
|
message: "New delay is {{ states[delay_seconds_helper].state }} seconds"
|
2023-07-28 20:29:37 -07:00
|
|
|
- stop: "Motion detected during notice period."
|
2023-12-08 18:34:22 -08:00
|
|
|
- if:
|
|
|
|
condition: template
|
|
|
|
value_template: "{{ debug_mode == true }}"
|
|
|
|
then:
|
|
|
|
- service: logbook.log
|
|
|
|
data:
|
|
|
|
name: "Notice period finished."
|
|
|
|
message: "Notice period has finished (motion is still off)."
|
2023-07-28 20:29:37 -07:00
|
|
|
|
2023-11-10 23:18:32 -08:00
|
|
|
|
|
|
|
# Warning period, just before the light turns off. The warning scene is shown.
|
2023-10-10 06:46:35 -07:00
|
|
|
- alias: "Log that the warning period has begun."
|
2023-12-08 18:34:22 -08:00
|
|
|
if:
|
|
|
|
- condition: template
|
|
|
|
value_template: "{{ debug_mode == true }}"
|
|
|
|
then:
|
|
|
|
service: logbook.log
|
|
|
|
data:
|
|
|
|
name: "Begin warning period"
|
|
|
|
message: "Begin warning period; Waiting while motion is still off."
|
2023-12-27 20:59:20 -08:00
|
|
|
|
|
|
|
- alias: "Activate Scene: Warning"
|
2023-12-27 21:59:46 -08:00
|
|
|
repeat:
|
|
|
|
count: "{{ scene_repeat_count }}"
|
|
|
|
sequence:
|
|
|
|
- service: scene.turn_on
|
|
|
|
target:
|
|
|
|
entity_id: !input scene_warning
|
|
|
|
- delay:
|
2023-12-27 22:07:21 -08:00
|
|
|
milliseconds: 500
|
2023-12-27 20:59:20 -08:00
|
|
|
|
2023-07-28 20:29:37 -07:00
|
|
|
- alias: "Delay during the warning period"
|
2023-12-19 23:33:39 -08:00
|
|
|
wait_template: "{{ states[motion_sensor].state == 'on' or (enabled_helper != None and is_state('enabled_helper', 'off') ) }}"
|
2023-10-10 06:46:35 -07:00
|
|
|
timeout: "{{ warning_seconds }}"
|
2023-12-19 23:33:39 -08:00
|
|
|
|
|
|
|
- alias: "Quit now if the enabled-helper went OFF"
|
|
|
|
if:
|
|
|
|
- condition: template
|
|
|
|
value_template: "{{ enabled_helper != None }}"
|
|
|
|
- condition: template
|
|
|
|
value_template: "{{ is_state( enabled_helper, 'off' ) }}"
|
|
|
|
then:
|
|
|
|
stop: "Quitting early because the enabled-helper went OFF."
|
|
|
|
|
2023-07-28 20:29:37 -07:00
|
|
|
- if:
|
|
|
|
- condition: state
|
|
|
|
entity_id: !input motion_sensor
|
|
|
|
state: "on"
|
|
|
|
then:
|
2023-12-27 20:59:20 -08:00
|
|
|
|
|
|
|
- alias: "Activate Scene: On"
|
2023-12-27 21:59:46 -08:00
|
|
|
repeat:
|
|
|
|
count: "{{ scene_repeat_count }}"
|
|
|
|
sequence:
|
|
|
|
- service: scene.turn_on
|
|
|
|
target:
|
|
|
|
entity_id: !input scene_on
|
|
|
|
- delay:
|
2023-12-27 22:07:21 -08:00
|
|
|
milliseconds: 500
|
2023-12-27 20:59:20 -08:00
|
|
|
|
2023-07-28 20:29:37 -07:00
|
|
|
- alias: "Double countdown timer when user interrupts the warning period."
|
|
|
|
service: input_number.set_value
|
|
|
|
data:
|
|
|
|
entity_id: !input delay_seconds_helper
|
2023-12-08 17:27:24 -08:00
|
|
|
value: "{{ states[delay_seconds_helper].state | int * delay_seconds_multiplier }}"
|
2023-12-27 20:59:20 -08:00
|
|
|
|
2023-11-15 05:53:03 -08:00
|
|
|
- alias: "Limit delay seconds to its defined maximum"
|
|
|
|
if:
|
|
|
|
- condition: template
|
2023-12-08 17:27:24 -08:00
|
|
|
value_template: "{{ states[delay_seconds_helper].state | int > delay_seconds_max | int }}"
|
2023-11-15 05:53:03 -08:00
|
|
|
then:
|
|
|
|
- service: input_number.set_value
|
|
|
|
data:
|
|
|
|
entity_id: !input delay_seconds_helper
|
|
|
|
value: "{{ delay_seconds_max | int }}"
|
|
|
|
- if:
|
|
|
|
- condition: template
|
|
|
|
value_template: "{{ debug_mode == true }}"
|
|
|
|
then:
|
|
|
|
- service: logbook.log
|
|
|
|
data:
|
|
|
|
name: "Limiting delay seconds"
|
2023-12-08 17:27:24 -08:00
|
|
|
message: "Delay limited to max: {{ states[delay_seconds_helper].state }}"
|
2023-12-27 20:59:20 -08:00
|
|
|
|
2023-11-15 05:00:36 -08:00
|
|
|
- alias: "Log new delay seconds"
|
|
|
|
if:
|
|
|
|
- condition: template
|
|
|
|
value_template: "{{ debug_mode == true }}"
|
|
|
|
then:
|
|
|
|
- service: logbook.log
|
|
|
|
data:
|
|
|
|
name: "New delay seconds"
|
2023-12-08 17:27:24 -08:00
|
|
|
message: "New delay is {{ states[delay_seconds_helper].state }} seconds."
|
2023-07-28 20:29:37 -07:00
|
|
|
- stop: "Motion detected during the warning period."
|
2023-12-08 18:34:22 -08:00
|
|
|
- if:
|
|
|
|
- condition: template
|
|
|
|
value_template: "{{ debug_mode == true }}"
|
|
|
|
then:
|
|
|
|
- service: logbook.log
|
|
|
|
data:
|
|
|
|
name: "Warning period finished."
|
|
|
|
message: "Warning period has finished and motion is still off."
|
2023-10-10 06:46:35 -07:00
|
|
|
|
2023-07-28 20:29:37 -07:00
|
|
|
|
2023-11-10 23:18:32 -08:00
|
|
|
# Finally, we decide to actually turn off the lights with the "Off" scene.
|
|
|
|
|
|
|
|
# Maybe turn on the "On" scene just before the "Off" scene, if the user enabled this option
|
2023-12-27 21:59:46 -08:00
|
|
|
# - if:
|
|
|
|
# - condition: template
|
|
|
|
# value_template: "{{ on_just_before_off_seconds > 0 }}"
|
|
|
|
# then:
|
|
|
|
# - alias: "Log the number of on-before-off seconds"
|
|
|
|
# if:
|
|
|
|
# - condition: template
|
|
|
|
# value_template: "{{ debug_mode == true }}"
|
|
|
|
# then:
|
|
|
|
# service: logbook.log
|
|
|
|
# data:
|
|
|
|
# name: "On-Before-Off seconds"
|
|
|
|
# message: "Will turn on for {{ on_just_before_off_seconds }} seconds before off."
|
|
|
|
# - service: scene.turn_on
|
|
|
|
# target:
|
|
|
|
# entity_id: !input scene_on
|
|
|
|
# - alias: "Wait a second to set the \"On\" scene."
|
|
|
|
# delay:
|
|
|
|
# seconds: "{{ on_just_before_off_seconds }}"
|
|
|
|
# else:
|
|
|
|
# - if:
|
|
|
|
# - condition: template
|
|
|
|
# value_template: "{{ debug_mode == true }}"
|
|
|
|
# then:
|
|
|
|
# - service: logbook.log
|
|
|
|
# data:
|
|
|
|
# name: "Won't run on-before-off"
|
|
|
|
# message: "Won't run on-before-off because seconds was less than 1"
|
2023-11-10 23:18:32 -08:00
|
|
|
|
2023-12-27 20:59:20 -08:00
|
|
|
- alias: "Activate Scene: Off (Done)"
|
2023-12-27 21:59:46 -08:00
|
|
|
repeat:
|
|
|
|
count: "{{ scene_repeat_count }}"
|
|
|
|
sequence:
|
|
|
|
- service: scene.turn_on
|
|
|
|
target:
|
|
|
|
entity_id: !input scene_off
|
|
|
|
- delay:
|
2023-12-27 22:07:21 -08:00
|
|
|
milliseconds: 500
|
2023-07-28 20:29:37 -07:00
|
|
|
|
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 }}"
|
|
|
|
|
2023-12-08 18:34:22 -08:00
|
|
|
- if:
|
|
|
|
- condition: template
|
|
|
|
value_template: "{{ debug_mode == true }}"
|
|
|
|
then:
|
|
|
|
- service: logbook.log
|
|
|
|
data:
|
|
|
|
name: "Turning off light, due to motion off."
|
|
|
|
message: "Activated off-scene and reset delay."
|
2023-07-28 20:29:37 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|