Add ability to select a default scene mode when DISABLED (including all scenes or auto mode, based on motion)

Also tweaked logging and stuff
This commit is contained in:
mike 2023-12-08 18:34:22 -08:00
parent aa187ac3a2
commit 9b9d5a3466

View File

@ -5,7 +5,7 @@
######################## ########################
mode: queued mode: queued
max: 10 max: 25
blueprint: blueprint:
name: "Mike's Motion Activated Light" name: "Mike's Motion Activated Light"
@ -153,6 +153,21 @@ blueprint:
domain: input_boolean domain: input_boolean
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"
debug_mode: debug_mode:
name: "Debug mode." name: "Debug mode."
description: "Enable debug mode, which increases logging." description: "Enable debug mode, which increases logging."
@ -176,6 +191,7 @@ variables:
warning_seconds: !input warning_seconds warning_seconds: !input warning_seconds
on_just_before_off_seconds: !input on_just_before_off_seconds on_just_before_off_seconds: !input on_just_before_off_seconds
enabled_helper: !input enabled_helper enabled_helper: !input enabled_helper
disabled_scene: !input disabled_scene
debug_mode: !input debug_mode debug_mode: !input debug_mode
@ -212,10 +228,11 @@ trigger:
action: action:
# Action #0
- alias: "Debug log whether the enabled_helper was set" - alias: "Debug log whether the enabled_helper was set"
if: if:
- condition: template - condition: template
value_template: "{{ debug_mode == true or true }}" value_template: "{{ debug_mode == true }}"
then: then:
- if: - if:
- condition: template - condition: template
@ -231,6 +248,8 @@ action:
name: "Enabled helper" name: "Enabled helper"
message: "Enabled helper is not set." message: "Enabled helper is not set."
# Action #1
- alias: "Debug log the enabled_helper name" - alias: "Debug log the enabled_helper name"
if: if:
- condition: template - condition: template
@ -241,6 +260,7 @@ action:
name: "Enabled helper" name: "Enabled helper"
message: "Enabled helper name is: {{ enabled_helper }}" message: "Enabled helper name is: {{ enabled_helper }}"
# Action #2
- alias: "Debug log the current delay_seconds value" - alias: "Debug log the current delay_seconds value"
if: if:
- condition: template - condition: template
@ -251,6 +271,7 @@ action:
name: "Delay seconds" name: "Delay seconds"
message: "Delay seconds is: {{ states[delay_seconds_helper].state }}" message: "Delay seconds is: {{ states[delay_seconds_helper].state }}"
# Action #3
- alias: "Debug log the on_just_before_off_seconds value" - alias: "Debug log the on_just_before_off_seconds value"
if: if:
- condition: template - condition: template
@ -263,6 +284,7 @@ action:
# Take actions based on whether the "Enabled helper" was just toggled on or off # Take actions based on whether the "Enabled helper" was just toggled on or off
# Action #4
- if: - if:
- condition: trigger - condition: trigger
id: id:
@ -271,35 +293,100 @@ action:
then: then:
# Debug log # Debug log
- alias: "Debug log" - alias: "Debug log - Enabled Helper On/Off"
if: if:
- condition: template - condition: template
value_template: "{{ debug_mode == true }}" value_template: "{{ debug_mode == true }}"
then: then:
- service: logbook.log - service: logbook.log
data: data:
name: "Debug: Trigger" name: "Debug: Trigger"
message: "Enabled helper was toggled, and has triggered this automation" message: "Enabled helper was toggled, and has triggered this automation"
- alias: "Debug log - Disabled scene"
# Activate the "On" scene, if motion is currently detected
- alias: "Activate ON scene, if motion is currently detected, otherwise activate the OFF scene"
if: if:
- condition: state - condition: template
entity_id: !input motion_sensor value_template: "{{ debug_mode == true }}"
state: "on" then:
- service: logbook.log
data:
name: "Debug: Disabled scene"
message: "Disabled scene is currently set to: {{ disabled_scene }}"
# 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
value_template: "{{ disabled_scene == 'auto' or is_state( enabled_helper, 'on' ) }}"
then:
- if:
- condition: state
entity_id: !input motion_sensor
state: "on"
then:
- parallel:
- alias: "Activate the ON scene"
service: scene.turn_on
target:
entity_id: !input scene_on
else:
- parallel:
- alias: "Activate the OFF scene"
service: scene.turn_on
target:
entity_id: !input scene_off
- stop: ""
# In ON mode, just activate the ON scene
- alias: "on mode: just activate the ON scene"
if:
- condition: template
value_template: "{{ disabled_scene == 'on' }}"
then: then:
- parallel: - parallel:
- alias: "Activate the ON scene" - service: scene.turn_on
service: scene.turn_on
target: target:
entity_id: !input scene_on entity_id: !input scene_on
else: - stop: ""
# In OFF mode, just activate the OF scene
- alias: "off mode: just activate the ON scene"
if:
- condition: template
value_template: "{{ disabled_scene == 'off' }}"
then:
- parallel: - parallel:
- alias: "Activate the OFF scene" - service: scene.turn_on
service: scene.turn_on
target: target:
entity_id: !input scene_off entity_id: !input scene_off
- 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:
- parallel:
- service: scene.turn_on
target:
entity_id: !input scene_off_prep_1
- 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:
- parallel:
- service: scene.turn_on
target:
entity_id: !input scene_off_prep_2
- stop: ""
# Don't do anything after processing the enabled_helper triggers
- stop: "Done handling enabled helper" - stop: "Done handling enabled helper"
@ -324,11 +411,15 @@ action:
# Motion is detected # Motion is detected
then: then:
- alias: "Log that motion was detected." - alias: "Debug Log that motion was detected."
service: logbook.log if:
data: - condition: template
name: "Motion On" value_template: "{{ debug_mode == true }}"
message: "Motion was detected." then:
service: logbook.log
data:
name: "Motion On"
message: "Motion was detected."
- parallel: - parallel:
- alias: "Activate the ON scene" - alias: "Activate the ON scene"
@ -340,11 +431,15 @@ action:
# Motion is not detected # Motion is not detected
else: else:
- alias: "Log that the motion-off sequence will run, due to motion no longer detected." - alias: "Debug Log that the motion-off sequence will run, due to motion no longer detected."
service: logbook.log if:
data: - condition: template
name: "Motion Off" value_template: "{{ debug_mode == true }}"
message: "Initiating motion-off sequence, because motion no longer detected." then:
service: logbook.log
data:
name: "Motion Off"
message: "Initiating motion-off sequence, because motion no longer detected."
# Initial period where nothing happens # Initial period where nothing happens
@ -358,19 +453,27 @@ action:
then: then:
- stop: "Motion detected again during initial delay." - stop: "Motion detected again during initial delay."
- alias: "Log that the initial delay has finished." - alias: "Log that the initial delay has finished."
service: logbook.log if:
data: - condition: template
name: "Motion Off" value_template: "{{ debug_mode == true }}"
message: "Finished initial no-motion delay" then:
service: logbook.log
data:
name: "Motion Off"
message: "Finished initial no-motion delay"
# Notice period, where the notice scene is shown # 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 if:
data: - condition: template
name: "Begin notice period" value_template: "{{ debug_mode == true }}"
message: "Begin notice period; Waiting while motion is still off." then:
service: logbook.log
data:
name: "Begin notice period"
message: "Begin notice period; Waiting while motion is still off."
- parallel: - parallel:
- alias: "Activate Scene: Off Prep 1 (Notice)" - alias: "Activate Scene: Off Prep 1 (Notice)"
service: scene.turn_on service: scene.turn_on
@ -421,18 +524,26 @@ action:
name: "New delay" name: "New delay"
message: "New delay is {{ states[delay_seconds_helper].state }} seconds" message: "New delay is {{ states[delay_seconds_helper].state }} seconds"
- stop: "Motion detected during notice period." - stop: "Motion detected during notice period."
- service: logbook.log - if:
data: condition: template
name: "Notice period finished." value_template: "{{ debug_mode == true }}"
message: "Notice period has finished (motion is still off)." then:
- 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. # 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 if:
data: - condition: template
name: "Begin warning period" value_template: "{{ debug_mode == true }}"
message: "Begin warning period; Waiting while motion is still off." then:
service: logbook.log
data:
name: "Begin warning period"
message: "Begin warning period; Waiting while motion is still off."
- parallel: - parallel:
- alias: "Activate Scene: Off Prep 2 (Warning)" - alias: "Activate Scene: Off Prep 2 (Warning)"
service: scene.turn_on service: scene.turn_on
@ -483,10 +594,14 @@ action:
name: "New delay seconds" name: "New delay seconds"
message: "New delay is {{ states[delay_seconds_helper].state }} seconds." message: "New delay is {{ states[delay_seconds_helper].state }} seconds."
- stop: "Motion detected during the warning period." - stop: "Motion detected during the warning period."
- service: logbook.log - if:
data: - condition: template
name: "Warning period finished." value_template: "{{ debug_mode == true }}"
message: "Warning period has finished and motion is still off." then:
- service: logbook.log
data:
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. # Finally, we decide to actually turn off the lights with the "Off" scene.
@ -533,10 +648,14 @@ action:
entity_id: !input delay_seconds_helper entity_id: !input delay_seconds_helper
value: "{{ delay_seconds_default }}" value: "{{ delay_seconds_default }}"
- service: logbook.log - if:
data: - condition: template
name: "Turning off light, due to motion off." value_template: "{{ debug_mode == true }}"
message: "Activated off-scene and reset delay." then:
- service: logbook.log
data:
name: "Turning off light, due to motion off."
message: "Activated off-scene and reset delay."