New feature: Allow optional boolean input helper to enable/disable motion activation, so we can activate proper ON/OFF scene based on motion at the time of enabling/disabling.
(also rename an input variable)
This commit is contained in:
parent
9f143ffb9a
commit
aa187ac3a2
@ -141,6 +141,18 @@ blueprint:
|
|||||||
mode: box
|
mode: box
|
||||||
|
|
||||||
|
|
||||||
|
enabled_helper:
|
||||||
|
name: "Enabled helper"
|
||||||
|
description: >
|
||||||
|
Helper variable that will control whether motion activation is enabled or disabled.
|
||||||
|
This will allow this blueprint to correctly select the "On" or "Off" scene, based on whether motion is currently detected when disabled.
|
||||||
|
An example would be a "Toggle" helper.
|
||||||
|
default: # Allows no selection
|
||||||
|
selector:
|
||||||
|
entity:
|
||||||
|
domain: input_boolean
|
||||||
|
|
||||||
|
|
||||||
debug_mode:
|
debug_mode:
|
||||||
name: "Debug mode."
|
name: "Debug mode."
|
||||||
description: "Enable debug mode, which increases logging."
|
description: "Enable debug mode, which increases logging."
|
||||||
@ -156,16 +168,21 @@ blueprint:
|
|||||||
variables:
|
variables:
|
||||||
|
|
||||||
motion_sensor: !input motion_sensor
|
motion_sensor: !input motion_sensor
|
||||||
delay_seconds: !input delay_seconds_helper
|
delay_seconds_helper: !input delay_seconds_helper
|
||||||
delay_seconds_default: !input delay_seconds_default
|
delay_seconds_default: !input delay_seconds_default
|
||||||
delay_seconds_multiplier: !input delay_seconds_multiplier
|
delay_seconds_multiplier: !input delay_seconds_multiplier
|
||||||
delay_seconds_max: !input delay_seconds_max
|
delay_seconds_max: !input delay_seconds_max
|
||||||
notice_seconds: !input notice_seconds
|
notice_seconds: !input notice_seconds
|
||||||
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
|
||||||
debug_mode: !input debug_mode
|
debug_mode: !input debug_mode
|
||||||
|
|
||||||
|
|
||||||
|
trigger_variables:
|
||||||
|
enabled_helper: !input enabled_helper
|
||||||
|
|
||||||
|
|
||||||
############
|
############
|
||||||
### Triggers
|
### Triggers
|
||||||
############
|
############
|
||||||
@ -173,22 +190,66 @@ variables:
|
|||||||
trigger:
|
trigger:
|
||||||
|
|
||||||
- platform: state
|
- platform: state
|
||||||
|
id: Motion changed
|
||||||
entity_id:
|
entity_id:
|
||||||
- !input motion_sensor
|
- !input motion_sensor
|
||||||
to:
|
to:
|
||||||
- "on"
|
- "on"
|
||||||
- "off"
|
- "off"
|
||||||
|
|
||||||
|
- platform: template
|
||||||
|
id: "Enabled helper is on"
|
||||||
|
value_template: "{{ (enabled_helper != None) and is_state( enabled_helper, 'on' ) }}"
|
||||||
|
|
||||||
|
- platform: template
|
||||||
|
id: "Enabled helper is off"
|
||||||
|
value_template: "{{ (enabled_helper != None) and is_state( enabled_helper, 'off' ) }}"
|
||||||
|
|
||||||
|
|
||||||
###########
|
###########
|
||||||
### Actions
|
### Actions
|
||||||
###########
|
###########
|
||||||
|
|
||||||
action:
|
action:
|
||||||
|
|
||||||
|
- alias: "Debug log whether the enabled_helper was set"
|
||||||
|
if:
|
||||||
|
- condition: template
|
||||||
|
value_template: "{{ debug_mode == true or true }}"
|
||||||
|
then:
|
||||||
|
- if:
|
||||||
|
- condition: template
|
||||||
|
value_template: "{{ not enabled_helper == None }}"
|
||||||
|
then:
|
||||||
- service: logbook.log
|
- service: logbook.log
|
||||||
data:
|
data:
|
||||||
name: "First log"
|
name: "Enabled helper"
|
||||||
message: "Motion automation has started. Delay counter is: {{ states[delay_seconds].state }}"
|
message: "Enabled helper is: {{ enabled_helper }}"
|
||||||
|
else:
|
||||||
|
- service: logbook.log
|
||||||
|
data:
|
||||||
|
name: "Enabled helper"
|
||||||
|
message: "Enabled helper is not set."
|
||||||
|
|
||||||
|
- alias: "Debug log the enabled_helper name"
|
||||||
|
if:
|
||||||
|
- condition: template
|
||||||
|
value_template: "{{ debug_mode == true }}"
|
||||||
|
then:
|
||||||
|
- service: logbook.log
|
||||||
|
data:
|
||||||
|
name: "Enabled helper"
|
||||||
|
message: "Enabled helper name is: {{ enabled_helper }}"
|
||||||
|
|
||||||
|
- alias: "Debug log the current delay_seconds value"
|
||||||
|
if:
|
||||||
|
- condition: template
|
||||||
|
value_template: "{{ debug_mode == true }}"
|
||||||
|
then:
|
||||||
|
- service: logbook.log
|
||||||
|
data:
|
||||||
|
name: "Delay seconds"
|
||||||
|
message: "Delay seconds is: {{ states[delay_seconds_helper].state }}"
|
||||||
|
|
||||||
- alias: "Debug log the on_just_before_off_seconds value"
|
- alias: "Debug log the on_just_before_off_seconds value"
|
||||||
if:
|
if:
|
||||||
@ -200,12 +261,67 @@ action:
|
|||||||
name: "Debug: On just before off seconds"
|
name: "Debug: On just before off seconds"
|
||||||
message: "On just before off is: {{ on_just_before_off_seconds }} "
|
message: "On just before off is: {{ on_just_before_off_seconds }} "
|
||||||
|
|
||||||
|
|
||||||
|
# Take actions based on whether the "Enabled helper" was just toggled on or off
|
||||||
|
- if:
|
||||||
|
- condition: trigger
|
||||||
|
id:
|
||||||
|
- Enabled helper is on
|
||||||
|
- Enabled helper is off
|
||||||
|
then:
|
||||||
|
|
||||||
|
# Debug log
|
||||||
|
- alias: "Debug log"
|
||||||
|
if:
|
||||||
|
- condition: template
|
||||||
|
value_template: "{{ debug_mode == true }}"
|
||||||
|
then:
|
||||||
|
- service: logbook.log
|
||||||
|
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"
|
||||||
|
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: "Done handling enabled helper"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Take actions based on whether Motion is detected
|
||||||
|
- alias: "Refuse to do anything if the enabled-helper says we're OFF."
|
||||||
|
if:
|
||||||
|
- condition: template
|
||||||
|
value_template: "{{ enabled_helper != None }}"
|
||||||
|
- condition: template
|
||||||
|
value_template: "{{ not is_state( enabled_helper, 'on' ) }}"
|
||||||
|
then:
|
||||||
|
stop: "Refusing to continue because the enabled-helper is OFF."
|
||||||
|
|
||||||
- if:
|
- if:
|
||||||
- condition: state
|
- condition: state
|
||||||
entity_id: !input motion_sensor
|
entity_id: !input motion_sensor
|
||||||
state: "on"
|
state: "on"
|
||||||
|
|
||||||
# Take actions based on Motion being detected!
|
|
||||||
|
# Motion is detected
|
||||||
then:
|
then:
|
||||||
|
|
||||||
- alias: "Log that motion was detected."
|
- alias: "Log that motion was detected."
|
||||||
@ -221,7 +337,7 @@ action:
|
|||||||
entity_id: !input scene_on
|
entity_id: !input scene_on
|
||||||
|
|
||||||
|
|
||||||
# Take actions based on Motion being undetected
|
# Motion is not detected
|
||||||
else:
|
else:
|
||||||
|
|
||||||
- alias: "Log that the motion-off sequence will run, due to motion no longer detected."
|
- alias: "Log that the motion-off sequence will run, due to motion no longer detected."
|
||||||
@ -234,7 +350,7 @@ action:
|
|||||||
# Initial period where nothing happens
|
# 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_helper].state }}"
|
||||||
- if:
|
- if:
|
||||||
- condition: state
|
- condition: state
|
||||||
entity_id: !input motion_sensor
|
entity_id: !input motion_sensor
|
||||||
@ -277,11 +393,11 @@ action:
|
|||||||
service: input_number.set_value
|
service: input_number.set_value
|
||||||
data:
|
data:
|
||||||
entity_id: !input delay_seconds_helper
|
entity_id: !input delay_seconds_helper
|
||||||
value: "{{ states[delay_seconds].state | int * delay_seconds_multiplier }}"
|
value: "{{ states[delay_seconds_helper].state | int * delay_seconds_multiplier }}"
|
||||||
- alias: "Limit delay seconds to its defined maximum"
|
- alias: "Limit delay seconds to its defined maximum"
|
||||||
if:
|
if:
|
||||||
- condition: template
|
- condition: template
|
||||||
value_template: "{{ states[delay_seconds].state | int > delay_seconds_max | int }}"
|
value_template: "{{ states[delay_seconds_helper].state | int > delay_seconds_max | int }}"
|
||||||
then:
|
then:
|
||||||
- service: input_number.set_value
|
- service: input_number.set_value
|
||||||
data:
|
data:
|
||||||
@ -294,7 +410,7 @@ action:
|
|||||||
- service: logbook.log
|
- service: logbook.log
|
||||||
data:
|
data:
|
||||||
name: "Limiting delay seconds"
|
name: "Limiting delay seconds"
|
||||||
message: "Delay limited to max: {{ states[delay_seconds].state }}"
|
message: "Delay limited to max: {{ states[delay_seconds_helper].state }}"
|
||||||
- alias: "Log new delay"
|
- alias: "Log new delay"
|
||||||
if:
|
if:
|
||||||
- condition: template
|
- condition: template
|
||||||
@ -303,7 +419,7 @@ action:
|
|||||||
- service: logbook.log
|
- service: logbook.log
|
||||||
data:
|
data:
|
||||||
name: "New delay"
|
name: "New delay"
|
||||||
message: "New delay is {{ states[delay_seconds].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
|
- service: logbook.log
|
||||||
data:
|
data:
|
||||||
@ -339,11 +455,11 @@ action:
|
|||||||
service: input_number.set_value
|
service: input_number.set_value
|
||||||
data:
|
data:
|
||||||
entity_id: !input delay_seconds_helper
|
entity_id: !input delay_seconds_helper
|
||||||
value: "{{ states[delay_seconds].state | int * delay_seconds_multiplier }}"
|
value: "{{ states[delay_seconds_helper].state | int * delay_seconds_multiplier }}"
|
||||||
- alias: "Limit delay seconds to its defined maximum"
|
- alias: "Limit delay seconds to its defined maximum"
|
||||||
if:
|
if:
|
||||||
- condition: template
|
- condition: template
|
||||||
value_template: "{{ states[delay_seconds].state | int > delay_seconds_max | int }}"
|
value_template: "{{ states[delay_seconds_helper].state | int > delay_seconds_max | int }}"
|
||||||
then:
|
then:
|
||||||
- service: input_number.set_value
|
- service: input_number.set_value
|
||||||
data:
|
data:
|
||||||
@ -356,7 +472,7 @@ action:
|
|||||||
- service: logbook.log
|
- service: logbook.log
|
||||||
data:
|
data:
|
||||||
name: "Limiting delay seconds"
|
name: "Limiting delay seconds"
|
||||||
message: "Delay limited to max: {{ states[delay_seconds].state }}"
|
message: "Delay limited to max: {{ states[delay_seconds_helper].state }}"
|
||||||
- alias: "Log new delay seconds"
|
- alias: "Log new delay seconds"
|
||||||
if:
|
if:
|
||||||
- condition: template
|
- condition: template
|
||||||
@ -365,7 +481,7 @@ action:
|
|||||||
- service: logbook.log
|
- service: logbook.log
|
||||||
data:
|
data:
|
||||||
name: "New delay seconds"
|
name: "New delay seconds"
|
||||||
message: "New delay is {{ states[delay_seconds].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
|
- service: logbook.log
|
||||||
data:
|
data:
|
||||||
|
Loading…
Reference in New Issue
Block a user