-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfriagte_ntfy_0.1.yaml
600 lines (594 loc) · 24.6 KB
/
friagte_ntfy_0.1.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
blueprint:
name: Frigate Ntfy Notifications (1.0)
description: |
This blueprint allows you to send notifications via the Ntfy integration when Frigate detects an event.
Customize your notifications with options for camera selection, notification content, priorities, and filters.
Based on https://github.com/SgtBatten/HA_blueprints/blob/main/Frigate%20Camera%20Notifications/Stable
domain: automation
author: shaulbd
input:
camera:
name: Frigate Camera
description: |
Select the camera entity that will trigger notifications.
Ensure the Frigate integration is installed to see cameras listed here.
selector:
entity:
integration: frigate
domain: camera
device_class: camera
notify_device:
name: Notify Device
description: |
Select a notify device created with the Ntfy integration.
For more information, visit https://github.com/ivanmihov/homeassistant-ntfy.sh
default: ""
base_url:
name: Base URL
description: |
The external URL for your Home Assistant instance.
This is used to generate links in the notification.
default: "https://hass.mydomain.com"
ntfy_topic:
name: Notification Topic (Optional)
description: |
Override the default topic assigned with this ntfy configuration.
default: ""
title:
name: Notification Title (Optional)
description: |
The title of the notification.
default: ""
icon:
name: Notification Icon (Optional)
description: |
Path to the icon relative to the www folder. Example: /ntfy/icons/cctv.jpg
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 '.'}}"
custom_value: true
priority:
name: Notification Priority (Optional)
description: |
This priority defines how urgently Android will notify you about the notification, and whether they make a sound and/or vibrate.
By default, messages with default priority or higher (>= 3) will vibrate and make a sound.
Messages with high or urgent priority (>= 4) will also show as pop-over.
default: ""
selector:
select:
options:
- "1"
- "2"
- "3"
- "4"
- "5"
- "{{'5' if now().hour in [8,9,10,11,12,13,14,15,16,17,18] else '1'}}"
- "{{'1' if is_state('sun.sun', 'above_horizon') else '5' }}"
custom_value: true
alert_once:
name: Alert Once (Optional)
description: |
Only the first notification for each event will play a sound. Subsequent notifications, including updates, will be silent.
default: true
selector:
boolean:
attachment:
name: Attachment Type
description: |
Choose which image to attach to the notification.
default: thumbnail
selector:
select:
options:
- label: Thumbnail
value: thumbnail
- label: Snapshot
value: snapshot
update_thumbnail:
name: Update Attachment (Optional)
description: |
Update the notification if a new "better" image is available.
default: false
selector:
boolean:
tags:
name: Notification Tags (Optional)
description: |
Tag messages with relevant strings or emojis like 🥳 🎉. Tags are automatically converted to emojis.
default: ""
selector:
select:
options:
- door
- man
- boy
- woman
- rotating_light
- warning
- no_entry
custom_value: true
multiple: true
zone_filter:
name: Zone Filter on/off (Optional)
description: |
Enable to notify only if the object has entered a specified zone.
default: false
selector:
boolean:
zones:
name: Required Zones (Optional - Enabled Above)
description: |
Enter the names of zones as per your Frigate configuration. Use underscores where necessary.
To require all listed zones to be entered before notifying, enable the Multi Zone option below.
default: []
selector:
select:
options:
- examples
- porch
- front_door
- side
- garden
- entrance
multiple: true
custom_value: true
zone_multi:
name: Multi Zone (Optional)
description: |
Require all specified zones to be entered before notifying. Zone Filter must be enabled.
default: false
selector:
boolean:
labels:
name: Object Filter (Optional)
description: |
Enter or select one object at a time to filter notifications based on object type.
default: ""
selector:
select:
options:
- person
- dog
- cat
- car
- package
- bird
multiple: true
custom_value: true
presence_filter:
name: Presence Filter (Optional)
description: |
Only notify if the 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 to notify only if a selected entity is in specified states.
default: false
selector:
boolean:
state_entity:
name: State Filter Entity (Optional)
description: |
Notify only if the selected entity is in the specified state(s). State Filter must be enabled.
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:
options: []
multiple: true
custom_value: true
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 the same object.
Example: If cooldown is 5 minutes, no new notifications for the same object within that time.
default: 30
selector:
number:
max: 300
min: 0
unit_of_measurement: seconds
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
click_action:
name: Click Action URL (Optional)
description: |
The URL to open when clicking on the notification. Some presets are provided, or you can set your own.
An empty value will open the ntfy app.
default: ""
selector:
select:
options:
- label: View Clip
value: "{{base_url}}/api/frigate/notifications/{{id}}/{{camera}}/clip.mp4"
- label: View Snapshot
value: "{{base_url}}/api/frigate/notifications/{{id}}/snapshot.jpg"
- label: View Stream
value: "{{base_url}}/api/camera_proxy_stream/camera.{{trigger.payload_json['after']['camera'].lower()}}?token={{state_attr( 'camera.' ~ camera, 'access_token')}}"
- label: Open Home Assistant (web)
value: "{{base_url}}/lovelace"
- label: Open Home Assistant (app)
value: /lovelace
- label: Open Frigate
value: /ccab4aaf_frigate/dashboard
- label: Open Frigate (Full Access)
value: /ccab4aaf_frigate-fa/dashboard
- label: Open Frigate (proxy)
value: /ccab4aaf_frigate-proxy/dashboard
custom_value: true
button_1:
name: Button 1 Label
description: "The text used on the first Action button at the bottom of the notification. Set the action below. Default is View Clip"
default: "View Clip"
action_1:
name: Button 1 Action
description: |
Customise what happens when you press the first Action Button. Select from one of the preconfigured options or enter your own custom configuration.
Please refer to: https://docs.ntfy.sh/publish/?h=action#action-buttons
default: |
{
"action": "view",
"label": "{{button_1}}",
"url": "{{base_url}}/api/frigate/notifications/{{id}}/{{camera}}/clip.mp4"
}
selector:
select:
options:
- label: View Clip
value: |
{
"action": "view",
"label": "{{button_1}}",
"url": "{{base_url}}/api/frigate/notifications/{{id}}/{{camera}}/clip.mp4"
}
- label: View Snapshot
value: |
{
"action": "view",
"label": "{{button_1}}",
"url": "{{base_url}}/api/frigate/notifications/{{id}}/snapshot.jpg"
}
- label: View Stream
value: |
{
"action": "view",
"label": "{{button_1}}",
"url": "{{base_url}}/api/camera_proxy_stream/camera.{{trigger.payload_json['after']['camera'].lower()}}?token={{state_attr( 'camera.' ~ camera, 'access_token')}}"
}
custom_value: true
button_2:
name: Button 2 Label
description: "The text used on the second Action button at the bottom of the notification. Set the action below. Default is View Snapshot"
default: "View Snapshot"
action_2:
name: Button 2 Action
description: |
Customise what happens when you press the second Action Button. Select from one of the preconfigured options or enter your own custom configuration.
Please refer to: https://docs.ntfy.sh/publish/?h=action#action-buttons
default: |
{
"action": "view",
"label": "{{button_2}}",
"url": "{{base_url}}/api/frigate/notifications/{{id}}/snapshot.jpg"
}
selector:
select:
options:
- label: View Clip
value: |
{
"action": "view",
"label": "{{button_2}}",
"url": "{{base_url}}/api/frigate/notifications/{{id}}/{{camera}}/clip.mp4"
}
- label: View Snapshot
value: |
{
"action": "view",
"label": "{{button_2}}",
"url": "{{base_url}}/api/frigate/notifications/{{id}}/snapshot.jpg"
}
- label: View Stream
value: |
{
"action": "view",
"label": "{{button_2}}",
"url": "{{base_url}}/api/camera_proxy_stream/camera.{{trigger.payload_json['after']['camera'].lower()}}?token={{state_attr( 'camera.' ~ camera, 'access_token')}}"
}
custom_value: true
button_3:
name: Button 3 Label
description: "The text used on the third Action button at the bottom of the notification. Set the action below. Default is View Stream"
default: "View Stream"
action_3:
name: Button 3 Action
description: |
Customise what happens when you press the third Action Button. Select from one of the preconfigured options or enter your own custom configuration.
Please refer to: https://docs.ntfy.sh/publish/?h=action#action-buttons
default: |
{
"action": "view",
"label": "{{button_3}}",
"url": "{{base_url}}/api/camera_proxy_stream/camera.{{trigger.payload_json['after']['camera'].lower()}}?token={{state_attr( 'camera.' ~ camera, 'access_token')}}"
}
selector:
select:
options:
- label: View Clip
value: |
{
"action": "view",
"label": "{{button_3}}",
"url": "{{base_url}}/api/frigate/notifications/{{id}}/{{camera}}/clip.mp4"
}
- label: View Snapshot
value: |
{
"action": "view",
"label": "{{button_3}}",
"url": "{{base_url}}/api/frigate/notifications/{{id}}/snapshot.jpg"
}
- label: View Stream
value: |
{
"action": "view",
"label": "{{button_3}}",
"url": "{{base_url}}/api/camera_proxy_stream/camera.{{trigger.payload_json['after']['camera'].lower()}}?token={{state_attr( 'camera.' ~ camera, 'access_token')}}"
}
custom_value: true
mode: parallel
trigger_variables:
input_camera: !input camera
camera: "{{ input_camera | replace('camera.', '') }}"
trigger:
- 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 }}"
input_base_url: !input base_url
base_url: "{{ input_base_url.rstrip('/')}}"
input_icon: !input icon
icon: "{{ input_icon.lstrip('/')}}"
attachment: !input attachment
priority_input: !input priority
priority: "{{ priority_input }}"
alert_once: !input alert_once
update_thumbnail: !input update_thumbnail
device: !input notify_device
group_target: "{{ group | lower | replace('notify.', '') | replace(' ','_') }}"
notify_target: "{{ device | lower | replace('notify.', '') | replace(' ','_') }}"
zone_only: !input zone_filter
input_zones: !input zones
zones: "{{ input_zones | list | lower }}"
zone_multi: !input zone_multi
input_labels: !input labels
labels: "{{ input_labels | list | lower }}"
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 | lower }}"
tags: !input tags
action:
- choose:
- 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'] |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 }}"
# Customisation of text
title: !input title
ntfy_topic: !input ntfy_topic
message: !input message
priority: !input priority
tags: !input tags
click_action: !input click_action
button_1: !input button_1
button_2: !input button_2
button_3: !input button_3
action_1: !input action_1
action_2: !input action_2
action_3: !input action_3
action_1_payload: "{{ action_1 | replace('{\"', '{',1) | replace('\"}', '}',1) }}"
action_2_payload: "{{ action_2 | replace('{\"', '{',1) | replace('\"}', '}',1) }}"
action_3_payload: "{{ action_3 | replace('{\"', '{',1) | replace('\"}', '}',1) }}"
- 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:
- service: "notify.{{ notify_target }}"
data:
title: "{{title}}"
message: "{{message}}"
data:
topic: "{{ntfy_topic}}"
click: "{{click_action}}"
icon: "{{base_url}}/local/{{icon}}"
tags: "{{tags}}"
priority: "{{priority}}"
image: "{{base_url}}/api/frigate/notifications/{{id}}/{{attachment}}.jpg?format=android"
actions: |
[{{action_1_payload}},{{action_2_payload}},{{action_3_payload}}]
- 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) }}"
priority: !input priority
tags: !input tags
click_action: !input click_action
ntfy_topic: !input ntfy_topic
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: "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:
- service: "notify.{{ notify_target }}"
data:
title: "{{title}}"
message: "{{message}}"
data:
topic: "{{ntfy_topic}}"
click: "{{click_action}}"
icon: "{{base_url}}/local/{{icon}}"
priority: "{{priority}}"
tags: "{{tags}}"
image: "{{base_url}}/api/frigate/notifications/{{id}}/{{attachment}}.jpg?format=android"
actions: |
[{{action_1_payload}},{{action_2_payload}},{{action_3_payload}}]
until: "{{ not wait.trigger or wait.trigger.payload_json['type'] == 'end' }}"
#trace:
# stored_traces: 15