Last active
December 8, 2024 12:35
-
-
Save MrRaph/3a1b1959d716413536c7b9f520e4f968 to your computer and use it in GitHub Desktop.
This file contains hidden or 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: Frigate Notification (0.0.6) via Matrix | |
description: | | |
## Frigate Notification via Matrix | |
Ce blueprint envoie une notification via Matrix lorsqu'un événement Frigate se produit pour la caméra sélectionnée. | |
Le message inclut une image de la détection, ainsi que des liens pour voir le clip et le snapshot. | |
### Paramètres requis : | |
- Nom de la caméra Frigate | |
- Cible Matrix (une salle ou un utilisateur) | |
### Options : | |
- Notification critique (option ignorée, car Matrix ne gère pas ce concept) | |
- Mise à jour de la miniature (si une nouvelle image est disponible) | |
- Filtrage par zone et par type d'objet | |
- Filtrage par présence à la maison | |
- Cooldown entre notifications | |
- Temporisation pour ignorer les nouvelles notifications | |
- Notification de "loitering" (objet stationnaire) | |
domain: automation | |
source_url: https://www.home-assistant.io/integrations/matrix/ | |
input: | |
camera: | |
name: Frigate Camera | |
description: Le nom de la caméra tel que défini dans votre configuration frigate. | |
matrix_target: | |
name: Cible Matrix | |
description: "L'ID de la room (ex: !roomid:matrix.org) ou l'ID utilisateur Matrix à notifier." | |
selector: | |
text: | |
base_url: | |
name: (Optionnel) Base URL | |
description: > | |
URL externe de votre instance Home Assistant. Par défaut utilise une URL relative. | |
default: "" | |
critical: | |
name: (Optionnel) Notification critique | |
description: Option non prise en compte pour Matrix. | |
default: false | |
selector: | |
boolean: | |
update_thumbnail: | |
name: (Optionnel) Mise à jour de la miniature | |
description: Mettre à jour la notification si une nouvelle miniature est disponible. | |
default: false | |
selector: | |
boolean: | |
zone_filter: | |
name: (Optionnel) Filtrage par zone | |
description: Notifier uniquement si l'objet entre dans une zone définie. | |
default: false | |
selector: | |
boolean: | |
zones: | |
name: (Optionnel) Zones ciblées | |
description: Liste des zones pour lesquelles vous souhaitez recevoir des notifications. | |
default: [] | |
selector: | |
object: | |
labels: | |
name: (Optionnel) Objets ciblés | |
description: Liste des objets pour lesquels vous souhaitez recevoir des notifications. | |
default: [] | |
selector: | |
object: | |
presence_filter: | |
name: (Optionnel) Filtre de présence | |
description: Notifier uniquement si l'entité de présence n'est pas "home". | |
default: "" | |
selector: | |
entity: | |
cooldown: | |
name: (Optionnel) Cooldown | |
description: Délai avant d'envoyer une nouvelle notification pour cette caméra après le dernier événement. | |
default: 30 | |
selector: | |
number: | |
max: 300 | |
min: 0 | |
unit_of_measurement: seconds | |
silence_timer: | |
name: (Optionnel) Temporisation du silence | |
description: > | |
Durée pendant laquelle on ne recevra plus de notifications si demandé (en minutes). | |
default: 30 | |
selector: | |
number: | |
max: 300 | |
min: 0 | |
unit_of_measurement: minutes | |
loiter_timer: | |
name: (Optionnel) Détection de loitering | |
description: > | |
Envoie une notification si un objet stationnaire est détecté plus longtemps | |
que le temps spécifié (en minutes). 0 = désactivé. | |
default: 0 | |
selector: | |
number: | |
max: 300 | |
min: 0 | |
unit_of_measurement: minutes | |
mode: parallel | |
trigger_variables: | |
camera: !input 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'] }}/{{ value_json['type']}}" | |
id: frigate-event | |
variables: | |
camera: !input camera | |
camera_name: "{{ camera | replace('_', ' ') | title }}" | |
base_url: !input base_url | |
critical: !input critical | |
update_thumbnail: !input update_thumbnail | |
matrix_target: !input matrix_target | |
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_value: "{{ states('sensor.' + camera + '_camera_fps') }}" | |
fps: "{{ fps_value|int if is_number(fps_value) else 5 }}" | |
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 }}" | |
initial_home: "{{ presence_entity != '' and is_state(presence_entity, 'home') }}" | |
initial_entered_zones: "{{ trigger.payload_json['after']['entered_zones'] }}" | |
- alias: "Notifications enabled for object label" | |
condition: template | |
value_template: "{{ not labels|length or object in labels }}" | |
- action: downloader.download_file | |
data: | |
url: >- | |
http://localhost:8123/api/frigate/notifications/{{id}}/snapshot.jpg | |
filename: frigate_snapshot.jpg | |
overwrite: true | |
- delay: '00:00:02' | |
- 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 }}" | |
sequence: | |
- service: matrix.send_message | |
data: | |
target: "{{ matrix_target }}" | |
message: > | |
A {{ label }} was detected on the {{ camera_name }} camera. | |
data: | |
images: "/media/frigate_snapshot.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 | |
- 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 }}" | |
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) }}" | |
update: "{{ 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 (new_snapshot or presence_changed or stationary_moved or zone_only_changed or entered_zones_changed)) }}" | |
sequence: | |
- service: matrix.send_message | |
data: | |
target: "{{ matrix_target }}" | |
message: > | |
A {{ label }} was detected on the {{ camera_name }} camera. | |
data: | |
images: "/media/frigate_snapshot.jpg" | |
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