Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
19e6fbf577 | |||
3534adff19 | |||
0f41bf3f6a | |||
9b9d5a3466 |
@ -5,11 +5,11 @@
|
||||
########################
|
||||
|
||||
mode: queued
|
||||
max: 10
|
||||
max: 25
|
||||
blueprint:
|
||||
|
||||
name: "Mike's Motion Activated Light"
|
||||
description: "Turn lights on or off based on motion, plus an increasing delay when motion is continuously detected."
|
||||
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."
|
||||
domain: automation
|
||||
input:
|
||||
|
||||
@ -69,7 +69,7 @@ blueprint:
|
||||
|
||||
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 Notice scene."
|
||||
default: 15
|
||||
selector:
|
||||
number:
|
||||
@ -81,7 +81,7 @@ blueprint:
|
||||
|
||||
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 Warning scene."
|
||||
default: 15
|
||||
selector:
|
||||
number:
|
||||
@ -99,16 +99,16 @@ blueprint:
|
||||
domain: scene
|
||||
|
||||
|
||||
scene_off_prep_1:
|
||||
name: "Off Prep Scene 1 (Notice)"
|
||||
scene_notice:
|
||||
name: "Notice Scene"
|
||||
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)"
|
||||
scene_warning:
|
||||
name: "Warning Scene"
|
||||
description: "The second scene to activate when motion is no longer detected (warning phase)."
|
||||
selector:
|
||||
entity:
|
||||
@ -153,6 +153,21 @@ blueprint:
|
||||
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:
|
||||
name: "Debug mode."
|
||||
description: "Enable debug mode, which increases logging."
|
||||
@ -176,6 +191,7 @@ variables:
|
||||
warning_seconds: !input warning_seconds
|
||||
on_just_before_off_seconds: !input on_just_before_off_seconds
|
||||
enabled_helper: !input enabled_helper
|
||||
disabled_scene: !input disabled_scene
|
||||
debug_mode: !input debug_mode
|
||||
|
||||
|
||||
@ -212,10 +228,11 @@ trigger:
|
||||
|
||||
action:
|
||||
|
||||
# Action #0
|
||||
- alias: "Debug log whether the enabled_helper was set"
|
||||
if:
|
||||
- condition: template
|
||||
value_template: "{{ debug_mode == true or true }}"
|
||||
value_template: "{{ debug_mode == true }}"
|
||||
then:
|
||||
- if:
|
||||
- condition: template
|
||||
@ -231,6 +248,8 @@ action:
|
||||
name: "Enabled helper"
|
||||
message: "Enabled helper is not set."
|
||||
|
||||
|
||||
# Action #1
|
||||
- alias: "Debug log the enabled_helper name"
|
||||
if:
|
||||
- condition: template
|
||||
@ -241,6 +260,8 @@ action:
|
||||
name: "Enabled helper"
|
||||
message: "Enabled helper name is: {{ enabled_helper }}"
|
||||
|
||||
|
||||
# Action #2
|
||||
- alias: "Debug log the current delay_seconds value"
|
||||
if:
|
||||
- condition: template
|
||||
@ -251,6 +272,8 @@ action:
|
||||
name: "Delay seconds"
|
||||
message: "Delay seconds is: {{ states[delay_seconds_helper].state }}"
|
||||
|
||||
|
||||
# Action #3
|
||||
- alias: "Debug log the on_just_before_off_seconds value"
|
||||
if:
|
||||
- condition: template
|
||||
@ -263,6 +286,7 @@ action:
|
||||
|
||||
|
||||
# Take actions based on whether the "Enabled helper" was just toggled on or off
|
||||
# Action #4
|
||||
- if:
|
||||
- condition: trigger
|
||||
id:
|
||||
@ -271,7 +295,7 @@ action:
|
||||
then:
|
||||
|
||||
# Debug log
|
||||
- alias: "Debug log"
|
||||
- alias: "Debug log - Enabled Helper On/Off"
|
||||
if:
|
||||
- condition: template
|
||||
value_template: "{{ debug_mode == true }}"
|
||||
@ -280,11 +304,25 @@ action:
|
||||
data:
|
||||
name: "Debug: Trigger"
|
||||
message: "Enabled helper was toggled, and has triggered this automation"
|
||||
|
||||
|
||||
# Activate the "On" scene, if motion is currently detected
|
||||
- alias: "Activate ON scene, if motion is currently detected, otherwise activate the OFF scene"
|
||||
- alias: "Debug log - Disabled scene"
|
||||
if:
|
||||
- condition: template
|
||||
value_template: "{{ debug_mode == true }}"
|
||||
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 (enabled_helper != None and is_state( enabled_helper, 'on' )) }}"
|
||||
then:
|
||||
- if:
|
||||
- condition: state
|
||||
entity_id: !input motion_sensor
|
||||
state: "on"
|
||||
@ -300,6 +338,57 @@ action:
|
||||
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:
|
||||
- parallel:
|
||||
- service: scene.turn_on
|
||||
target:
|
||||
entity_id: !input scene_on
|
||||
- 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:
|
||||
- service: scene.turn_on
|
||||
target:
|
||||
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_notice
|
||||
- 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_warning
|
||||
- stop: ""
|
||||
|
||||
# Don't do anything after processing the enabled_helper triggers
|
||||
- stop: "Done handling enabled helper"
|
||||
|
||||
|
||||
@ -324,7 +413,11 @@ action:
|
||||
# Motion is detected
|
||||
then:
|
||||
|
||||
- alias: "Log that motion was detected."
|
||||
- alias: "Debug Log that motion was detected."
|
||||
if:
|
||||
- condition: template
|
||||
value_template: "{{ debug_mode == true }}"
|
||||
then:
|
||||
service: logbook.log
|
||||
data:
|
||||
name: "Motion On"
|
||||
@ -340,7 +433,11 @@ action:
|
||||
# Motion is not detected
|
||||
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."
|
||||
if:
|
||||
- condition: template
|
||||
value_template: "{{ debug_mode == true }}"
|
||||
then:
|
||||
service: logbook.log
|
||||
data:
|
||||
name: "Motion Off"
|
||||
@ -350,7 +447,17 @@ action:
|
||||
# Initial period where nothing happens
|
||||
- alias: "Delay appropriately before doing anything"
|
||||
wait_template: "{{ states[motion_sensor].state == 'on' }}"
|
||||
timeout: "{{ states[delay_seconds_helper].state }}"
|
||||
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."
|
||||
|
||||
- if:
|
||||
- condition: state
|
||||
entity_id: !input motion_sensor
|
||||
@ -358,6 +465,10 @@ action:
|
||||
then:
|
||||
- stop: "Motion detected again during initial delay."
|
||||
- alias: "Log that the initial delay has finished."
|
||||
if:
|
||||
- condition: template
|
||||
value_template: "{{ debug_mode == true }}"
|
||||
then:
|
||||
service: logbook.log
|
||||
data:
|
||||
name: "Motion Off"
|
||||
@ -367,18 +478,33 @@ action:
|
||||
|
||||
# Notice period, where the notice scene is shown
|
||||
- alias: "Log that the notice period has begun."
|
||||
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."
|
||||
- parallel:
|
||||
- alias: "Activate Scene: Off Prep 1 (Notice)"
|
||||
- alias: "Activate Scene: Notice"
|
||||
service: scene.turn_on
|
||||
target:
|
||||
entity_id: !input scene_off_prep_1
|
||||
entity_id: !input scene_notice
|
||||
- alias: "Delay during the notice period"
|
||||
wait_template: "{{ states[motion_sensor].state == 'on' }}"
|
||||
wait_template: "{{ states[motion_sensor].state == 'on' or (enabled_helper != None and is_state('enabled_helper', 'off') ) }}"
|
||||
timeout: "{{ notice_seconds }}"
|
||||
|
||||
- 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."
|
||||
|
||||
|
||||
- if:
|
||||
- condition: state
|
||||
entity_id: !input motion_sensor
|
||||
@ -421,6 +547,10 @@ action:
|
||||
name: "New delay"
|
||||
message: "New delay is {{ states[delay_seconds_helper].state }} seconds"
|
||||
- stop: "Motion detected during notice period."
|
||||
- if:
|
||||
condition: template
|
||||
value_template: "{{ debug_mode == true }}"
|
||||
then:
|
||||
- service: logbook.log
|
||||
data:
|
||||
name: "Notice period finished."
|
||||
@ -429,18 +559,35 @@ action:
|
||||
|
||||
# Warning period, just before the light turns off. The warning scene is shown.
|
||||
- alias: "Log that the warning period has begun."
|
||||
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."
|
||||
- parallel:
|
||||
- alias: "Activate Scene: Off Prep 2 (Warning)"
|
||||
- alias: "Activate Scene: Warning"
|
||||
service: scene.turn_on
|
||||
target:
|
||||
entity_id: !input scene_off_prep_2
|
||||
entity_id: !input scene_warning
|
||||
- alias: "Delay during the warning period"
|
||||
wait_template: "{{ states[motion_sensor].state == 'on' }}"
|
||||
wait_template: "{{ states[motion_sensor].state == 'on' or (enabled_helper != None and is_state('enabled_helper', 'off') ) }}"
|
||||
timeout: "{{ warning_seconds }}"
|
||||
|
||||
|
||||
- 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."
|
||||
|
||||
|
||||
|
||||
- if:
|
||||
- condition: state
|
||||
entity_id: !input motion_sensor
|
||||
@ -483,6 +630,10 @@ action:
|
||||
name: "New delay seconds"
|
||||
message: "New delay is {{ states[delay_seconds_helper].state }} seconds."
|
||||
- stop: "Motion detected during the warning period."
|
||||
- if:
|
||||
- condition: template
|
||||
value_template: "{{ debug_mode == true }}"
|
||||
then:
|
||||
- service: logbook.log
|
||||
data:
|
||||
name: "Warning period finished."
|
||||
@ -533,6 +684,10 @@ action:
|
||||
entity_id: !input delay_seconds_helper
|
||||
value: "{{ delay_seconds_default }}"
|
||||
|
||||
- if:
|
||||
- condition: template
|
||||
value_template: "{{ debug_mode == true }}"
|
||||
then:
|
||||
- service: logbook.log
|
||||
data:
|
||||
name: "Turning off light, due to motion off."
|
||||
|
Reference in New Issue
Block a user