From 08816f2b9b0cb84883bd4efa2ea0ab1fc2381529 Mon Sep 17 00:00:00 2001 From: "J.P. Krauss" Date: Sat, 21 Sep 2024 17:10:59 -0700 Subject: [PATCH] fix: Fix garage door close script --- packages/security/security.yaml | 57 ++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 23 deletions(-) diff --git a/packages/security/security.yaml b/packages/security/security.yaml index b45e933..0877b05 100644 --- a/packages/security/security.yaml +++ b/packages/security/security.yaml @@ -641,56 +641,67 @@ automation: entity_id: alarm_control_panel.ha_alarm to: armed_vacation condition: "{{ is_state('binary_sensor.garage_door', 'on') }}" - mode: restart + mode: single action: - - alias: Set up action variables + - alias: Set up variables for action callback variables: - action_close: "{{ 'CLOSE_' ~ context.id }}" action_ignore: "{{ 'IGNORE_' ~ context.id }}" - - - alias: Send the notification with Close/Ignore actions + action_close: "{{ 'CLOSE_' ~ context.id }}" + + - alias: Send notice to devices action: notify.iphone_jp data: - title: Garage Door Left Open - message: > - The garage door is open - close it now? It will automatically - close in 10 minutes. + message: "Garage door is open! It will close in 10 minutes if not ignored." data: actions: - - action: "{{ action_close }}" - title: Close - action: "{{ action_ignore }}" title: Ignore + - action: "{{ action_close }}" + title: Close - - alias: Wait for a response - timeout: - minutes: 10 + - alias: Wait for action callback wait_for_trigger: - platform: event event_type: mobile_app_notification_action event_data: # waiting for the specific action avoids accidentally continuing # for another script/automation's notification action - action: "{{ action_close }}" + action: "{{ action_ignore }}" - platform: event event_type: mobile_app_notification_action event_data: - action: "{{ action_ignore }}" + action: "{{ action_close }}" + timeout: + seconds: "30" - - alias: Handle the action + - alias: Process callback choose: + - conditions: "{{ wait.trigger.event.data.action == action_ignore }}" + sequence: + - alias: Notify that the event was ignored + action: notify.iphone_jp + data: + message: > + {% + set person = states.person + |selectattr('attributes.user_id', 'eq', wait.context.user_id) + |first|default({'attributes':{'friendly_name':'Automation'}}) + %}Open garage door ignored by {{ person.attributes.friendly_name }} + - conditions: "{{ wait.trigger.event.data.action == action_close }}" sequence: - - action: switch.turn_on + - alias: Close garage door + action: switch.turn_on target: entity_id: switch.garage_door_relay_1 - - conditions: "{{ wait.trigger.event.data.action == action_ignore }}" - sequence: [] - # no-op - - conditions: "{{ not wait.completed }}" sequence: - - action: switch.turn_on + - alias: Notify the event timed out + action: notify.iphone_jp + data: + message: "Garage door closing automatically" + - alias: Close garage door + action: switch.turn_on target: entity_id: switch.garage_door_relay_1