Skip to content

Instantly share code, notes, and snippets.

@titovskiy
Last active September 24, 2024 08:23
Show Gist options
  • Save titovskiy/8aa161eefb36c71782de33eb03cf1c65 to your computer and use it in GitHub Desktop.
Save titovskiy/8aa161eefb36c71782de33eb03cf1c65 to your computer and use it in GitHub Desktop.
Frigate - Frigate - Telegram Notification With Downloader (blueprint)
blueprint:
name: Frigate - Telegram Notification by Timestamp
description: Скачивает отрезок видео с событием указанной длительности и отправляет уведомление в telegram. Видео автоматически удаляется из HA через минуту после отправки.
domain: automation
source_url: https://gist.github.com/titovskiy/8aa161eefb36c71782de33eb03cf1c65
input:
camera:
name: Frigate Camera
description: Название камеры, как определено в конфигурации Frigate.
chat_id:
name: ID телеграмм чата/бота
baseUrl:
name: Base URL
description: "Внешняя ссылка для отправки снапшота из фригата. Пример: https://ha.domain.com"
frigate_ip:
name: Frigate IP
description: IP адрес Frigate для АПИ запроса
frigate_port:
name: Frigate PORT
description: Ипользуемый Frigate порт для АПИ
default: 5000
frigate_external_url:
name: Frigate URL
description: Внешний адрес для доступа к видео-потокам Frigate
default: ""
video_duration_sec:
name: Длительность видео, секунд
description: Длительность запрашемого отрезка видео по АПИ
default: 20
video_duration_shift_sec:
name: Сдвиг видео, секунд
description: "Сдвиг видео вперед относительно события. Важно! Не должен быть больше или равен длительности видео"
default: 10
send_photo:
name: Отправка фото
default: true
selector:
boolean: {}
send_video:
name: Отправка видео
default: true
selector:
boolean: {}
with_link_stream:
name: Ссылка на видеопоток (beta)
default: false
selector:
boolean: {}
with_link_snapshot:
name: Ссылка на снапшот (beta)
default: false
selector:
boolean: {}
mode: single
max_exceeded: silent
trigger:
- platform: mqtt
topic: frigate/events
value_template: "{{ value_json['after']['camera'] }}"
payload: !input camera
condition:
- condition: template
value_template: "{{ type != 'end' }}"
action:
- parallel:
- service: telegram_bot.send_message
data:
title: Обнаружен объект! Зона - {{ camera }}
message: >
Event id: {{ id }}
{% if with_link_snapshot %}
- <a href="{{ snapshot_external }}">snapshot</a>
{% endif %}
{% if with_link_stream %}
- <a href="{{ live_stream }}">live_stream</a>
{% endif %}
target: "{{ chat_id }}"
disable_web_page_preview: true
parse_mode: html
- if:
- condition: template
value_template: "{{ send_photo }}"
then:
- service: telegram_bot.send_photo
data:
url: "{{ snapshot }}"
target: "{{ chat_id }}"
- if:
- condition: template
value_template: "{{ send_video }}"
then:
- delay:
hours: 0
minutes: 0
seconds: "{{ (10 + (video_duration_shift_sec) | int) | int }}"
milliseconds: 0
- service: telegram_bot.send_video
data:
url: "{{ video }}"
caption: >-
Видео из {{ camera }} за последние {{ video_duration_sec }}
секунд
target: "{{ chat_id }}"
variables:
camera: !input camera
send_photo: !input send_photo
send_video: !input send_video
with_link_snapshot: !input with_link_snapshot
with_link_stream: !input with_link_stream
frigate_ip: !input frigate_ip
frigate_port: !input frigate_port
frigate_external_url: !input frigate_external_url
chat_id: !input chat_id
baseUrl: !input baseUrl
video_duration_sec: !input video_duration_sec
video_duration_shift_sec: !input video_duration_shift_sec
start_timestamp: >-
{{ (as_timestamp(now()) + (video_duration_shift_sec) | int - (video_duration_sec) | int) |
int }}
end_timestamp: "{{ (as_timestamp(now()) + (video_duration_shift_sec) | int) | int }}"
id: "{{ trigger.payload_json['after']['id'] }}"
frigate_url: "http://{{ frigate_ip }}:{{ frigate_port }}/vod/event/{{ id }}/index.m3u8"
video: >-
http://{{ frigate_ip }}:{{ frigate_port }}/api/{{ camera }}/start/{{ start_timestamp
}}/end/{{ end_timestamp }}/clip.mp4
snapshot: "{{ baseUrl }}/api/frigate/notifications/{{ id }}/snapshot.jpg"
#snapshot: "http://{{ frigate_ip }}:{{ frigate_port }}/api/events/{{ id }}/snapshot.jpg"
live_stream: "{{ frigate_external_url }}/vod/event/{{ id }}/index.m3u8"
snapshot_external: "{{ baseUrl }}/api/frigate/notifications/{{ id }}/snapshot.jpg"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment