2 Commits

Author SHA1 Message Date
16db7d752b Upgrade: User can now set the "On" scene to run just before the "Off" scene, if they want
(to mitigate color and other settings not reaching lights that are off, for some reason)
2023-11-10 23:18:32 -08:00
f5b49149e9 Switch senes to parallel to avoid lag, probably 2023-10-20 23:51:25 -07:00

View File

@ -17,6 +17,9 @@ blueprint:
selector: selector:
entity: entity:
domain: binary_sensor 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: delay_seconds_helper:
name: "Delay seconds (helper)" name: "Delay seconds (helper)"
@ -25,6 +28,7 @@ blueprint:
entity: entity:
domain: input_number domain: input_number
delay_seconds_default: delay_seconds_default:
name: "Default delay seconds" name: "Default delay seconds"
description: "The default delay before the motion-off sequence begins. Will be used to reset the running delay." description: "The default delay before the motion-off sequence begins. Will be used to reset the running delay."
@ -36,6 +40,7 @@ blueprint:
step: 1 step: 1
mode: box mode: box
notice_seconds: notice_seconds:
name: "Notice seconds" name: "Notice seconds"
description: "The number of seconds to wait in the Prep1 (Notice) scene." description: "The number of seconds to wait in the Prep1 (Notice) scene."
@ -47,6 +52,7 @@ blueprint:
step: 1 step: 1
mode: box mode: box
warning_seconds: warning_seconds:
name: "Warning seconds" name: "Warning seconds"
description: "The number of seconds to wait in the Prep2 (Warning) scene." description: "The number of seconds to wait in the Prep2 (Warning) scene."
@ -58,6 +64,7 @@ blueprint:
step: 1 step: 1
mode: box mode: box
scene_on: scene_on:
name: "On Scene" name: "On Scene"
description: "The scene to activate when motion is detected" description: "The scene to activate when motion is detected"
@ -65,6 +72,7 @@ blueprint:
entity: entity:
domain: scene domain: scene
scene_off_prep_1: scene_off_prep_1:
name: "Off Prep Scene 1 (Notice)" name: "Off Prep Scene 1 (Notice)"
description: "The first scene to activate when motion is no longer detected (notice phase)." description: "The first scene to activate when motion is no longer detected (notice phase)."
@ -72,6 +80,7 @@ blueprint:
entity: entity:
domain: scene domain: scene
scene_off_prep_2: scene_off_prep_2:
name: "Off Prep Scene 2 (Warning)" name: "Off Prep Scene 2 (Warning)"
description: "The second scene to activate when motion is no longer detected (warning phase)." description: "The second scene to activate when motion is no longer detected (warning phase)."
@ -79,6 +88,7 @@ blueprint:
entity: entity:
domain: scene domain: scene
scene_off: scene_off:
name: "Off Scene" name: "Off Scene"
description: "The scene to activate when the user has failed to produce motion, and the light should be considered \"off\"." description: "The scene to activate when the user has failed to produce motion, and the light should be considered \"off\"."
@ -87,17 +97,26 @@ blueprint:
domain: scene domain: scene
on_just_before_off:
name: "Use On scene just before Off scene."
description: "Toggle this to \"on\" if you would like the \"On\" scene to trigger just before the \"Off\" scene. This is sometimes helpful to mitigate an issue where the \"On\" scene doesn't apply all colors and settings correctly from an \"Off\" state."
selector:
boolean: {}
############# #############
### Variables ### Variables
############# #############
variables: variables:
motion_sensor: !input motion_sensor motion_sensor: !input motion_sensor
delay_seconds: !input delay_seconds_helper delay_seconds: !input delay_seconds_helper
delay_seconds_default: !input delay_seconds_default delay_seconds_default: !input delay_seconds_default
notice_seconds: !input notice_seconds notice_seconds: !input notice_seconds
warning_seconds: !input warning_seconds warning_seconds: !input warning_seconds
on_just_before_off: !input on_just_before_off
############ ############
### Triggers ### Triggers
@ -123,6 +142,13 @@ action:
name: "First log" name: "First log"
message: "Motion automation has started. Delay counter is: {{ states[delay_seconds].state }}" message: "Motion automation has started. Delay counter is: {{ states[delay_seconds].state }}"
- alias: "Debug log the on_just_before_off bool"
enabled: false
service: logbook.log
data:
name: "Debug: On just before off?"
message: "On just before off is: {{ on_just_before_off }} "
- if: - if:
- condition: state - condition: state
entity_id: !input motion_sensor entity_id: !input motion_sensor
@ -137,16 +163,11 @@ action:
name: "Motion On" name: "Motion On"
message: "Motion was detected." message: "Motion was detected."
- alias: "Activate the ON scene" - parallel:
service: scene.turn_on - alias: "Activate the ON scene"
target: service: scene.turn_on
entity_id: !input scene_on target:
- delay: entity_id: !input scene_on
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
# Take actions based on Motion being undetected # Take actions based on Motion being undetected
@ -159,6 +180,7 @@ action:
message: "Initiating motion-off sequence, because motion no longer detected." message: "Initiating motion-off sequence, because motion no longer detected."
# Initial period where nothing happens
- alias: "Delay appropriately before doing anything" - alias: "Delay appropriately before doing anything"
wait_template: "{{ states[motion_sensor].state == 'on' }}" wait_template: "{{ states[motion_sensor].state == 'on' }}"
timeout: "{{ states[delay_seconds].state }}" timeout: "{{ states[delay_seconds].state }}"
@ -176,15 +198,17 @@ action:
# Notice period, where the notice scene is shown
- alias: "Log that the notice period has begun." - alias: "Log that the notice period has begun."
service: logbook.log service: logbook.log
data: data:
name: "Begin notice period" name: "Begin notice period"
message: "Begin notice period; Waiting while motion is still off." message: "Begin notice period; Waiting while motion is still off."
- alias: "Activate Scene: Off Prep 1 (Notice)" - parallel:
service: scene.turn_on - alias: "Activate Scene: Off Prep 1 (Notice)"
target: service: scene.turn_on
entity_id: !input scene_off_prep_1 target:
entity_id: !input scene_off_prep_1
- alias: "Delay during the notice period" - alias: "Delay during the notice period"
wait_template: "{{ states[motion_sensor].state == 'on' }}" wait_template: "{{ states[motion_sensor].state == 'on' }}"
timeout: "{{ notice_seconds }}" timeout: "{{ notice_seconds }}"
@ -193,10 +217,11 @@ action:
entity_id: !input motion_sensor entity_id: !input motion_sensor
state: "on" state: "on"
then: then:
- alias: "Activate Scene: On" - parallel:
service: scene.turn_on - alias: "Activate Scene: On"
target: service: scene.turn_on
entity_id: !input scene_on target:
entity_id: !input scene_on
- alias: "Double countdown timer when user interrupts the notice period." - alias: "Double countdown timer when user interrupts the notice period."
service: input_number.set_value service: input_number.set_value
data: data:
@ -208,15 +233,18 @@ action:
name: "Notice period finished." name: "Notice period finished."
message: "Notice period has finished (motion is still off)." 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." - alias: "Log that the warning period has begun."
service: logbook.log service: logbook.log
data: data:
name: "Begin warning period" name: "Begin warning period"
message: "Begin warning period; Waiting while motion is still off." message: "Begin warning period; Waiting while motion is still off."
- alias: "Activate Scene: Off Prep 2 (Warning)" - parallel:
service: scene.turn_on - alias: "Activate Scene: Off Prep 2 (Warning)"
target: service: scene.turn_on
entity_id: !input scene_off_prep_2 target:
entity_id: !input scene_off_prep_2
- alias: "Delay during the warning period" - alias: "Delay during the warning period"
wait_template: "{{ states[motion_sensor].state == 'on' }}" wait_template: "{{ states[motion_sensor].state == 'on' }}"
timeout: "{{ warning_seconds }}" timeout: "{{ warning_seconds }}"
@ -225,10 +253,11 @@ action:
entity_id: !input motion_sensor entity_id: !input motion_sensor
state: "on" state: "on"
then: then:
- alias: "Activate Scene: On" - parallel:
service: scene.turn_on - alias: "Activate Scene: On"
target: service: scene.turn_on
entity_id: !input scene_on target:
entity_id: !input scene_on
- alias: "Double countdown timer when user interrupts the warning period." - alias: "Double countdown timer when user interrupts the warning period."
service: input_number.set_value service: input_number.set_value
data: data:
@ -241,10 +270,31 @@ action:
message: "Warning period has finished and motion is still off." message: "Warning period has finished and motion is still off."
- alias: "Activate Scene: Off (Done)" # Finally, we decide to actually turn off the lights with the "Off" scene.
service: scene.turn_on
target: # Maybe turn on the "On" scene just before the "Off" scene, if the user enabled this option
entity_id: !input scene_off - if:
- condition: template
value_template: "{{ on_just_before_off == true }}"
then:
- alias: "Do a debug log"
enabled: false
service: logbook.log
data:
name: "DEBUG: Will turn on before off?"
message: "Yes, will turn on just before off!"
- service: scene.turn_on
target:
entity_id: !input scene_on
- alias: "Wait a second to set the \"On\" scene."
delay:
seconds: 1
- parallel:
- alias: "Activate Scene: Off (Done)"
service: scene.turn_on
target:
entity_id: !input scene_off
- alias: "Reset countdown timer after turning off lights." - alias: "Reset countdown timer after turning off lights."
service: input_number.set_value service: input_number.set_value