Skip to content

Instantly share code, notes, and snippets.

@dandmrantalsllc
Forked from jhallenb/frigate_notification.yaml
Last active November 9, 2021 18:09
Show Gist options
  • Save dandmrantalsllc/dad59005355446ce7238f826d6169aa8 to your computer and use it in GitHub Desktop.
Save dandmrantalsllc/dad59005355446ce7238f826d6169aa8 to your computer and use it in GitHub Desktop.
Frigate Notification Blueprint
blueprint:
name: Frigate Notification With App button
description: |
---------------------------------------------------------------------------------------------------------------------------
## This is a fork of Frigate Mobile App Notification found here
https://gist.github.com/hunterjm/23c1588a9f2b8b9c2a62ffc364e17f8c
All credits to the initial author
---------------------------------------------------------------------------------------------------------------------------
## Changes made
Added a condition entity that must be on for the notification to execute. Can be a binary_sensor or an input_boolean for example.
Added variables for customizing button titles.
Added an "Open App" button (use a app:// type of path, android only)
Added support for custom notification channel
Added support for custom notification update channel (to remove sound when notification is updated with video clip)
Added support for custom notification color
---------------------------------------------------------------------------------------------------------------------------
This blueprint will send a notification to your device when a Frigate event for the selected camera is fired. The notification will initially include the thumbnail of the detection, but will update to include actionable notifications allowing you to view the saved clip/snapshot when available, or silence the notification for a configurable amount of time.
With this blueprint, you may send the notification to multiple devices by leaving "Device" blank and instead use a [notification group][1].
### Required entities:
- Frigate Camera Name
- Mobile App Device **or** the name of a Notification Group
### Optional features:
- You can limit notifications to objects entering **any** pre-defined [zones][2] in Frigate.
- You can specify which [zones][2] to be notified about. This must be a list (e.g.):
```yaml
- backyard
```
- You can specify what type of [objects][3] to be notified about. This must be a list (e.g.):
```yaml
- person
- car
```
- You can disable notifications if a presence entity or group is "home".
- You can configure a cooldown for the camera to reduce the number of notifications when back-to-back events occur.
- You can silence future notifications for a defined amount of time through actionable notifications. This is helpful in situations where you know you will be triggering detections for an extended period of time, like when the kids are playing outside.
[1]: https://companion.home-assistant.io/docs/notifications/notifications-basic#sending-notifications-to-multiple-devices
[2]: https://blakeblackshear.github.io/frigate/configuration/cameras#zones
[3]: https://blakeblackshear.github.io/frigate/configuration/objects
domain: automation
source_url: https://gist.github.com/jhallenb/3b76ed5afa47054dc11213f5bb5b7528
input:
camera:
name: Frigate Camera
description: The name of the camera as defined in your frigate configuration.
notify_device:
name: Device
description: The device must run the official Home Assistant app to receive notifications.
default: false
selector:
device:
integration: mobile_app
notify_group:
name: Notification Group
description: The name of the notification group to call.
default: ""
base_url:
name: (Optional) Base URL
description: >
The external url for your Home Assistant instance. This will default to a relative
URL and will open the clips in the app instead of the browser, which may cause issues
on some devices.
default: ""
zone_filter:
name: (Optional) Zone Filter
description: Only notify if object has entered a defined zone.
default: false
selector:
boolean:
zones:
name: (Optional) Trigger Zones
description: A list (-) of zones you wish to recieve notifications for.
default: []
selector:
object:
labels:
name: (Optional) Trigger Objects
description: A list (-) of objects you wish to recieve notifications for.
default: []
selector:
object:
presence_filter:
name: (Optional) Presence Filter
description: Only notify if selected presence entity is not "home".
default: ""
selector:
entity:
notify_entity_filter:
name: (Optional) Notify Entity Filter
description: Entity that must match the entity value filter for the notification to be sent
default: ""
selector:
entity:
notify_entity_value_filter:
name: (Optional) Notify Entity if value matches Filter
description: Entity must match this value for the notification to be sent
default: ""
selector:
text:
cooldown:
name: (Optional) Cooldown
description: Delay before sending another notification for this camera after the last event.
default: 30
selector:
number:
max: 300
min: 0
unit_of_measurement: seconds
silence_timer:
name: (Optional) Silence Notifications
description: >
How long to silence notifications for this camera when requested as part of the
actionable notification.
default: 30
selector:
number:
max: 300
min: 0
unit_of_measurement: minutes
channel:
name: Channel
description: Notification Channel to use, allows you to use a custom notification sound in your phone.
default: "Frigate_Channel"
channel_update:
name: Channel Update
description: Notification Channel to use when updating a notification with more information.
default: "Frigate_Channel_Update"
color:
name: Color Notification
description: Color of the notification. You may use color names like blue or red, or hex format #FF0042
default: "yellow"
button_view_clip_title:
name: Button View Clip Text
description: Text for View Clip button
default: "View Clip"
button_silence_notification_title:
name: Button Silence Notification Text
description: Text for Silence Notification button
default: "Silence Notifications"
button_open_app_title:
name: Button Open App Text
description: Text for Open App button
default: "Open App"
button_open_app_url:
name: Button Open App URL
description: >
URL for Open App button (only supported for Android)
Example app://com.xm.csee
To find out the correct path for your app one may use ES Filemanager.
Click backup on the app twice. The second time you will get a popup asking to overwrite the file,
then you will see the correct app name (possibly wrapped into some nonsense text)
You may very well open your home assistant to a local lovelace path using this button instead.
default: "app://com.mm.android.smartlifeiot"
mode: single
max_exceeded: silent
trigger:
platform: mqtt
topic: frigate/events
payload: !input camera
value_template: "{{ value_json['after']['camera'] }}"
variables:
id: "{{ trigger.payload_json['after']['id'] }}"
camera: "{{ trigger.payload_json['after']['camera'] }}"
camera_name: "{{ camera | replace('_', ' ') | title }}"
object: "{{ trigger.payload_json['after']['label'] }}"
label: "{{ object | title }}"
entered_zones: "{{ trigger.payload_json['after']['entered_zones'] }}"
type: "{{ trigger.payload_json['type'] }}"
base_url: !input base_url
group_target: !input notify_group
zone_only: !input zone_filter
input_zones: !input zones
zones: "{{ input_zones | list }}"
input_labels: !input labels
labels: "{{ input_labels | list }}"
presence_entity: !input presence_filter
notification_channel: !input channel
notification_channel_update: !input channel_update
notification_color: !input color
notify_entity: !input notify_entity_filter
notify_entity_value: !input notify_entity_value_filter
button_view_clip_title: !input button_view_clip_title
button_open_app_title: !input button_open_app_title
button_open_app_url: !input button_open_app_url
button_silence_notification_title: !input button_silence_notification_title
condition:
- "{{ type != 'end' }}"
- "{{ not zone_only or entered_zones|length > 0 }}"
- "{{ not zones|length or zones|select('in', entered_zones)|list|length > 0 }}"
- "{{ not labels|length or object in labels }}"
- "{{ not presence_entity or not is_state(presence_entity, 'home') }}"
- "{{ not notify_entity or is_state(notify_entity, notify_entity_value) }}"
action:
- choose:
- conditions: "{{ not group_target }}"
sequence:
- device_id: !input notify_device
domain: mobile_app
type: notify
message: 'A {{ label }} was detected on {{ camera_name }}.'
data:
channel: '{{notification_channel}}'
color: '{{notification_color}}'
tag: '{{ id }}'
group: 'frigate-notification-{{ camera }}'
image: '/api/frigate/notifications/{{id}}/thumbnail.jpg?format=android' # Android
attachment: # iOS
url: '/api/frigate/notifications/{{id}}/thumbnail.jpg'
default:
- service: "notify.{{ group_target }}"
data:
message: 'A {{ label }} was detected on {{ camera_name }}.'
data:
channel: '{{notification_channel}}'
color: '{{notification_color}}'
tag: '{{ id }}'
group: 'frigate-notification-{{ camera }}'
image: '/api/frigate/notifications/{{id}}/thumbnail.jpg?format=android' # Android
attachment: # iOS
url: '/api/frigate/notifications/{{id}}/thumbnail.jpg'
- repeat:
sequence:
- wait_for_trigger:
- platform: mqtt
topic: frigate/events
payload: "{{ id }}"
value_template: "{{ value_json['after']['id'] }}"
timeout:
minutes: 2
continue_on_timeout: false
- condition: template
value_template: "{{ wait.trigger.payload_json['type'] == 'end' }}"
- choose:
- conditions: "{{ not group_target }}"
sequence:
- device_id: !input notify_device
domain: mobile_app
type: notify
message: 'A {{ label }} was detected on {{ camera_name }}.'
data:
channel: '{{notification_channel_update}}'
color: '{{notification_color}}'
tag: '{{ id }}'
group: 'frigate-notification-{{ camera }}'
url: '{{base_url}}/api/frigate/notifications/{{id}}/{{camera}}/clip.mp4' # iOS
clickAction: '{{base_url}}/api/frigate/notifications/{{id}}/{{camera}}/clip.mp4' # Android
image: '/api/frigate/notifications/{{id}}/thumbnail.jpg?format=android' # Android
sound: none
attachment: # iOS
url: '/api/frigate/notifications/{{id}}/thumbnail.jpg'
# lazy: true
actions:
- action: URI
title: '{{button_view_clip_title}}'
uri: '{{base_url}}/api/frigate/notifications/{{id}}/{{camera}}/clip.mp4'
- action: URI
title: '{{button_open_app_title}}'
uri: '{{button_open_app_url}}'
- action: 'silence-{{ camera }}'
title: '{{button_silence_notification_title}}'
destructive: true
default:
- service: "notify.{{ group_target }}"
data:
message: 'A {{ label }} was detected on {{ camera_name }}.'
data:
channel: '{{notification_channel_update}}'
color: '{{notification_color}}'
tag: '{{ id }}'
group: 'frigate-notification-{{ camera }}'
url: '{{base_url}}/api/frigate/notifications/{{id}}/{{camera}}/clip.mp4' # iOS
clickAction: '{{base_url}}/api/frigate/notifications/{{id}}/{{camera}}/clip.mp4' # Android
image: '/api/frigate/notifications/{{id}}/thumbnail.jpg?format=android' # Android
sound: none
attachment: # iOS
url: '/api/frigate/notifications/{{id}}/thumbnail.jpg'
# lazy: true
actions:
- action: URI
title: '{{button_view_clip_title}}'
uri: '{{base_url}}/api/frigate/notifications/{{id}}/{{camera}}/clip.mp4'
- action: URI
title: '{{button_open_app_title}}'
uri: '{{button_open_app_url}}'
- action: 'silence-{{ camera }}'
title: '{{button_silence_notification_title}}'
destructive: true
until: "{{ wait.trigger.payload_json['type'] == 'end' }}"
- wait_for_trigger:
- platform: event
event_type: mobile_app_notification_action
event_data:
action: 'silence-{{ camera }}'
timeout:
seconds: !input cooldown
continue_on_timeout: false
- delay:
minutes: !input silence_timer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment