Skip to content

Instantly share code, notes, and snippets.

@cvroque
Forked from SgtBatten/frigate_0.11_notification.yaml
Last active November 28, 2022 19:39
Show Gist options
  • Save cvroque/2aa82956e5eccbd1fcc3638afd990203 to your computer and use it in GitHub Desktop.
Save cvroque/2aa82956e5eccbd1fcc3638afd990203 to your computer and use it in GitHub Desktop.
Frigate 0.11 Notifications
blueprint:
name: Frigate Notification (0.11.0.6) - SgtB
description: |
## Frigate Mobile App Notification
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 include an actionable notification allowing you to view the clip and snapshot.
With this blueprint, you may send the notification to multiple devices by leaving "Device" blank and instead use a [notification group][1].
### Software Version Requirements
Minimum Home Assistant Version: 2022.2
Minimum Frigate Version: 0.10.0 Beta 10
Minimum Frigate Integration Version: 2.2.0
Minimum iOS Version: 15.0
### Required entities:
- Frigate Camera Name
- Mobile App Device **or** the name of a Notification Group
### Optional features:
- You can optionally send the notification as a critical alert.
- You can choose whether or not to update the notification with new thumbnails as they become available.
- You can limit notifications to objects entering 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. i.e. kids playing outside.
- You can set a loitering timer to notify you of stationary objects that remain for a set period of time.
### Updates by SgtBatten:
- Fix for fps_value template error as per https://community.home-assistant.io/t/frigate-mobile-app-notifications/311091/451?u=sgtbatten
- Fix Zone Filter being bypassed by snapshots as per https://community.home-assistant.io/t/frigate-mobile-app-notifications/311091/421?u=sgtbatten
- Improve camera entity selection by limiting it to frigate entities
- Improve presence entity selection by limiting it to device trackers, persons and groups
- You can prevent all secondary updates from making notification sounds (Alert Once)
- You can add use a state condition to restrict when you recieve notifications. E.g only when your door is locked, or only when your car isn't in the driveway or the sun is below the horizon.
- Added ability to customise the message text and buttons in the notification.
- Made the snapshot Action button customisable so you can link to anything of choice.
[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/hunterjm/8ff0005104dce3f28923294f49a443b1
input:
camera:
name: Frigate Camera
description: "Select the camera entity that will trigger notifications.
DO NOT select one with a trailing object.
e.g select camera.front not camera.front_person"
selector:
entity:
integration: frigate
domain: camera
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 does not work well on iOS.
default: ""
critical:
name: (Optional) Critical Notification
description: >
Send as a critical notification to the mobile device.
Sometimes notifications (particularly on android) are delayed, this will resolve this.
default: false
selector:
boolean:
alert_once:
name: (Optional) Alert Once
description: "Only the first notification for each event can have a sound. Updates, including new thumbnails will be silent."
default: false
selector:
boolean:
update_thumbnail:
name: (Optional) Update Thumbnail
description: Update notification if a new "better" thumbnail is available.
default: false
selector:
boolean:
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:
domain:
- device_tracker
- person
- group
state_filter:
name: (Optional) State Filter
description: Enable the two State Filter settings below. Only notify if selected entity is in the specified states.
default: false
selector:
boolean:
state_entity:
name: (Optional) State Filter Entity
description: Only notify if selected entity is in the below state. You must enable State Filter above to use this.
default: ""
selector:
entity:
state_filter_states:
name: (Optional) State Filter States
description: A list (-) of states that the above entity must be in.
default: []
selector:
object:
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 New Object Notifications
description: >
How long to silence notifications for this camera when requested as part of the
actionable notification. Note: This only applies to new objects. Existing tracked
objects will not be affected.
default: 30
selector:
number:
max: 300
min: 0
unit_of_measurement: minutes
loiter_timer:
name: (Optional) Loitering Notifications
description: >
Sends new loitering notification if a stationary object is detected for longer
than the specified time. 0 is off and will not send notifications.
default: 0
selector:
number:
max: 300
min: 0
unit_of_measurement: minutes
message:
name: Message
description: >
"The message of the notification.
You can use variables such as {{camera_name}} and {{label}}
e.g A {{ label }} {{ 'is loitering' if loitering else 'was detected' }} on the {{ camera_name }} camera."
default: A {{ label }} was detected on the {{ camera_name }} camera.
button_1:
name: View Clip Button Text
description: "The text used on the View Clip button at the bottom of the notification"
default: "View Clip"
button_2:
name: Custom Button Text
description: Customise the text on the third Action Button
default: "View Snapshot"
custom_url:
name: Custom button link
description: Customise what happens when you press the third Action Button. Select from one of the preconfigured options or enter your own custom URL.
default: "{{base_url}}/api/frigate/notifications/{{id}}/snapshot.jpg"
selector:
select:
options:
- label: View Snapshot
value: "{{base_url}}/api/frigate/notifications/{{id}}/snapshot.jpg"
- label: Open Home Assistant
value: "{{base_url}}"
custom_value: true
button_3:
name: Silence New Notifications Button Text
description: "The text used on the Silence button at the bottom of the notification"
default: "Silence New Notifications"
mode: parallel
trigger_variables:
input_camera: !input camera
camera: "{{ input_camera | replace('camera.', '') }}"
trigger:
- platform: event
event_type: mobile_app_notification_action
event_data:
action: "silence-{{ camera }}"
id: silence
- platform: mqtt
topic: frigate/events
payload: "{{ camera }}/new"
value_template: "{{ value_json['after']['camera'] | lower }}/{{ value_json['type']}}"
id: frigate-event
variables:
input_camera: !input camera
camera: "{{ input_camera | replace('camera.', '') }}"
camera_name: "{{ camera | replace('_', ' ') | title }}"
base_url: !input base_url
critical: !input critical
alert_once: !input alert_once
update_thumbnail: !input update_thumbnail
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
cooldown: !input cooldown
loiter_timer: !input loiter_timer
fps: "{{ states('sensor.' + camera + '_camera_fps')|int(5) }}"
state_only: !input state_filter
input_entity: !input state_entity
input_states: !input state_filter_states
states_filter: "{{ input_states | list }}"
action:
- choose:
- alias: "Silence New Object Notifications"
conditions:
- condition: trigger
id: silence
sequence:
- service: automation.turn_off
target:
entity_id: "{{ this.entity_id }}"
data:
stop_actions: false
- delay:
minutes: !input silence_timer
- service: automation.turn_on
target:
entity_id: "{{ this.entity_id }}"
- alias: "Frigate Event"
conditions:
- condition: trigger
id: "frigate-event"
- "{{ is_state(this.entity_id, 'on') }}"
- "{{ not this.attributes.last_triggered or (now() - this.attributes.last_triggered).seconds > cooldown }}"
sequence:
- variables:
id: "{{ trigger.payload_json['after']['id'] }}"
object: "{{ trigger.payload_json['after']['label'] }}"
label: "{{ object | title }}"
# Dynamic Variables per event
initial_home: "{{ presence_entity != '' and is_state(presence_entity, 'home') }}"
initial_entered_zones: "{{ trigger.payload_json['after']['entered_zones'] }}"
# Customisation of text
message: !input message
button_1: !input button_1
button_2: !input button_2
button_3: !input button_3
custom_url: !input custom_url
- alias: "Notifications enabled for object label"
condition: template
value_template: "{{ not labels|length or object in labels }}"
- alias: "Notify on new object"
choose:
- conditions:
- "{{ not zone_only or initial_entered_zones|length > 0 }}"
- "{{ not zones|length or zones|select('in', initial_entered_zones)|list|length > 0 }}"
- "{{ not initial_home }}"
- "{{ not state_only or states(input_entity) in states_filter }}"
sequence:
- choose:
- conditions: "{{ not group_target }}"
sequence:
- device_id: !input notify_device
domain: mobile_app
type: notify
message: "{{message}}"
data:
tag: "{{ id }}"
group: "{{ camera }}-frigate-notification"
# Android Specific
image: "/api/frigate/notifications/{{id}}/thumbnail.jpg?format=android"
clickAction: "{{base_url}}/api/frigate/notifications/{{id}}/{{camera}}/clip.mp4"
ttl: "{{ iif(critical, 0, 3600000) }}"
priority: "{{ iif(critical, 'high', 'normal') }}"
# iOS Specific
url: "{{base_url}}/api/frigate/notifications/{{id}}/{{camera}}/clip.mp4"
attachment:
url: "/api/frigate/notifications/{{id}}/thumbnail.jpg"
push:
interruption-level: "{{ iif(critical, 'critical', 'active') }}"
# Actions
actions:
- action: URI
title: "{{button_1}}"
uri: "{{base_url}}/api/frigate/notifications/{{id}}/{{camera}}/clip.mp4"
- action: URI
title: "{{button_2}}"
uri: "{{custom_url}}"
- action: "silence-{{ camera }}"
title: "{{button_3}}"
destructive: true
default:
- service: "notify.{{ group_target }}"
data:
message: "{{message}}"
data:
tag: "{{ id }}"
group: "{{ camera }}-frigate-notification"
# Android Specific
image: "http://homeassistant.local:8123/api/frigate/notifications/{{id}}/thumbnail.jpg?format=android"
clickAction: "{{base_url}}/api/frigate/notifications/{{id}}/{{camera}}/clip.mp4"
ttl: "{{ iif(critical, 0, 3600000) }}"
priority: "{{ iif(critical, 'high', 'normal') }}"
# iOS Specific
url: "{{base_url}}/api/frigate/notifications/{{id}}/{{camera}}/clip.mp4"
attachment:
url: "/api/frigate/notifications/{{id}}/thumbnail.jpg"
push:
interruption-level: "{{ iif(critical, 'critical', 'active') }}"
# HASS Specific
data:
image: "/api/frigate/notifications/{{id}}/thumbnail.jpg"
# Actions
actions:
- action: URI
title: "{{button_1}}"
uri: "{{base_url}}/api/frigate/notifications/{{id}}/{{camera}}/clip.mp4"
- action: URI
title: "{{button_2}}"
uri: "{{custom_url}}"
- action: "silence-{{ camera }}"
title: "{{button_3}}"
destructive: true
- 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
- variables:
event: "{{ wait.trigger.payload_json }}"
loitering: "{{ loiter_timer and event['before']['motionless_count']/fps/60 < loiter_timer and event['after']['motionless_count']/fps/60 >= loiter_timer }}"
new_snapshot: "{{ update_thumbnail and event['before']['snapshot_time'] != event['after']['snapshot_time'] }}"
home: "{{ presence_entity != '' and is_state(presence_entity, 'home') }}"
presence_changed: "{{ presence_entity != '' and as_datetime(event['before']['frame_time']) < states[presence_entity].last_changed }}"
last_zones: "{{ event['before']['entered_zones'] }}"
entered_zones: "{{ event['after']['entered_zones'] }}"
zone_filter: "{{ not zone_only or entered_zones|length > 0 and zones|select('in', entered_zones)|list|length > 0 }}"
stationary_moved: "{{ event['after']['position_changes'] > event['before']['position_changes'] }}"
zone_only_changed: "{{ zone_only and (entered_zones|length > 0 and not last_zones|length) }}"
entered_zones_changed: "{{ zones|length > 0 and (zones|select('in', entered_zones)|list|length > 0 and not zones|select('in', last_zones)|list|length) }}"
state_true: "{{ not state_only or states(input_entity) in states_filter }}"
update: "{{ alert_once or (new_snapshot and not loitering and not presence_changed and not zone_only_changed and not entered_zones_changed) }}"
- alias: "Notify on loitering or significant change"
choose:
- conditions: "{{ loitering or (not home and zone_filter and state_true and (new_snapshot or presence_changed or stationary_moved or zone_only_changed or entered_zones_changed)) }}"
sequence:
- choose:
- conditions: "{{ not group_target }}"
sequence:
- device_id: !input notify_device
domain: mobile_app
type: notify
message: "{{message}}"
data:
tag: "{{ id }}{{'-loitering' if loitering}}"
group: "{{ camera }}-frigate-notification{{'-loitering' if loitering}}"
# Android Specific
image: "/api/frigate/notifications/{{id}}/thumbnail.jpg?format=android"
clickAction: "{{base_url}}/api/frigate/notifications/{{id}}/{{camera}}/clip.mp4"
ttl: "{{ iif(critical, 0, 3600000) }}"
priority: "{{ iif(critical, 'high', 'normal') }}"
alert_once: "{{ alert_once }}"
# iOS Specific
url: "{{base_url}}/api/frigate/notifications/{{id}}/{{camera}}/clip.mp4"
attachment:
url: "/api/frigate/notifications/{{id}}/thumbnail.jpg"
sound: "{{ iif(update, 'none', 'default') }}"
push:
interruption-level: "{{ iif(critical, 'critical', 'active') }}"
# Actions
actions:
- action: URI
title: "{{button_1}}"
uri: "{{base_url}}/api/frigate/notifications/{{id}}/{{camera}}/clip.mp4"
- action: URI
title: "{{button_2}}"
uri: "{{custom_url}}"
- action: "silence-{{ camera }}"
title: "{{button_3}}"
destructive: true
default:
- service: "notify.{{ group_target }}"
data:
message: "{{message}}"
data:
tag: "{{ id }}{{'-loitering' if loitering}}"
group: "{{ camera }}-frigate-notification{{'-loitering' if loitering}}"
# Android Specific
image: "http://homeassistant.local:8123/api/frigate/notifications/{{id}}/thumbnail.jpg?format=android"
clickAction: "{{base_url}}/api/frigate/notifications/{{id}}/{{camera}}/clip.mp4"
ttl: "{{ iif(critical, 0, 3600000) }}"
priority: "{{ iif(critical, 'high', 'normal') }}"
alert_once: "{{ alert_once }}"
# iOS Specific
url: "{{base_url}}/api/frigate/notifications/{{id}}/{{camera}}/clip.mp4"
attachment:
url: "/api/frigate/notifications/{{id}}/thumbnail.jpg"
sound: "{{ iif(update, 'none', 'default') }}"
push:
interruption-level: "{{ iif(critical, 'critical', 'active') }}"
# HASS Specific
data:
image: "/api/frigate/notifications/{{id}}/thumbnail.jpg"
# Actions
actions:
- action: URI
title: "{{button_1}}"
uri: "{{base_url}}/api/frigate/notifications/{{id}}/{{camera}}/clip.mp4"
- action: URI
title: "{{button_2}}"
uri: "{{custom_url}}"
- action: "silence-{{ camera }}"
title: "{{button_3}}"
destructive: true
until: "{{ not wait.trigger or wait.trigger.payload_json['type'] == 'end' }}"
blueprint:
name: Frigate Notification (0.11.0.6e) - SgtB
description: |
## Frigate Mobile App Notification
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 include an actionable notification allowing you to view the clip and snapshot.
With this blueprint, you may send the notification to multiple devices by leaving "Device" blank and instead use a [notification group][1].
### Software Version Requirements
Minimum Home Assistant Version: 2022.2
Minimum Frigate Version: 0.10.0 Beta 10
Minimum Frigate Integration Version: 2.2.0
Minimum iOS Version: 15.0
### Required entities:
- Frigate Camera Name
- Mobile App Device **or** the name of a Notification Group
### Optional features:
- You can optionally send the notification as a critical alert.
- You can choose whether or not to update the notification with new thumbnails as they become available.
- You can limit notifications to objects entering 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. i.e. kids playing outside.
- You can set a loitering timer to notify you of stationary objects that remain for a set period of time.
### Updates by SgtBatten:
- Fix for fps_value template error as per https://community.home-assistant.io/t/frigate-mobile-app-notifications/311091/451?u=sgtbatten
- Fix Zone Filter being bypassed by snapshots as per https://community.home-assistant.io/t/frigate-mobile-app-notifications/311091/421?u=sgtbatten
- Fix Zone Filter being incorrectly applied to the initial notification when Zone Filter was set to false.
- Improve camera entity selection by limiting it to frigate entities
- Improve presence entity selection by limiting it to device trackers, persons and groups
- You can prevent all secondary updates from making notification sounds (Alert Once)
- You can add use a state condition to restrict when you recieve notifications. E.g only when your door is locked, or only when your car isn't in the driveway or the sun is below the horizon.
- Added ability to customise the message text and buttons in the notification.
- Made the snapshot Action button customisable so you can link to anything of choice.
- Fix issue if user does not cleanup the yaml after removing object filter
- Added customisable Icons. - not sure if it works on IOS yet
- Added customisable sound for IOS.
- You can disable the notifications at certain times (Time Filter)
- You can choose to have the notifications sent as critical only at certain times (different method to the time filter to test preferences)
[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/hunterjm/8ff0005104dce3f28923294f49a443b1
input:
camera:
name: Frigate Camera
description: "Select the camera entity that will trigger notifications.
DO NOT select one with a trailing object.
e.g select camera.front not camera.front_person"
selector:
entity:
integration: frigate
domain: camera
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 does not work well on iOS.
default: ""
critical:
name: (Optional) Critical Notification
description: >
Send as a critical notification to the mobile device.
Sometimes notifications (particularly on android) are delayed, this will resolve this.
You can choose to limit crtical notifications to certain times using a template (two examples provided but you can enter your own as long as it outputs true or false)
default: "false"
selector:
select:
options:
- "false"
- "true"
- "{{'false' if now().hour in [8,9,10,11,12,13,14,15,16,17,18] else 'true'}}"
- "{{'true' if is_state('sun.sun', 'above_horizon') else 'false' }}"
custom_value: true
alert_once:
name: (Optional) Alert Once
description: "Only the first notification for each event can have a sound. Updates, including new thumbnails will be silent."
default: false
selector:
boolean:
update_thumbnail:
name: (Optional) Update Thumbnail
description: Update notification if a new "better" thumbnail is available.
default: false
selector:
boolean:
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:
domain:
- device_tracker
- person
- group
state_filter:
name: (Optional) State Filter
description: Enable the two State Filter settings below. Only notify if selected entity is in the specified states.
default: false
selector:
boolean:
state_entity:
name: (Optional) State Filter Entity
description: Only notify if selected entity is in the below state. You must enable State Filter above to use this.
default: ""
selector:
entity:
state_filter_states:
name: (Optional) State Filter States
description: A list (-) of states that the above entity must be in.
default: []
selector:
object:
disable_times:
name: (Optional) Disable notifications by time
description: Prevent notifications from being sent during the specified hours
default: []
selector:
select:
multiple: true
options:
- label: 00:00 - 00:59
value: "0"
- label: 01:00 - 01:59
value: "1"
- label: 02:00 - 02:59
value: "2"
- label: 03:00 - 03:59
value: "3"
- label: 04:00 - 04:59
value: "4"
- label: 05:00 - 05:59
value: "5"
- label: 06:00 - 06:59
value: "6"
- label: 07:00 - 06:59
value: "7"
- label: 08:00 - 08:59
value: "8"
- label: 09:00 - 09:59
value: "9"
- label: 10:00 - 10:59
value: "10"
- label: 11:00 - 11:59
value: "11"
- label: 12:00 - 12:59
value: "12"
- label: 13:00 - 13:59
value: "13"
- label: 14:00 - 14:59
value: "14"
- label: 15:00 - 15:59
value: "15"
- label: 16:00 - 16:59
value: "16"
- label: 17:00 - 17:59
value: "17"
- label: 18:00 - 18:59
value: "18"
- label: 19:00 - 19:59
value: "19"
- label: 20:00 - 20:59
value: "20"
- label: 21:00 - 21:59
value: "21"
- label: 22:00 - 22:59
value: "22"
- label: 23:00 - 23:59
value: "23"
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 New Object Notifications
description: >
How long to silence notifications for this camera when requested as part of the
actionable notification. Note: This only applies to new objects. Existing tracked
objects will not be affected.
default: 30
selector:
number:
max: 300
min: 0
unit_of_measurement: minutes
loiter_timer:
name: (Optional) Loitering Notifications
description: >
Sends new loitering notification if a stationary object is detected for longer
than the specified time. 0 is off and will not send notifications.
default: 0
selector:
number:
max: 300
min: 0
unit_of_measurement: minutes
message:
name: Message
description: >
"The message of the notification.
You can use variables such as {{camera_name}} and {{label}}
e.g A {{ label }} {{ 'is loitering' if loitering else 'was detected' }} on the {{ camera_name }} camera."
default: A {{ label }} was detected on the {{ camera_name }} camera.
button_1:
name: View Clip Button Text
description: "The text used on the View Clip button at the bottom of the notification"
default: "View Clip"
button_2:
name: Custom Button Text
description: Customise the text on the third Action Button
default: "View Snapshot"
custom_url:
name: Custom button link
description: Customise what happens when you press the third Action Button. Select from one of the preconfigured options or enter your own custom URL.
default: "{{base_url}}/api/frigate/notifications/{{id}}/snapshot.jpg"
selector:
select:
options:
- label: View Snapshot
value: "{{base_url}}/api/frigate/notifications/{{id}}/snapshot.jpg"
- label: Open Home Assistant
value: "{{base_url}}"
custom_value: true
button_3:
name: Silence New Notifications Button Text
description: "The text used on the Silence button at the bottom of the notification"
default: "Silence New Notifications"
icon:
name: Notification Icons
description: Change the icon that displays on the notification. You can enter a single icon or create a template like the example given in the dropdown. You must include 'mdi:' in the icon name.
default:
- mdi:home-assistant
selector:
select:
options:
- mdi:home-assistant
- mdi:cctv
- "mdi:{{'account-outline' if label == 'Person' else 'dog' if label == 'Dog' else 'cat' if label == 'Cat' else 'car' if label == 'Car' else 'home-assistant'}}"
custom_value: true
sound:
name: Sound (IOS only)
description: You can specify a soud file on your device that will play for the notifications. You will need to import the sound file into home assistant.
default: default
selector:
select:
options:
- default
- none
custom_value: true
mode: parallel
trigger_variables:
input_camera: !input camera
camera: "{{ input_camera | replace('camera.', '') }}"
trigger:
- platform: event
event_type: mobile_app_notification_action
event_data:
action: "silence-{{ camera }}"
id: silence
- platform: mqtt
topic: frigate/events
payload: "{{ camera }}/new"
value_template: "{{ value_json['after']['camera'] | lower }}/{{ value_json['type']}}"
id: frigate-event
variables:
input_camera: !input camera
camera: "{{ input_camera | replace('camera.', '') }}"
camera_name: "{{ camera | replace('_', ' ') | title }}"
base_url: !input base_url
critical_input: !input critical
critical: "{{true if critical_input == 'true' else false}}"
alert_once: !input alert_once
update_thumbnail: !input update_thumbnail
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
disable_times: !input disable_times
# time_filter: "{{ disable_times | list }}"
cooldown: !input cooldown
loiter_timer: !input loiter_timer
fps: "{{ states('sensor.' + camera + '_camera_fps')|int(5) }}"
state_only: !input state_filter
input_entity: !input state_entity
input_states: !input state_filter_states
states_filter: "{{ input_states | list }}"
sound: !input sound
action:
- choose:
- alias: "Silence New Object Notifications"
conditions:
- condition: trigger
id: silence
sequence:
- service: automation.turn_off
target:
entity_id: "{{ this.entity_id }}"
data:
stop_actions: false
- delay:
minutes: !input silence_timer
- service: automation.turn_on
target:
entity_id: "{{ this.entity_id }}"
- alias: "Frigate Event"
conditions:
- condition: trigger
id: "frigate-event"
- "{{ is_state(this.entity_id, 'on') }}"
- "{{ not this.attributes.last_triggered or (now() - this.attributes.last_triggered).seconds > cooldown }}"
- "{{ not disable_times|length or not now().hour in disable_times }}"
sequence:
- variables:
id: "{{ trigger.payload_json['after']['id'] }}"
object: "{{ trigger.payload_json['after']['label'] }}"
label: "{{ object | title }}"
# Dynamic Variables per event
initial_home: "{{ presence_entity != '' and is_state(presence_entity, 'home') }}"
initial_entered_zones: "{{ trigger.payload_json['after']['entered_zones'] }}"
# Customisation of text
message: !input message
button_1: !input button_1
button_2: !input button_2
button_3: !input button_3
custom_url: !input custom_url
icon: !input icon
- alias: "Notifications enabled for object label"
condition: template
value_template: "{{ not labels|length or object in labels }}"
- alias: "Notify on new object"
choose:
- conditions:
- "{{ not zone_only or zones|select('in', initial_entered_zones)|list|length > 0 }}"
- "{{ not initial_home }}"
- "{{ not state_only or states(input_entity) in states_filter }}"
sequence:
- choose:
- conditions: "{{ not group_target }}"
sequence:
- device_id: !input notify_device
domain: mobile_app
type: notify
message: "{{message}}"
data:
tag: "{{ id }}"
group: "{{ camera }}-frigate-notification"
# Android Specific
image: "/api/frigate/notifications/{{id}}/thumbnail.jpg?format=android"
clickAction: "{{base_url}}/api/frigate/notifications/{{id}}/{{camera}}/clip.mp4"
ttl: "{{ iif(critical, 0, 3600000) }}"
priority: "{{ iif(critical, 'high', 'normal') }}"
notification_icon: "{{icon}}"
# iOS Specific
url: "{{base_url}}/api/frigate/notifications/{{id}}/{{camera}}/clip.mp4"
attachment:
url: "/api/frigate/notifications/{{id}}/thumbnail.jpg"
push:
sound: "{{sound}}"
interruption-level: "{{ iif(critical, 'critical', 'active') }}"
# Actions
actions:
- action: URI
title: "{{button_1}}"
uri: "{{base_url}}/api/frigate/notifications/{{id}}/{{camera}}/clip.mp4"
- action: URI
title: "{{button_2}}"
uri: "{{custom_url}}"
- action: "silence-{{ camera }}"
title: "{{button_3}}"
destructive: true
default:
- service: "notify.{{ group_target }}"
data:
message: "{{message}}"
data:
tag: "{{ id }}"
group: "{{ camera }}-frigate-notification"
# Android Specific
image: "/api/frigate/notifications/{{id}}/thumbnail.jpg?format=android"
clickAction: "{{base_url}}/api/frigate/notifications/{{id}}/{{camera}}/clip.mp4"
ttl: "{{ iif(critical, 0, 3600000) }}"
priority: "{{ iif(critical, 'high', 'normal') }}"
notification_icon: "{{icon}}"
# iOS Specific
url: "{{base_url}}/api/frigate/notifications/{{id}}/{{camera}}/clip.mp4"
attachment:
url: "/api/frigate/notifications/{{id}}/thumbnail.jpg"
push:
sound: "{{sound}}"
interruption-level: "{{ iif(critical, 'critical', 'active') }}"
# Actions
actions:
- action: URI
title: "{{button_1}}"
uri: "{{base_url}}/api/frigate/notifications/{{id}}/{{camera}}/clip.mp4"
- action: URI
title: "{{button_2}}"
uri: "{{custom_url}}"
- action: "silence-{{ camera }}"
title: "{{button_3}}"
destructive: true
- 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
- variables:
event: "{{ wait.trigger.payload_json }}"
loitering: "{{ loiter_timer and event['before']['motionless_count']/fps/60 < loiter_timer and event['after']['motionless_count']/fps/60 >= loiter_timer }}"
new_snapshot: "{{ update_thumbnail and event['before']['snapshot_time'] != event['after']['snapshot_time'] }}"
home: "{{ presence_entity != '' and is_state(presence_entity, 'home') }}"
presence_changed: "{{ presence_entity != '' and as_datetime(event['before']['frame_time']) < states[presence_entity].last_changed }}"
last_zones: "{{ event['before']['entered_zones'] }}"
entered_zones: "{{ event['after']['entered_zones'] }}"
zone_filter: "{{ not zone_only or zones|select('in', entered_zones)|list|length > 0 }}"
stationary_moved: "{{ event['after']['position_changes'] > event['before']['position_changes'] }}"
zone_only_changed: "{{ zone_only and (entered_zones|length > 0 and not last_zones|length) }}"
entered_zones_changed: "{{ zones|length > 0 and (zones|select('in', entered_zones)|list|length > 0 and not zones|select('in', last_zones)|list|length) }}"
state_true: "{{ not state_only or states(input_entity) in states_filter }}"
update: "{{ alert_once or (new_snapshot and not loitering and not presence_changed and not zone_only_changed and not entered_zones_changed) }}"
- alias: "Notify on loitering or significant change"
choose:
- conditions: "{{ loitering or (not home and zone_filter and state_true and (new_snapshot or presence_changed or stationary_moved or zone_only_changed or entered_zones_changed)) }}"
sequence:
- choose:
- conditions: "{{ not group_target }}"
sequence:
- device_id: !input notify_device
domain: mobile_app
type: notify
message: "{{message}}"
data:
tag: "{{ id }}{{'-loitering' if loitering}}"
group: "{{ camera }}-frigate-notification{{'-loitering' if loitering}}"
# Android Specific
image: "/api/frigate/notifications/{{id}}/thumbnail.jpg?format=android"
clickAction: "{{base_url}}/api/frigate/notifications/{{id}}/{{camera}}/clip.mp4"
ttl: "{{ iif(critical, 0, 3600000) }}"
priority: "{{ iif(critical, 'high', 'normal') }}"
alert_once: "{{ alert_once }}"
notification_icon: "{{icon}}"
# iOS Specific
url: "{{base_url}}/api/frigate/notifications/{{id}}/{{camera}}/clip.mp4"
attachment:
url: "/api/frigate/notifications/{{id}}/thumbnail.jpg"
push:
sound:
name: "{{ iif(update, 'none', sound) }}"
interruption-level: "{{ iif(critical, 'critical', 'active') }}"
# Actions
actions:
- action: URI
title: "{{button_1}}"
uri: "{{base_url}}/api/frigate/notifications/{{id}}/{{camera}}/clip.mp4"
- action: URI
title: "{{button_2}}"
uri: "{{custom_url}}"
- action: "silence-{{ camera }}"
title: "{{button_3}}"
destructive: true
default:
- service: "notify.{{ group_target }}"
data:
message: "{{message}}"
data:
tag: "{{ id }}{{'-loitering' if loitering}}"
group: "{{ camera }}-frigate-notification{{'-loitering' if loitering}}"
# Android Specific
image: "/api/frigate/notifications/{{id}}/thumbnail.jpg?format=android"
clickAction: "{{base_url}}/api/frigate/notifications/{{id}}/{{camera}}/clip.mp4"
ttl: "{{ iif(critical, 0, 3600000) }}"
priority: "{{ iif(critical, 'high', 'normal') }}"
alert_once: "{{ alert_once }}"
notification_icon: "{{icon}}"
# iOS Specific
url: "{{base_url}}/api/frigate/notifications/{{id}}/{{camera}}/clip.mp4"
attachment:
url: "/api/frigate/notifications/{{id}}/thumbnail.jpg"
push:
sound:
name: "{{ iif(update, 'none', sound) }}"
interruption-level: "{{ iif(critical, 'critical', 'active') }}"
# Actions
actions:
- action: URI
title: "{{button_1}}"
uri: "{{base_url}}/api/frigate/notifications/{{id}}/{{camera}}/clip.mp4"
- action: URI
title: "{{button_2}}"
uri: "{{custom_url}}"
- action: "silence-{{ camera }}"
title: "{{button_3}}"
destructive: true
until: "{{ not wait.trigger or wait.trigger.payload_json['type'] == 'end' }}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment