Thanks for your work.
I’ve also issue with notifications. Notification test by dev tools is ok.
The code :
alias: Frigate Notifications
description: ""
use_blueprint:
path: SgtBatten/Stable.yaml
input:
camera: camera.r4252_smart_outdoor_camera_2
notify_device: 1336b603037d01a61d6de3e445a6
message: Un mouvement a été détecté dehors
attachment: snapshot
update_thumbnail: false
The automation config :
mode: parallel
trigger_variables:
input_camera: camera.r4252_smart_outdoor_camera_2
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 | replace('-','_') }}/{{
value_json['type']}}
id: frigate-event
variables:
input_camera: camera.r4252_smart_outdoor_camera_2
camera: '{{ input_camera | replace(''camera.'', '''') }}'
camera_name: '{{ camera | replace(''_'', '' '') | title }}'
input_base_url: ''
base_url: '{{ input_base_url.rstrip(''/'')}}'
attachment: snapshot
critical_input: 'false'
critical: '{{ true if critical_input == ''true'' else false }}'
alert_once: false
update_thumbnail: false
ios_live_view: false
group: ''
group_target: '{{ group | lower | replace(''notify.'', '''') | replace('' '',''_'') }}'
zone_only: false
input_zones: []
zones: '{{ input_zones | list | lower }}'
zone_multi: false
input_labels: ''
labels: '{{ input_labels | list | lower }}'
presence_entity: ''
disable_times: []
cooldown: 30
loitering: false
loiter_timer: 0
fps: '{{ states(''sensor.'' + camera + ''_camera_fps'')|int(5) }}'
state_only: false
input_entity: ''
input_states: []
states_filter: '{{ input_states | list | lower }}'
color: steelblue
sound: default
tv: false
tv_position: center
tv_size: large
tv_duration: 10
tv_transparency: 0%
tv_interrupt: false
debug: false
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: 30
- 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 }}'
initial_home: >-
{{ presence_entity != '' and is_state(presence_entity, 'home')
}}
initial_entered_zones: '{{ trigger.payload_json[''after''][''entered_zones''] |lower}}'
zone_multi_filter: >-
{{zone_only and zone_multi and initial_entered_zones|length and
zones and zones |reject('in', initial_entered_zones) |list
|length == 0 }}
title: ''
message: Un mouvement a été détecté dehors
tap_action: >-
{{base_url}}/api/frigate/notifications/{{id}}/{{camera}}/clip.mp4
button_1: View Clip
button_2: View Snapshot
button_3: Silence New Notifications
url_1: >-
{{base_url}}/api/frigate/notifications/{{id}}/{{camera}}/clip.mp4
url_2: '{{base_url}}/api/frigate/notifications/{{id}}/snapshot.jpg'
url_3: silence-{{ camera }}
icon: mdi:home-assistant
channel: ''
- alias: 'Debug: write to Log'
choose:
- conditions:
- '{{debug}}'
sequence:
- service: logbook.log
data_template:
name: Frigate Notification
message: |
DEBUG:
Info:
fps: {{fps}},
frigate event id: {{id}},
object (formatted): {{object}} ({{label}}),
Config:
camera(formatted): {{camera}}({{camera_name}}),
Base URL: {{base_url}},
critical: {{critical}},
alert once: {{alert_once}},
Update Thumbnails: {{update_thumbnail}},
Target: {{'group (input/formatted): ' + group + '/' + group_target + ', ' if group else 'Mobile Device'}}
cooldown: {{cooldown}}s,
loiter timer: {{loiter_timer}}s,
color: {{color}},
sound: {{sound}},
Title: {{title}},
Message: {{message}},
tap_action: {{tap_action}},
button 1 Text/URL: {{iif(button_1, button_1, 'unset')}} ({{url_1}}),
button 2 Text/URL: {{button_2}} ({{url_2}}),
button 3 Text/URL: {{button_3}} ({{url_3}}),
icon: {{icon}}
tv: {{tv}},
tv_position: {{tv_position}},
tv_size: {{tv_size}},
tv_duration: {{tv_duration}},
tv_transparency: {{tv_transparency}},
tv_interrupt: {{tv_interrupt}},
Filters:
Zones:
zone filter toggle on: {{zone_only}},
Multi Zone toggle on: {{zone_multi}},
Required zones: {{input_zones}},
Entered Zones: {{initial_entered_zones}},
Zone Filter TEST: {{'PASS (Multi)' if zone_multi_filter else 'PASS' if ( not zone_only or not zone_multi and zones|select('in', initial_entered_zones)|list|length ) else 'FAIL (Multi)' if zone_multi else 'FAIL' }},
Required objects TEST:
Input: {{input_labels}},
TEST: {{'PASS' if not labels|length or object in labels else 'FAIL'}}
presence entity (not home):
Entity: {{presence_entity}}
TEST: {{'PASS' if not initial_home else 'FAIL'}},
disabled times: {{disable_times}},
State Filter:
state filter toggle on: {{state_only}},
state filter entity: {{input_entity}},
required 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 (not zone_multi and zones|select('in',
initial_entered_zones)|list|length > 0) or (zone_multi and
initial_entered_zones|length > 0 and zones |reject('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: 1336b603037d01a61d6de3e445a6
domain: mobile_app
type: notify
title: '{{title}}'
message: '{{message}}'
data:
tag: '{{ id }}'
group: '{{ camera }}-frigate-notification'
color: '{{color}}'
image: >-
/api/frigate/notifications/{{id}}/{{attachment}}.jpg?format=android
clickAction: '{{tap_action}}'
ttl: '{{ iif(critical, 0, 3600000) }}'
priority: '{{ iif(critical, ''high'', ''normal'') }}'
notification_icon: '{{icon}}'
channel: '{{channel}}'
url: '{{tap_action}}'
attachment:
url: >-
/api/frigate/notifications/{{id}}/{{attachment}}.jpg
push:
sound: '{{sound}}'
interruption-level: '{{ iif(critical, ''critical'', ''active'') }}'
entity_id: '{{ iif(ios_live_view, input_camera, '''' ) }}'
actions:
- action: URI
title: '{{button_1}}'
uri: '{{url_1}}'
- action: URI
title: '{{button_2}}'
uri: '{{url_2}}'
- action: '{{ ''URI'' if ''/'' in url_3 else url_3 }}'
title: '{{button_3}}'
uri: '{{url_3}}'
destructive: true
- conditions: '{{ tv }}'
sequence:
- service: notify.{{ group_target }}
data:
title: '{{title}}'
message: '{{message}}'
data:
tag: '{{ id }}'
group: '{{ camera }}-frigate-notification'
color: '{{color}}'
clickAction: '{{tap_action}}'
ttl: '{{ iif(critical, 0, 3600000) }}'
priority: '{{ iif(critical, ''high'', ''normal'') }}'
notification_icon: '{{icon}}'
channel: '{{channel}}'
image:
url: >-
{{base_url}}/api/frigate/notifications/{{id}}/snapshot.jpg
fontsize: '{{tv_size}}'
position: '{{tv_position}}'
duration: '{{tv_duration}}'
transparency: '{{tv_transparency}}'
interrupt: '{{tv_interrupt}}'
timeout: 30
url: '{{tap_action}}'
attachment:
url: >-
/api/frigate/notifications/{{id}}/{{attachment}}.jpg
push:
sound: '{{sound}}'
interruption-level: '{{ iif(critical, ''critical'', ''active'') }}'
entity_id: '{{ iif(ios_live_view, input_camera, '''' ) }}'
actions:
- action: URI
title: '{{button_1}}'
uri: '{{url_1}}'
- action: URI
title: '{{button_2}}'
uri: '{{url_2}}'
- action: '{{ ''URI'' if ''/'' in url_3 else url_3 }}'
title: '{{button_3}}'
uri: '{{url_3}}'
destructive: true
default:
- service: notify.{{ group_target }}
data:
title: '{{title}}'
message: '{{message}}'
data:
tag: '{{ id }}{{''-loitering'' if loitering}}'
group: >-
{{ camera }}-frigate-notification{{'-loitering' if
loitering}}
color: '{{color}}'
image: >-
/api/frigate/notifications/{{id}}/{{attachment}}.jpg?format=android
clickAction: '{{tap_action}}'
ttl: '{{ iif(critical, 0, 3600000) }}'
priority: '{{ iif(critical, ''high'', ''normal'') }}'
notification_icon: '{{icon}}'
channel: '{{channel}}'
fontsize: '{{tv_size}}'
position: '{{tv_position}}'
duration: '{{tv_duration}}'
transparency: '{{tv_transparency}}'
interrupt: '{{tv_interrupt}}'
url: '{{tap_action}}'
attachment:
url: >-
/api/frigate/notifications/{{id}}/{{attachment}}.jpg
push:
sound: '{{sound}}'
interruption-level: '{{ iif(critical, ''critical'', ''active'') }}'
entity_id: '{{ iif(ios_live_view, input_camera, '''' ) }}'
actions:
- action: URI
title: '{{button_1}}'
uri: '{{url_1}}'
- action: URI
title: '{{button_2}}'
uri: '{{url_2}}'
- action: '{{ ''URI'' if ''/'' in url_3 else url_3 }}'
title: '{{button_3}}'
uri: '{{url_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''] |lower}}'
entered_zones: '{{ event[''after''][''entered_zones''] |lower}}'
zone_filter: >-
{{ not zone_only or zones|select('in',
entered_zones)|list|length > 0 }}
zone_multi_filter: >-
{{not zone_only or not zone_multi or (
entered_zones|list|length > 0 and zones and
zones|reject('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''] }}'
update: >-
{{ alert_once or (new_snapshot and not loitering and not
presence_changed and not zone_only_changed and not
entered_zones_changed and not sub_label_changed) }}
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):
Info:
Last Zones: {{last_zones}},
Current zones: {{entered_zones}},
sublabel: {{sub_label}},
iOS sound: {{update if not critical else 'yes due critical notifications'}},
Android Sound: {{'disabled by alert once' if alert_once else 'enabled'}},
Triggers:
New Snapshot: {{new_snapshot}},
Presence Changed: {{presence_changed}},
stationary moved: {{stationary_moved}},
entered zones changed: {{entered_zones_changed}},
sublabel changed: {{sub_label_changed}},
Conditions:
Loitering: {{loitering}}
or
Presence Entity not home: {{'ON' if presence_entity != '' else 'OFF'}} - {{'PASS' if not home else 'FAIL'}},
zone filter TEST: {{'ON' if zone_only else 'OFF'}} - {{'PASS' if zone_filter else 'FAIL'}},
multi-zone filter: {{'OFF' if not zone_only or not zone_multi else 'ON'}} - {{'PASS' if not zone_only or not zone_multi or ( entered_zones|length and zones and zones |reject('in', entered_zones) |list |length == 0 ) else 'FAIL'}},
state filter TEST: {{'ON' if state_only else 'OFF'}} - {{'PASS' if state_true else 'FAIL'}}
image: "/api/frigate/notifications/{{id}}/{{attachment}}.jpg"
- alias: Notify on loitering or significant change
choose:
- conditions: >-
{{ loitering or (not home and zone_filter and
zone_multi_filter and state_true and (new_snapshot or
presence_changed or stationary_moved or
zone_only_changed or entered_zones_changed or
sub_label_changed)) }}
sequence:
- choose:
- conditions: '{{ not group_target }}'
sequence:
- device_id: 1336b603037d01a61d6de3e445a6
domain: mobile_app
type: notify
title: '{{title}}'
message: '{{message}}'
data:
tag: '{{ id }}{{''-loitering'' if loitering}}'
group: >-
{{ camera
}}-frigate-notification{{'-loitering' if
loitering}}
color: '{{color}}'
image: >-
/api/frigate/notifications/{{id}}/{{attachment}}.jpg?format=android
clickAction: '{{tap_action}}'
ttl: '{{ iif(critical, 0, 3600000) }}'
priority: '{{ iif(critical, ''high'', ''normal'') }}'
alert_once: '{{ alert_once }}'
notification_icon: '{{icon}}'
channel: '{{channel}}'
url: '{{tap_action}}'
attachment:
url: >-
/api/frigate/notifications/{{id}}/{{attachment}}.jpg
push:
sound: '{{ iif(update, ''none'', sound) }}'
interruption-level: >-
{{ iif(critical, 'critical', 'active')
}}
entity_id: >-
{{ iif(ios_live_view, input_camera, '' )
}}
actions:
- action: URI
title: '{{button_1}}'
uri: '{{url_1}}'
- action: URI
title: '{{button_2}}'
uri: '{{url_2}}'
- action: '{{ ''URI'' if ''/'' in url_3 else url_3 }}'
title: '{{button_3}}'
uri: '{{url_3}}'
destructive: true
- conditions: '{{ tv }}'
sequence:
- service: notify.{{ group_target }}
data:
title: '{{title}}'
message: '{{message}}'
data:
tag: '{{ id }}{{''-loitering'' if loitering}}'
group: >-
{{ camera
}}-frigate-notification{{'-loitering' if
loitering}}
color: '{{color}}'
clickAction: '{{tap_action}}'
ttl: '{{ iif(critical, 0, 3600000) }}'
priority: '{{ iif(critical, ''high'', ''normal'') }}'
alert_once: '{{ alert_once }}'
notification_icon: '{{icon}}'
channel: '{{channel}}'
image:
url: >-
{{base_url}}/api/frigate/notifications/{{id}}/snapshot.jpg
fontsize: '{{tv_size}}'
position: '{{tv_position}}'
duration: '{{tv_duration}}'
transparency: '{{tv_transparency}}'
interrupt: '{{tv_interrupt}}'
timeout: 30
url: '{{tap_action}}'
attachment:
url: >-
/api/frigate/notifications/{{id}}/{{attachment}}.jpg
push:
sound: '{{ iif(update, ''none'', sound) }}'
interruption-level: >-
{{ iif(critical, 'critical', 'active')
}}
entity_id: >-
{{ iif(ios_live_view, input_camera, '' )
}}
actions:
- action: URI
title: '{{button_1}}'
uri: '{{url_1}}'
- action: URI
title: '{{button_2}}'
uri: '{{url_2}}'
- action: '{{ ''URI'' if ''/'' in url_3 else url_3 }}'
title: '{{button_3}}'
uri: '{{url_3}}'
destructive: true
default:
- service: notify.{{ group_target }}
data:
title: '{{title}}'
message: '{{message}}'
data:
tag: '{{ id }}{{''-loitering'' if loitering}}'
group: >-
{{ camera
}}-frigate-notification{{'-loitering' if
loitering}}
color: '{{color}}'
image: >-
/api/frigate/notifications/{{id}}/{{attachment}}.jpg?format=android
clickAction: '{{tap_action}}'
ttl: '{{ iif(critical, 0, 3600000) }}'
priority: '{{ iif(critical, ''high'', ''normal'') }}'
alert_once: '{{ alert_once }}'
notification_icon: '{{icon}}'
channel: '{{channel}}'
fontsize: '{{tv_size}}'
position: '{{tv_position}}'
duration: '{{tv_duration}}'
transparency: '{{tv_transparency}}'
interrupt: '{{tv_interrupt}}'
url: '{{tap_action}}'
attachment:
url: >-
/api/frigate/notifications/{{id}}/{{attachment}}.jpg
push:
sound: '{{ iif(update, ''none'', sound) }}'
interruption-level: '{{ iif(critical, ''critical'', ''active'') }}'
entity_id: '{{ iif(ios_live_view, input_camera, '''' ) }}'
actions:
- action: URI
title: '{{button_1}}'
uri: '{{url_1}}'
- action: URI
title: '{{button_2}}'
uri: '{{url_2}}'
- action: '{{ ''URI'' if ''/'' in url_3 else url_3 }}'
title: '{{button_3}}'
uri: '{{url_3}}'
destructive: true
until: >-
{{ not wait.trigger or wait.trigger.payload_json['type'] ==
'end' }}
id: '1714482324845'
alias: Frigate Notifications
description: ''
Trace timeline:
Triggered manually at April 30, 2024 at 3:25:25 PM
Choose: No action executed
Finished at April 30, 2024 at 3:25:25 PM (runtime: 0.00 seconds)