Skip to content

Instantly share code, notes, and snippets.

@NdR91
Last active April 19, 2025 16:46
Show Gist options
  • Save NdR91/5486a1e55101e062c48545395b7dd9a3 to your computer and use it in GitHub Desktop.
Save NdR91/5486a1e55101e062c48545395b7dd9a3 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:
name: Notification
description: 'Select "true" to disable notification, lave "false" to receive
notification.
'
selector:
select:
options:
- 'true'
- 'false'
default: 'false'
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/NdR91/5486a1e55101e062c48545395b7dd9a3
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'
notification: !input 'notification'
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
data:
target: '{{ target_chat }}'
disable_notification: '{{ notification }}'
caption: |
Movimento rilevato. Telecamera: {{ camera_name }} (ID: {{ id }})
url: >-
{{base_url}}/api/frigate/notifications/{{id}}/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
- condition: template
value_template: '{{ wait.trigger.payload_json[''type''] == ''end'' }}'
- service: telegram_bot.send_video
data:
target: '{{ target_chat }}'
disable_notification: '{{ notification }}'
caption: 'Movimento rilevato. Telecamera: {{ camera_name }}'
url: >-
{{base_url}}/api/frigate/notifications/{{id}}/{{camera}}/clip.mp4
until: '{{ wait.trigger.payload_json[''type''] == ''end'' }}'
@borgqueenx
Copy link

i see it is not working because i defined some zones.
I removed the zones and it works.
In the field for zones, i tried (zone_name), zone_name and -zone_name. I don't know how we should enter the zones. But as soon as filtering is on and i define the zone, it stops working. tried on two camera's, both stop working then for telegram notifications. But when i disable zone filtering, it works immediately.
would love some assistance there.

@borgqueenx
Copy link

So it was adding lines/minus characters to get it fixed.

  • zone_0
  • zone_1

Now working good, except that sometimes i do not get videos send. Photos are always being send, videos only sometimes. Could the video file be too big? Or too short after another? How can i debug? In frigate the events can be played without a problem.

@fama-lama
Copy link

@borgqueenx I had the same issue too. The only thing that seemed to help is adding timeout: 1000 like this.

- service: telegram_bot.send_video
      data:
        target: '{{ target_chat }}'
        disable_notification: '{{ notification }}'
        caption: 'Movimento rilevato. Telecamera: {{ camera_name }}'
        timeout: 1000
        url: >-
          {{base_url}}/api/frigate/notifications/{{id}}/{{camera}}/clip.mp4

It changes the send_video timeout to 1000 seconds instead of the default. Videos might arrive 10 mins+ after the event but it can't be helped.

Last time I tried to troubleshoot, I noticed the automation hanging in the send_video section, even though the source video is already playable locally.

10mb files shouldn't take so long to upload on my internet speed so I really believe it's Telegram themselves limiting video upload speeds. 🫤

@nixxon94
Copy link

nixxon94 commented Jan 14, 2024

I am getting the following error message

2024-01-14 13:18:51.917 ERROR (SyncWorker_2) [homeassistant.components.telegram_bot] Can't load data into ByteIO: Invalid URL '/api/frigate/notifications/1705234731.428055-zw79cd/snapshot.jpg': No scheme supplied. Perhaps you meant https:///api/frigate/notifications/1705234731.428055-zw79cd/snapshot.jpg? 2024-01-14 13:18:51.918 ERROR (SyncWorker_2) [homeassistant.components.telegram_bot] Can't send file with kwargs: {'disable_notification': False, 'caption': 'Movimento rilevato. Telecamera: Garage (ID: 1705234731.428055-zw79cd)', 'url': '/api/frigate/notifications/1705234731.428055-zw79cd/snapshot.jpg'} 2024-01-14 13:19:13.164 ERROR (SyncWorker_8) [homeassistant.components.telegram_bot] Can't load data into ByteIO: Invalid URL '/api/frigate/notifications/1705234731.428055-zw79cd/garage/clip.mp4': No scheme supplied. Perhaps you meant https:///api/frigate/notifications/1705234731.428055-zw79cd/garage/clip.mp4? 2024-01-14 13:19:13.164 ERROR (SyncWorker_8) [homeassistant.components.telegram_bot] Can't send file with kwargs: {'disable_notification': False, 'caption': 'Movimento rilevato. Telecamera: Garage', 'url': '/api/frigate/notifications/1705234731.428055-zw79cd/garage/clip.mp4'}

