3 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
045e87fe73 Turn scene on twice to account for laggy networks
Also quoted some things and improved logging a bit.
2023-10-10 06:46:35 -07:00

View File

@ -1,5 +1,9 @@
########################
### Blueprint definition
########################
blueprint:
name: "Mike's Motion Activated Light"
@ -8,22 +12,26 @@ blueprint:
input:
motion_sensor:
name: Motion Sensor
description: Entity ID of the motion sensor
name: "Motion Sensor"
description: "Entity ID of the motion sensor"
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)
description: The delay before the motion-off sequence will be initiated. Must be a helper so it can persist across activations.
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."
selector:
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.
name: "Default delay seconds"
description: "The default delay before the motion-off sequence begins. Will be used to reset the running delay."
default: 30
selector:
number:
@ -32,8 +40,9 @@ blueprint:
step: 1
mode: box
notice_seconds:
name: Notice seconds
name: "Notice seconds"
description: "The number of seconds to wait in the Prep1 (Notice) scene."
default: 15
selector:
@ -43,8 +52,9 @@ blueprint:
step: 1
mode: box
warning_seconds:
name: Warning seconds
name: "Warning seconds"
description: "The number of seconds to wait in the Prep2 (Warning) scene."
default: 15
selector:
@ -54,34 +64,50 @@ blueprint:
step: 1
mode: box
scene_on:
name: On Scene
description: The scene to activate when motion is detected
name: "On Scene"
description: "The scene to activate when motion is detected"
selector:
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).
name: "Off Prep Scene 1 (Notice)"
description: "The first scene to activate when motion is no longer detected (notice phase)."
selector:
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).
name: "Off Prep Scene 2 (Warning)"
description: "The second scene to activate when motion is no longer detected (warning phase)."
selector:
entity:
domain: scene
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\"."
selector:
entity:
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:
motion_sensor: !input motion_sensor
@ -89,6 +115,12 @@ variables:
delay_seconds_default: !input delay_seconds_default
notice_seconds: !input notice_seconds
warning_seconds: !input warning_seconds
on_just_before_off: !input on_just_before_off
############
### Triggers
############
trigger:
@ -99,12 +131,23 @@ trigger:
- "on"
- "off"
###########
### Actions
###########
action:
- service: logbook.log
data:
name: First log
message: "Test Poop Blueprint has started. Motion delay counter is: {{ states[delay_seconds].state }}"
name: "First log"
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:
- condition: state
@ -114,28 +157,31 @@ action:
# Take actions based on Motion being detected!
then:
- alias: Trying to log the motion state
- alias: "Log that motion was detected."
service: logbook.log
data:
name: Motion On
message: Motion Detected
name: "Motion On"
message: "Motion was detected."
- parallel:
- alias: "Activate the ON scene"
service: scene.turn_on
target:
entity_id: !input scene_on
# Take actions based on Motion being undetected
else:
- alias: Announce motion-off sequence
- alias: "Log that the motion-off sequence will run, due to motion no longer detected."
service: logbook.log
data:
name: Motion Off
message: Initiating motion-off sequence.
name: "Motion Off"
message: "Initiating motion-off sequence, because motion no longer detected."
- alias: Delay appropriately before doing anything
# Initial period where nothing happens
- alias: "Delay appropriately before doing anything"
wait_template: "{{ states[motion_sensor].state == 'on' }}"
timeout: "{{ states[delay_seconds].state }}"
- if:
@ -143,14 +189,22 @@ action:
entity_id: !input motion_sensor
state: "on"
then:
- stop: "Motion detected during initial delay."
- service: logbook.log
- stop: "Motion detected again during initial delay."
- alias: "Log that the initial delay has finished."
service: logbook.log
data:
name: Motion Off
message: Finished initial no-motion delay
name: "Motion Off"
message: "Finished initial no-motion delay"
# Notice period, where the notice scene is shown
- 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."
- parallel:
- alias: "Activate Scene: Off Prep 1 (Notice)"
service: scene.turn_on
target:
@ -163,6 +217,7 @@ action:
entity_id: !input motion_sensor
state: "on"
then:
- parallel:
- alias: "Activate Scene: On"
service: scene.turn_on
target:
@ -175,9 +230,17 @@ action:
- stop: "Motion detected during notice period."
- service: logbook.log
data:
name: Motion Off
message: Finished notice delay
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:
name: "Begin warning period"
message: "Begin warning period; Waiting while motion is still off."
- parallel:
- alias: "Activate Scene: Off Prep 2 (Warning)"
service: scene.turn_on
target:
@ -190,6 +253,7 @@ action:
entity_id: !input motion_sensor
state: "on"
then:
- parallel:
- alias: "Activate Scene: On"
service: scene.turn_on
target:
@ -202,15 +266,37 @@ action:
- stop: "Motion detected during the warning period."
- service: logbook.log
data:
name: Motion Off
message: Finished warning delay
name: "Warning period finished."
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 == 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 on lights."
- alias: "Reset countdown timer after turning off lights."
service: input_number.set_value
data:
entity_id: !input delay_seconds_helper
@ -218,8 +304,8 @@ action:
- service: logbook.log
data:
name: Motion Off
message: Activated off-scene and reset delay.
name: "Turning off light, due to motion off."
message: "Activated off-scene and reset delay."