From b6466160479a2d6cad7e05761db89dceb6bcaf1a Mon Sep 17 00:00:00 2001 From: Tony Stork Date: Tue, 2 Jan 2024 17:56:40 -0500 Subject: [PATCH] Rework door open alerts, close #185 --- automations.yaml | 100 +++++++++++++++++++++++++++++++++++++++++++ packages/alerts.yaml | 23 +--------- packages/notify.yaml | 14 +++++- 3 files changed, 114 insertions(+), 23 deletions(-) diff --git a/automations.yaml b/automations.yaml index 0169179..97e2f0c 100644 --- a/automations.yaml +++ b/automations.yaml @@ -4417,3 +4417,103 @@ alias: Call tylenol script mode: parallel max: 10 +- id: '1704233489587' + alias: Door Open Alert + description: '' + trigger: + - alias: Front door open + platform: state + entity_id: + - binary_sensor.front_door + from: 'off' + to: 'on' + for: + hours: 0 + minutes: 0 + seconds: 0 + id: front_door + - alias: Back door open + platform: state + entity_id: + - binary_sensor.back_door + from: 'off' + to: 'on' + for: + hours: 0 + minutes: 0 + seconds: 0 + id: back_door + condition: [] + action: + - variables: + sensor: '{{ "binary_sensor." + trigger.id }}' + alias: Set entity ID for the repeat loop + - alias: Repeat loop while triggered door is open + repeat: + sequence: + - alias: Decide announcements and light alerts + if: + - condition: template + value_template: '{{ repeat.first == ''true'' }}' + alias: If this is the first repeat + then: + - alias: Wait 2 minutes, break out if door is closed + wait_for_trigger: + - platform: template + value_template: '{{ is_state(sensor,''off'') }}' + alias: Triggered door closed + timeout: + hours: 0 + minutes: 2 + seconds: 0 + milliseconds: 0 + else: + - parallel: + - if: + - condition: template + value_template: '{{ repeat.index > 2 }}' + alias: If this is the third or higher repeat + then: + - parallel: + - alias: Living Room Lights Alert + service: script.living_room_lights_alert + data: + duration: 10 + type: red + flash: true + - service: script.basement_lights_alert + data: + type: red + duration: 10 + flash: true + alias: Basement Lights Alert + alias: Light alerts + alias: Light alert starts at 3rd repeat + - service: script.status_annc + data: + who: living_room + call_interruption: 1 + call_snark_door_open: 1 + alias: Play announcement + alias: Run announcement and, if applicable, light alerts + - alias: Wait 2 minutes, break out if door is closed + wait_for_trigger: + - platform: template + value_template: '{{ is_state(sensor,''off'') }}' + alias: Triggered door closed + timeout: + hours: 0 + minutes: 1 + seconds: 50 + milliseconds: 0 + while: + - alias: Triggered door is open + condition: template + value_template: '{{ is_state(sensor,''on'') }}' + - alias: Play announcement + service: script.status_annc + data: + who: living_room + call_snark_door_closed: 1 + mode: parallel + max: 5 diff --git a/packages/alerts.yaml b/packages/alerts.yaml index c586c92..ca4b7e7 100644 --- a/packages/alerts.yaml +++ b/packages/alerts.yaml @@ -42,25 +42,4 @@ alert: - tv_notifications - ios_tony - ios_tina - - ios_kallen - -automation: - - id: 5a82b718-3846-452b-9aa4-a183a88c8f29 - alias: Door Open Alert - trigger: - - platform: state - entity_id: - - binary_sensor.front_door - - binary_sensor.back_door - from: 'off' - to: 'on' - for: - hours: 0 - minutes: 2 - seconds: 0 - action: - - service: script.status_annc - data: - who: 'living_room' - call_interruption: 1 - call_snark_door_open: 1 \ No newline at end of file + - ios_kallen \ No newline at end of file diff --git a/packages/notify.yaml b/packages/notify.yaml index 5fe4559..aa43f22 100644 --- a/packages/notify.yaml +++ b/packages/notify.yaml @@ -1759,7 +1759,15 @@ script: 'Can a human be so kind and close it?', 'The air quality in this house has actually improved.', 'Closing the door would improve the security of the house.', - 'Hey. The door was just opened and this is crazy. But now you know. So. Close it maybe.' + 'Hey. The door was just opened and this is crazy. But now you know. So close it maybe.' + ] | random }} + {%- endmacro -%} + + {%- macro snark_door_closed() -%} + {{ [ + 'Thank you for finally closing the door. The outside world is grateful.', + 'The door has been closed. Thank you for paying attention.', + 'You have closed the door. Nerd Home Incorporated thanks you for singlehandedly saving the planet.', ] | random }} {%- endmacro -%} @@ -1919,6 +1927,10 @@ script: {{ snark_door_open() }} {% endif %} + {% if call_snark_door_closed == 1 %} + {{ snark_door_closed () }} + {% endif %} + {% if call_school_pickup_reminder == 1 %} {{ school_pickup_reminder() }} {% endif %}