@denzhel
Copy link

denzhel commented Jan 29, 2024

Is it possible to send the snapshot to telegram with the motion box detected by Frigate ?

@elmaswebon
Copy link

Works like a charm, thanks a lot!

Could you consider the possibility that we can modify the Italian texts for custom ones?

@balvant813
Copy link

Just added blueprint, activate and tested telegram bot. I ran the automation from automation page, it just does not run! it shows 'This node was not executed and so no further trace information is available.' . see screenshot below. What I am doing wrong?
Screenshot 2024-03-09 153913 - thanks

@balvant813
Copy link

I have also included mqtt message data from Frigate.

@jakesOneFourSeven
Copy link

jakesOneFourSeven commented Mar 31, 2024

If anyone is interested, I created a fork that incorporates Gemini AI generative comments.

(https://gist.github.com/jakesOneFourSeven/cc8fab1e8712a34dbd596ebd355d76ea)

@TokarevSergey
Copy link

Has anyone managed to send a video via telegram?

@jakesOneFourSeven
Copy link

Has anyone managed to send a video via telegram?

Yes, I receive a screenshot and then a video shortly after that.

@kornalexandr2
Copy link

Has anyone managed to send a video via telegram?

Yes, I receive a screenshot and then a video shortly after that.

But HOW?

@kornalexandr2
Copy link

kornalexandr2 commented Jul 31, 2024

Not work...

alias: Snapshot to TG by moving
description: ""
trigger:
  - platform: mqtt
    topic: frigate/events
    value_template: "{{ value_json['after']['camera'] }}"
condition:
  - condition: state
    entity_id: alarm_control_panel.aqara_hub_alarm
    state: armed_away
action:
  - service: notify.me
    data:
      title: A title
      message: A message
      data:
        inline_keyboard:
          - >-
            Disable Camera Alerts - 30m:/disable_cam_30, Disable Camera Alerts -
            1h:/disable_cam_60
          - >-
            Disable Camera Alerts Forever:/disable_cam_forever, Sound Panic
            Alarm:/sound_alarm
        photo:
          - url: >-
              http://192.168.1.169:5000/api/frigate/notifications/{{trigger.payload_json["after"]["id"]}}/snapshot.jpg
mode: single

Error rendering data template: UndefinedError: 'dict object' has no attribute 'payload_json'

@jakesOneFourSeven
Copy link

jakesOneFourSeven commented Aug 6, 2024

@kornalexandr2
This is from the blueprint:

  • service: telegram_bot.send_video
    data:
    target: '{{ target_chat }}'
    disable_notification: '{{ notification }}'
    caption: ' {{ generated_content.text }} '
    url: '{{base_url}}/api/frigate/notifications/{{id}}/{{camera}}/clip.mp4'

  • service: telegram_bot.send_photo
    data:
    target: '{{ target_chat }}'
    disable_notification: '{{ notification }}'
    caption: ' {{ generated_content.text }} '
    url: '{{base_url}}/api/frigate/notifications/{{id}}/snapshot.jpg'

@thesebastianf
Copy link

Can I also enable notificationa for the audio detectors of frigate? E.g. der audio detector for fire alarm I would Like to get These notifications

@Kedryn
Copy link

Kedryn commented Aug 26, 2024

This seems to work, BUT it's sending a notification every "interval" for stationary objects.
that means a big cluttering of notifications for parked cars, for example

@guikof97
Copy link

guikof97 commented Nov 11, 2024

If you need notification of offline devices via app and telegram, check my project.
https://github.com/guikof97/Automation_Home_Assistant_Telegram_Notify_and_Check_Offline_Cameras_Frigate

@Neflhiem
Copy link

This is great. Thank you so much for creating this. Is there anyway a "Message thread id" can be added so we can specify a topic to send the message to? This is done in other Telegram bot actions but i cant seem to figure out how to add it on my own to this blueprint

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