From 25c3a5838e285527a95fdaab55f5d3eecf76ff98 Mon Sep 17 00:00:00 2001 From: "J.P. Krauss" Date: Sun, 24 Nov 2024 15:57:58 -0800 Subject: [PATCH] feat: Add ntfy to Security automations --- packages/security/security.yaml | 161 ++++++++++++++++++++++++++++++++ 1 file changed, 161 insertions(+) diff --git a/packages/security/security.yaml b/packages/security/security.yaml index 9f7ca57..510f4b3 100644 --- a/packages/security/security.yaml +++ b/packages/security/security.yaml @@ -328,6 +328,23 @@ automation: person.attributes.friendly_name }} + - service: shell_command.ntfy + data: + topic: security + tags: + - arming + title: Home Security {{ trigger.to_state.state|replace('_', ' ')|title }} + message: > + {% + set person = states.person + |selectattr('attributes.user_id', 'eq', trigger.to_state.context.user_id) + |first|default({'attributes':{'friendly_name':'Automation'}}) + %}Alarm changed to {{ + trigger.to_state.state|replace('_', ' ')|title + }} by {{ + person.attributes.friendly_name + }} + - alias: Reset Alarm Trigger on Disarm trigger: - platform: state @@ -350,6 +367,15 @@ automation: data: message: Alarm triggered by {{ states('input_text.ha_alarm_trigger') }} + - service: shell_command.ntfy + data: + topic: security + tags: + - alarm + title: Home Alarm Triggered + message: Alarm triggered by {{ states('input_text.ha_alarm_trigger') }} + priority: high + - alias: Trigger Alarm on Window or Door Open trigger: - platform: state @@ -570,6 +596,19 @@ automation: title: View Snapshot uri: "https://hass.kraussnet.com/api/frigate/notifications/{{ trigger.payload_json.after.id }}/snapshot.jpg" + - service: shell_command.ntfy + data: + topic: security + tags: + - camera + title: Detection on {{ trigger.payload_json.after.camera|title }} + message: "A {{ trigger.payload_json.after.label }} detected on {{ trigger.payload_json.after.camera|title }} camera" + priority: high + attach: "%ha%/api/frigate/notifications/{{ trigger.payload_json.after.id }}/thumbnail.jpg" + actions: + - "view,View Clip,%ha%/api/frigate/notifications/{{ trigger.payload_json.after.id }}/clip.mp4" + - "view,View Snapshot,%ha%/api/frigate/notifications/{{ trigger.payload_json.after.id }}/snapshot.jpg" + - if: - condition: template value_template: >- @@ -625,6 +664,19 @@ automation: title: View Snapshot uri: "https://hass.kraussnet.com/api/frigate/notifications/{{ event_data['content']['event_id'] }}/snapshot.jpg" + - service: shell_command.ntfy + data: + topic: security + tags: + - doorbell + title: Doorbell + message: Home Doorbell Rang + priority: high + attach: "%ha%/api/frigate/notifications/{{ event_data['content']['event_id'] }}/thumbnail.jpg" + actions: + - "view,View Clip,%ha%/api/frigate/notifications/{{ event_data['content']['event_id'] }}/clip.mp4" + - "view,View Snapshot,%ha%/api/frigate/notifications/{{ event_data['content']['event_id'] }}/snapshot.jpg" + - service: persistent_notification.create data: notification_id: "camera-{{ event_data['content']['event_id'] }}" @@ -639,6 +691,15 @@ automation: title: "Doorbell" message: "Home Doorbell Rang but could not create event: {{ event_data['content']['message'] }}" + - service: shell_command.ntfy + data: + topic: security + tags: + - doorbell + title: Doorbell + message: "Home Doorbell Rang but could not create event: {{ event_data['content']['message'] }}" + priority: high + - alias: Notify that Garage Door is Open when Alarm Arms description: Send a Garage Door Open Notice to Phones trigger: @@ -673,6 +734,19 @@ automation: - action: "{{ action_close }}" title: Close + - alias: Send notice to ntfy + service: shell_command.ntfy + data: + topic: security + tags: + - garage + title: Garage Door Open + message: Garage door is open! It will close in 10 minutes if not ignored. + priority: high + actions: + - 'http,Ignore,%ha%,body={\"action\":\"{{ action_ignore }}\"}' + - 'http,Close,%ha%,body={\"action\":\"{{ action_close }}\"}' + - alias: Wait for action callback wait_for_trigger: - platform: event @@ -681,10 +755,18 @@ automation: # waiting for the specific action avoids accidentally continuing # for another script/automation's notification action action: "{{ action_ignore }}" + - platform: event + event_type: ntfy + event_data: + action: "{{ action_ignore }}" - platform: event event_type: mobile_app_notification_action event_data: action: "{{ action_close }}" + - platform: event + event_type: ntfy + event_data: + action: "{{ action_close }}" - platform: state entity_id: alarm_control_panel.ha_alarm to: disarmed @@ -704,6 +786,19 @@ automation: |selectattr('attributes.user_id', 'eq', wait.trigger.event.context.user_id) |first|default({'attributes':{'friendly_name':'Automation'}}) %}Open garage door ignored by {{ person.attributes.friendly_name }} + - alias: Notify that the event was ignored (ntfy) + shell_command.ntfy + data: + topic: security + tags: + - garage + title: Garage Door Ignored + message: > + {% + set person = states.person + |selectattr('attributes.user_id', 'eq', wait.trigger.event.context.user_id) + |first|default({'attributes':{'friendly_name':'Automation'}}) + %}Open garage door ignored by {{ person.attributes.friendly_name }} - conditions: "{{ wait.remaining > 0 and 'event' in wait.trigger and wait.trigger.event.data.action == action_close }}" sequence: @@ -718,6 +813,14 @@ automation: action: notify.security data: message: "Garage door timeout cancelled because alarm was disarmed" + - alias: Notify that the event was cancelled (ntfy) + shell_command.ntfy + data: + topic: security + tags: + - garage + title: Garage Door Cancelled + message: "Garage door timeout cancelled because alarm was disarmed" - conditions: "{{ not wait.completed }}" sequence: @@ -729,6 +832,14 @@ automation: action: notify.security data: message: "Garage door closing automatically" + - alias: Notify the event timed out (ntfy) + shell_command.ntfy + data: + topic: security + tags: + - garage + title: Garage Door Closing + message: Garage door closing automatically - alias: Notify that Front Door is Unlocked when Alarm Arms description: Send a Front Door Unlocked Notice to Phones @@ -764,6 +875,19 @@ automation: - action: "{{ action_lock }}" title: Lock + - alias: Send notice to ntfy + service: shell_command.ntfy + data: + topic: security + tags: + - front door + title: Front Door Unlocked + message: Front door is unlocked! It will lock in 10 minutes if not ignored. + priority: high + actions: + - 'http,Ignore,%ha%,body={\"action\":\"{{ action_ignore }}\"}' + - 'http,Lock,%ha%,body={\"action\":\"{{ action_lock }}\"}' + - alias: Wait for action callback wait_for_trigger: - platform: event @@ -772,10 +896,18 @@ automation: # waiting for the specific action avoids accidentally continuing # for another script/automation's notification action action: "{{ action_ignore }}" + - platform: event + event_type: ntfy + event_data: + action: "{{ action_ignore }}" - platform: event event_type: mobile_app_notification_action event_data: action: "{{ action_lock }}" + - platform: event + event_type: ntfy + event_data: + action: "{{ action_lock }}" - platform: state entity_id: alarm_control_panel.ha_alarm to: disarmed @@ -795,6 +927,19 @@ automation: |selectattr('attributes.user_id', 'eq', wait.trigger.event.context.user_id) |first|default({'attributes':{'friendly_name':'Automation'}}) %}Unlocked front door ignored by {{ person.attributes.friendly_name }} + - alias: Notify that the event was ignored (ntfy) + shell_command.ntfy + data: + topic: security + tags: + - front door + title: Front Door Ignored + message: > + {% + set person = states.person + |selectattr('attributes.user_id', 'eq', wait.trigger.event.context.user_id) + |first|default({'attributes':{'friendly_name':'Automation'}}) + %}Unlocked front door ignored by {{ person.attributes.friendly_name }} - conditions: "{{ wait.remaining > 0 and 'event' in wait.trigger and wait.trigger.event.data.action == action_lock }}" sequence: @@ -809,6 +954,14 @@ automation: action: notify.security data: message: "Front door timeout cancelled because alarm was disarmed" + - alias: Notify that the event timed out (ntfy) + shell_command.ntfy + data: + topic: security + tags: + - front door + title: Front Door Cancelled + message: Front door timeout cancelled because alarm was disarmed - conditions: "{{ not wait.completed }}" sequence: @@ -820,3 +973,11 @@ automation: action: notify.security data: message: "Front door locking automatically" + - alias: Notify that the event timed out (ntfy) + shell_command.ntfy + data: + topic: security + tags: + - front door + title: Front Door Locking + message: Front door locking automatically