From 3534adff1972d1500f27de4433026fba83caccc0 Mon Sep 17 00:00:00 2001 From: mike Date: Tue, 19 Dec 2023 23:33:39 -0800 Subject: [PATCH] Upgrade/Fix: Quit motion-off sequences immediately when enabled_helper goes off --- motion-activated-light.yaml | 48 ++++++++++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 6 deletions(-) diff --git a/motion-activated-light.yaml b/motion-activated-light.yaml index 04de4d7..6f4593a 100644 --- a/motion-activated-light.yaml +++ b/motion-activated-light.yaml @@ -260,6 +260,7 @@ action: name: "Enabled helper" message: "Enabled helper name is: {{ enabled_helper }}" + # Action #2 - alias: "Debug log the current delay_seconds value" if: @@ -271,6 +272,7 @@ 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: @@ -291,7 +293,7 @@ action: - Enabled helper is on - Enabled helper is off then: - + # Debug log - alias: "Debug log - Enabled Helper On/Off" if: @@ -318,7 +320,7 @@ action: - 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' ) }}" + value_template: "{{ disabled_scene == 'auto' or (enabled_helper != None and is_state( enabled_helper, 'on' )) }}" then: - if: - condition: state @@ -394,7 +396,7 @@ action: # Take actions based on whether Motion is detected - alias: "Refuse to do anything if the enabled-helper says we're OFF." - if: + if: - condition: template value_template: "{{ enabled_helper != None }}" - condition: template @@ -445,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 @@ -480,8 +492,19 @@ action: target: 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 @@ -550,8 +573,21 @@ action: target: 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