Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
baa226bcab | |||
c059a2773f | |||
acaf3518c2 | |||
c289fce42b | |||
16db7d752b |
@ -17,6 +17,9 @@ blueprint:
|
||||
selector:
|
||||
entity:
|
||||
domain: binary_sensor
|
||||
# for some reason, using a device_class of motion_sensor ends up hiding the actual motion sensors
|
||||
# device_class: motion_sensor
|
||||
|
||||
|
||||
delay_seconds_helper:
|
||||
name: "Delay seconds (helper)"
|
||||
@ -25,6 +28,7 @@ blueprint:
|
||||
entity:
|
||||
domain: input_number
|
||||
|
||||
|
||||
delay_seconds_default:
|
||||
name: "Default delay seconds"
|
||||
description: "The default delay before the motion-off sequence begins. Will be used to reset the running delay."
|
||||
@ -36,6 +40,31 @@ blueprint:
|
||||
step: 1
|
||||
mode: box
|
||||
|
||||
|
||||
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
|
||||
step: 0.1
|
||||
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
|
||||
|
||||
|
||||
notice_seconds:
|
||||
name: "Notice seconds"
|
||||
description: "The number of seconds to wait in the Prep1 (Notice) scene."
|
||||
@ -47,6 +76,7 @@ blueprint:
|
||||
step: 1
|
||||
mode: box
|
||||
|
||||
|
||||
warning_seconds:
|
||||
name: "Warning seconds"
|
||||
description: "The number of seconds to wait in the Prep2 (Warning) scene."
|
||||
@ -58,6 +88,7 @@ blueprint:
|
||||
step: 1
|
||||
mode: box
|
||||
|
||||
|
||||
scene_on:
|
||||
name: "On Scene"
|
||||
description: "The scene to activate when motion is detected"
|
||||
@ -65,6 +96,7 @@ blueprint:
|
||||
entity:
|
||||
domain: scene
|
||||
|
||||
|
||||
scene_off_prep_1:
|
||||
name: "Off Prep Scene 1 (Notice)"
|
||||
description: "The first scene to activate when motion is no longer detected (notice phase)."
|
||||
@ -72,6 +104,7 @@ blueprint:
|
||||
entity:
|
||||
domain: scene
|
||||
|
||||
|
||||
scene_off_prep_2:
|
||||
name: "Off Prep Scene 2 (Warning)"
|
||||
description: "The second scene to activate when motion is no longer detected (warning phase)."
|
||||
@ -79,6 +112,7 @@ blueprint:
|
||||
entity:
|
||||
domain: scene
|
||||
|
||||
|
||||
scene_off:
|
||||
name: "Off Scene"
|
||||
description: "The scene to activate when the user has failed to produce motion, and the light should be considered \"off\"."
|
||||
@ -87,6 +121,32 @@ blueprint:
|
||||
domain: scene
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
||||
debug_mode:
|
||||
name: "Debug mode."
|
||||
description: "Enable debug mode, which increases logging."
|
||||
default: false
|
||||
selector:
|
||||
boolean: {}
|
||||
|
||||
|
||||
#############
|
||||
### Variables
|
||||
#############
|
||||
@ -96,8 +156,13 @@ variables:
|
||||
motion_sensor: !input motion_sensor
|
||||
delay_seconds: !input delay_seconds_helper
|
||||
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
|
||||
on_just_before_off_seconds: !input on_just_before_off_seconds
|
||||
debug_mode: !input debug_mode
|
||||
|
||||
|
||||
############
|
||||
### Triggers
|
||||
@ -123,6 +188,16 @@ action:
|
||||
name: "First log"
|
||||
message: "Motion automation has started. Delay counter is: {{ states[delay_seconds].state }}"
|
||||
|
||||
- alias: "Debug log the on_just_before_off_seconds value"
|
||||
if:
|
||||
- condition: template
|
||||
value_template: "{{ debug_mode == true }}"
|
||||
then:
|
||||
service: logbook.log
|
||||
data:
|
||||
name: "Debug: On just before off seconds"
|
||||
message: "On just before off is: {{ on_just_before_off_seconds }} "
|
||||
|
||||
- if:
|
||||
- condition: state
|
||||
entity_id: !input motion_sensor
|
||||
@ -154,6 +229,7 @@ action:
|
||||
message: "Initiating motion-off sequence, because motion no longer detected."
|
||||
|
||||
|
||||
# Initial period where nothing happens
|
||||
- alias: "Delay appropriately before doing anything"
|
||||
wait_template: "{{ states[motion_sensor].state == 'on' }}"
|
||||
timeout: "{{ states[delay_seconds].state }}"
|
||||
@ -171,6 +247,7 @@ action:
|
||||
|
||||
|
||||
|
||||
# Notice period, where the notice scene is shown
|
||||
- alias: "Log that the notice period has begun."
|
||||
service: logbook.log
|
||||
data:
|
||||
@ -194,17 +271,45 @@ action:
|
||||
service: scene.turn_on
|
||||
target:
|
||||
entity_id: !input scene_on
|
||||
- alias: "Double countdown timer when user interrupts the notice period."
|
||||
- alias: "Increase 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 }}"
|
||||
value: "{{ states[delay_seconds].state | int * delay_seconds_multiplier }}"
|
||||
- alias: "Limit delay seconds to its defined maximum"
|
||||
if:
|
||||
- condition: template
|
||||
value_template: "{{ states[delay_seconds].state | int > delay_seconds_max | int }}"
|
||||
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"
|
||||
message: "Delay limited to max: {{ states[delay_seconds].state }}"
|
||||
- alias: "Log new delay"
|
||||
if:
|
||||
- condition: template
|
||||
value_template: "{{ debug_mode == true }}"
|
||||
then:
|
||||
- service: logbook.log
|
||||
data:
|
||||
name: "New delay"
|
||||
message: "New delay is {{ states[delay_seconds].state }} seconds"
|
||||
- stop: "Motion detected during notice period."
|
||||
- service: logbook.log
|
||||
data:
|
||||
name: "Notice period finished."
|
||||
message: "Notice period has finished (motion is still off)."
|
||||
|
||||
|
||||
# Warning period, just before the light turns off. The warning scene is shown.
|
||||
- alias: "Log that the warning period has begun."
|
||||
service: logbook.log
|
||||
data:
|
||||
@ -232,7 +337,33 @@ action:
|
||||
service: input_number.set_value
|
||||
data:
|
||||
entity_id: !input delay_seconds_helper
|
||||
value: "{{ states[delay_seconds].state | int * 2 }}"
|
||||
value: "{{ states[delay_seconds].state | int * delay_seconds_multiplier }}"
|
||||
- alias: "Limit delay seconds to its defined maximum"
|
||||
if:
|
||||
- condition: template
|
||||
value_template: "{{ states[delay_seconds].state | int > delay_seconds_max | int }}"
|
||||
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"
|
||||
message: "Delay limited to max: {{ states[delay_seconds].state }}"
|
||||
- alias: "Log new delay seconds"
|
||||
if:
|
||||
- condition: template
|
||||
value_template: "{{ debug_mode == true }}"
|
||||
then:
|
||||
- service: logbook.log
|
||||
data:
|
||||
name: "New delay seconds"
|
||||
message: "New delay is {{ states[delay_seconds].state }} seconds."
|
||||
- stop: "Motion detected during the warning period."
|
||||
- service: logbook.log
|
||||
data:
|
||||
@ -240,6 +371,38 @@ action:
|
||||
message: "Warning period has finished and motion is still off."
|
||||
|
||||
|
||||
# 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
|
||||
- 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"
|
||||
|
||||
- parallel:
|
||||
- alias: "Activate Scene: Off (Done)"
|
||||
service: scene.turn_on
|
||||
|
Reference in New Issue
Block a user