Created
April 11, 2023 10:43
-
-
Save simplepush/c9ec938667c3aecb30adf8db26dea99c to your computer and use it in GitHub Desktop.
Frigate 0.11 Notifications with Simplepush
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
blueprint: | |
name: Simplepush Frigate Notifications (0.11.0.1) | |
domain: automation | |
source_url: https://gist.github.com/SgtBatten/10a2dc7f16af9f55f3ba83fe4523d8d7 | |
input: | |
camera: | |
name: Frigate Camera | |
description: | | |
Select the camera entity that will trigger notifications. | |
If you do not see cameras listed in the drop down, check you have the frigate integration installed. | |
Note: The automation relies on this matching your frigate config (by default it does). | |
selector: | |
entity: | |
integration: frigate | |
domain: camera | |
device_class: camera | |
base_url: | |
name: Base URL (Required) | |
description: | | |
The external or internal url for your Home Assistant instance. | |
default: "" | |
title: | |
name: Notification Title (Optional) | |
description: | | |
The title of the notification. | |
default: "" | |
message: | |
name: Notification 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 }} {{ 'is loitering' if loitering else 'was detected' }} on the {{ camera_name }} camera. | |
selector: | |
select: | |
options: | |
- label: "Default: e.g A Person was detected on the Side camera." | |
value: "A {{ label }} {{ 'is loitering' if loitering else 'was detected' }} on the {{ camera_name }} camera." | |
- label: "Short: e.g Person detected - Side" | |
value: "{{ label }} detected - {{ camera_name }}" | |
- label: "Long: e.g A Person was detected on the Side camera in the driveway." | |
value: "A {{ label }} {{ 'is loitering' if loitering else 'was detected' }} on the {{ camera_name }} camera{{ ' in the ' + entered_zones if entered_zones else '.'}}" | |
- label: Debug | |
value: "DEBUG: Check the Home Assistant logbook" | |
custom_value: true | |
zone_filter: | |
name: Zone Filter on/off (Optional) | |
description: | | |
Enable to only notify if object has entered a zone listed below. | |
default: false | |
selector: | |
boolean: | |
zones: | |
name: Zone Filter (Optional - Enabled Above) | |
description: | | |
Enter the name of one zone at a time. Include underscores as per your frigate config. | |
Note: If the text entry is glitching (dissapearing every few seconds) select one of the examples, then edit in yaml mode. | |
default: [] | |
selector: | |
select: | |
multiple: true | |
custom_value: true | |
options: | |
- examples | |
- porch | |
- front_door | |
- side | |
- garden | |
labels: | |
name: Object Filter (Optional) | |
description: | | |
Enter or select one object at a time. | |
Note: If the text entry is glitching (dissapearing every few seconds) select one of the examples, then edit in yaml mode. | |
default: "" | |
selector: | |
select: | |
multiple: true | |
custom_value: true | |
options: | |
- person | |
- dog | |
- cat | |
- car | |
- package | |
- bird | |
presence_filter: | |
name: Presence Filter (Optional) | |
description: Only notify if selected presence entity is not "home". | |
default: "" | |
selector: | |
entity: | |
domain: | |
- device_tracker | |
- person | |
- group | |
state_filter: | |
name: State Filter on/off (Optional) | |
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: State Filter Entity (Optional) | |
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: State Filter States (Optional) | |
description: Enter the states that the above entity must be in, one at a time. | |
default: [] | |
selector: | |
select: | |
multiple: true | |
custom_value: true | |
options: [] | |
disable_times: | |
name: Time Filter (Optional) | |
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 - 07: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: Cooldown (Optional) | |
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: Silence New Object Notifications (Optional) | |
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: Loitering Notifications (Optional) | |
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 | |
debug: | |
name: Debug | |
description: | | |
Enable to send debug messsages to the home assistant logbook. | |
default: false | |
selector: | |
boolean: | |
mode: parallel | |
trigger_variables: | |
input_camera: !input camera | |
camera: "{{ input_camera | replace('camera.', '') }}" | |
trigger: | |
- platform: event | |
event_type: simplepush_action_triggered_event | |
event_data: | |
id: "silence-{{ camera }}" | |
id: silence | |
- platform: mqtt | |
topic: frigate/events | |
payload: "{{ camera }}/new" | |
value_template: "{{ value_json['after']['camera'] | lower | replace('-','_') }}/{{ 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 | |
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 | |
cooldown: !input cooldown | |
loitering: false | |
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 }}" | |
debug: !input debug | |
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|map('int')|list }}" | |
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 | |
title: !input title | |
message: !input message | |
- alias: "Debug: write to Log" | |
choose: | |
- conditions: | |
- "{{debug}}" | |
sequence: | |
- service: logbook.log | |
data_template: | |
name: Frigate Notification | |
message: | | |
DEBUG: camera(formatted): {{camera}}({{camera_name}}), frigate event id: {{id}}{{', Frigate client ID: ' + client_id if client_id else ''}}, object: {{object}}({{label}}), Base URL: {{base_url}}, | |
alert once: {{alert_once}}, | |
zone filter on: {{zone_only}}, zones: {{input_zones}}, Multi Zone on: {{zone_multi}}, initial_entered_zones: {{initial_entered_zones}}, | |
Zone Filter Test: {{'Pass (Multi)' if zone_only and zone_multi and initial_entered_zones|length>0 and zones and (zones | reject('in', initial_entered_zones) |list + initial_entered_zones | reject('in', zones) |list)|length == 0 else 'Pass' if (not zone_only and not zone_multi) or zones|select('in', initial_entered_zones)|list|length > 0 else 'Fail'}}, | |
labels: {{input_labels}}, presence entity/Test: {{presence_entity}}({{'Pass' if not initial_home else 'Fail'}}), disabled times: {{disable_times}}, cooldown: {{cooldown}}s, | |
loitering: {{loitering}}, loiter timer: {{loiter_timer}}, fps: {{fps}}, state filter on: {{state_only}}, | |
state filter entity: {{input_entity}}, acceptable states: {{input_states}}, State Filter test: {{'Pass' if not state_only or states(input_entity) in states_filter else 'Fail' }} | |
- 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: | |
- service: notify.simplepush | |
data: | |
title: "{{title}}" | |
message: "{{message}}" | |
data: | |
attachments: | |
- image: "{{base_url}}/api/frigate/notifications/{{id}}/snapshot.jpg" | |
- video: "{{base_url}}/api/frigate/notifications/{{id}}/{{camera}}/clip.mp4" | |
actions: | |
- action: "Silence {{ camera }}" | |
id: "silence-{{ camera }}" | |
- 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: "{{ 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 }}" | |
sub_label: "{{ event['after']['sub_label']}}" | |
sub_label_changed: "{{ sub_label != event['before']['sub_label'] }}" | |
title: > | |
{% if sub_label %} | |
{{title | replace('A Person', sub_label|title) | replace('Person', sub_label|title)}} | |
{%else%} | |
{{title}} | |
{%endif%} | |
message: > | |
{% if sub_label %} | |
{{message | replace('A Person', sub_label|title) | replace('Person', sub_label|title)}} | |
{%else%} | |
{{message}} | |
{%endif%} | |
- alias: "Debug: write to Log" | |
choose: | |
- conditions: | |
- "{{debug}}" | |
sequence: | |
- service: logbook.log | |
data_template: | |
name: Frigate Notification | |
message: | | |
DEBUG (in loop): new snapshot: {{new_snapshot}}, presence entity enabled/home: {{presence_entity != ''}}/{{home}}, presence changed: {{presence_changed}}, | |
last zones: {{last_zones}}, entered zones: {{entered_zones}}, entered zones changed: {{entered_zones_changed}}, zone filter test: {{'Pass' if zone_filter else 'Fail'}}, | |
stationary moved: {{stationary_moved}}, state filter test: {{'Pass' if state_true else 'Fail'}}, sublabel: {{sub_label}}, | |
sublabel changed: {{sub_label_changed}} | |
- alias: "Notify on loitering or significant change" | |
choose: | |
- conditions: "{{ loitering or (not home and zone_filter and state_true and (presence_changed or zone_only_changed or entered_zones_changed or sub_label_changed)) }}" | |
sequence: | |
- service: notify.simplepush | |
data: | |
title: "{{title}}" | |
message: "{{message}}" | |
data: | |
attachments: | |
- image: "{{base_url}}/api/frigate/notifications/{{id}}/snapshot.jpg" | |
- video: "{{base_url}}/api/frigate/notifications/{{id}}/{{camera}}/clip.mp4" | |
actions: | |
- action: "Silence {{ camera }}" | |
id: "silence-{{ camera }}" | |
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