Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dimitrystd/76770fee73496f928c7967be3842eb44 to your computer and use it in GitHub Desktop.
Save dimitrystd/76770fee73496f928c7967be3842eb44 to your computer and use it in GitHub Desktop.
Frigate - Telegram Notification
blueprint:
name: Frigate - Telegram Notification
description: Create automations to receive Snapshots and Clips from Frigate
domain: automation
input:
camera:
name: Frigate Camera
description:
The name of the camera as defined in your frigate configuration (/conf.yml).
target_chat:
name: Target
description:
"The chat_id to be used by the Telegram bot. !secret chat_id is
not allowed on Blueprint, you will need the chat_id code."
notification_photo:
name: Disable photo notification
description: "True/false for send the message with photo silently"
default: false
selector:
boolean:
notification_video:
name: Disable video notification
description: "True/false for send the message with video silently"
default: false
selector:
boolean:
message_caption:
name: (Optional) The title of the photo\video
description: User-friendly text
default: "Motion detected:"
message_tag:
name: (Optional) Tag for sent message
description: Can be usuful for your automation
default: ""
base_url:
name: (Optional) Base URL
description:
The external url for your Home Assistant instance. This will default
to a relative URL and will open the clips in the app instead of the browser,
which may cause issues on some devices.
default: ""
zone_filter:
name: (Optional) Zone Filter
description: Only notify if object has entered a defined zone.
default: false
selector:
boolean:
zones:
name: (Optional) Trigger Zones
description: A list (-) of zones you wish to recieve notifications for.
default: []
selector:
object: {}
labels:
name: (Optional) Trigger Objects
description: A list (-) of objects you wish to recieve notifications for.
default: []
selector:
object: {}
presence_filter:
name: (Optional) Presence Filter
description: Only notify if selected presence entity is not "home".
default: ""
selector:
entity: {}
source_url: https://gist.github.com/dimitrystd/76770fee73496f928c7967be3842eb44
mode: single
max_exceeded: silent
trigger:
platform: mqtt
topic: frigate/events
payload: !input "camera"
value_template: "{{ value_json['after']['camera'] }}"
variables:
id: "{{ trigger.payload_json['after']['id'] }}"
camera: "{{ trigger.payload_json['after']['camera'] }}"
camera_name: "{{ camera | replace('_', ' ') | title }}"
target_chat: !input target_chat
object: "{{ trigger.payload_json['after']['label'] }}"
label: "{{ object | title }}"
entered_zones: "{{ trigger.payload_json['after']['entered_zones'] }}"
type: "{{ trigger.payload_json['type'] }}"
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
message_caption: !input message_caption
condition:
- "{{ type != 'end' }}"
- "{{ not zone_only or entered_zones|length > 0 }}"
- "{{ not zones|length or zones|select('in', entered_zones)|list|length > 0 }}"
- "{{ not labels|length or object in labels }}"
- "{{ not presence_entity or not is_state(presence_entity, 'home') }}"
action:
- service: telegram_bot.send_photo
alias: Send photo
data:
target: !input target_chat
disable_notification: !input notification_photo
caption: "{{message_caption}} {{ camera_name }}"
url: "{{base_url}}/api/events/{{id}}/snapshot.jpg"
message_tag: !input message_tag
- 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
- condition: template
value_template: "{{ wait.trigger.payload_json['type'] == 'end' }}"
- alias: Extra delay before getting video file
delay: 5
- service: telegram_bot.send_video
alias: Send video
data:
target: !input target_chat
disable_notification: !input notification_video
caption: "{{message_caption}} {{ camera_name }}"
url: "{{base_url}}/api/events/{{id}}/clip.mp4"
timeout: 20
message_tag: !input message_tag
until: "{{ wait.trigger.payload_json['type'] == 'end' }}"
@dimitrystd
Copy link
Author

dimitrystd commented Jul 16, 2022

Changes

2022-07-18

  • Added two options to control notification: notification_photo and notification_video
  • Added options to control message_caption and message_tag. The last one is useful for external automation
  • Formatted code with HA code conventions

2022-07-15

  • Updated URLs for snapshot and video clip. My frigate (v0.9.4) and HTTP API documentation uses another URL pattern
  • Use english string for caption
  • Added 5 sec delay before downloading clip. I randomly got 404 status without it (no issues with the snapshot)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment