Frigate video via Telegram

Setup: RPi4 running Hassos. Both Hassos and Frigate are the latest versions.

Use case: when I receive an alert from a Frigate camera I would like to send the resultant video clip to my devices via the Telegram Bot. I can do this for the thumbnail picture but I have spent hours trying to make it work with video. Both the Home Assistant Telegram and Frigate documentation refer to this use case, but neither shows how it is done.

Here is my automation’s yaml file which I got from the Frigate documentation (https://blakeblackshear.github.io/frigate/usage/home-assistant):

alias: Frigate alerts
description: Person/car detection in cameras from Frigate
trigger:
  - platform: mqtt
    topic: frigate/events
condition: []
action:
   - service: notify.camera_alert_telegram
    data:
      message: >-
        A {{trigger.payload_json["after"]["label"]}} was detected on
        {{trigger.payload_json["after"]["camera"]}} 
      data:
        video:
          - url: >-
              'http://ccab4aaf-frigate:5000/api/events/{{trigger.payload_json["after"]["id"]}}/{{trigger.payload_json["after"]["camera"]}}/clip.mp4'  
            caption: >-
              'Video of {{trigger.payload_json["after"]["label"]}} detected on
              {{ trigger.payload_json["after"]["camera"] }}'
mode: single

And here are the error messages I receive.

Can't load data into ByteIO: No connection adapters were found for "'http://ccab4aaf-frigate:5000/api/events/1614904741.504328-knf1ic/Camera1/clip.mp4'"

and

Can't send file with kwargs: {'message': "'Video from person detected on Camera1'", 'url': "'http://ccab4aaf-frigate:5000/api/events/1614904741.504328-knf1ic/Camera1/clip.mp4'", 'caption': "'Video caption for person detected on Camera1'"}

I am guessing I have made a syntax error but I can’t see where. Please help!

Also doing exactly same as what you did, obviously not working. Interested into the solution as well.

Hi I presume that you have checked that you can see the video in the Media Browser (under Frigate/Clips)?
If so, this is how I got sending via Telegram working:

  1. Set a delay after the end of the detection (it seems like it needs to be at least 30 seconds but I found 45 seconds more reliable) before attempting to send the video;
  2. Set the timeout to 1000 in the video attachment YAML files. (add a line with timeout: 1000 after the video URL).
    I hope this helps

Yes I am able to see the clips within HA via browser.

If you would not mind, would you be able to post your automation of sending clip here for reference please?

Thx so much :slight_smile:

Here is my YAML for the automation:

alias: Frigate alerts
description: Person/car detection in cameras from Frigate
trigger:
  - platform: mqtt
    topic: frigate/events
condition:
  - condition: template
    value_template: '{{ trigger.payload_json["type"] == "end" }}'
action:
  - service: notify.camera_alert_telegram
    data:
      message: 'Snapshot of alert at {{trigger.payload_json["after"]["camera"]}}'
      data:
        photo:
          - url: >-
              https://[YOUR HA URL]/api/frigate/notifications/{{trigger.payload_json["after"]["id"]}}/thumbnail.jpg
            caption: >-
              Snapshot of {{trigger.payload_json["after"]["label"]}} detected on
              {{trigger.payload_json["after"]["camera"]}}, Event ID
              '{{trigger.payload_json["after"]["id"]}}'
  - delay:
      hours: 0
      minutes: 0
      seconds: 45
      milliseconds: 0
  - service: notify.camera_alert_telegram
    data:
      message: Video of alert
      data:
        video:
          - url: >-
              https://[YOUR HA URL]/api/frigate/notifications/{{trigger.payload_json["after"]["id"]}}/{{trigger.payload_json["after"]["camera"]}}/clip.mp4
            timeout: 1000
            caption: >-
              Video {{trigger.payload_json["after"]["label"]}} detected on
              {{trigger.payload_json["after"]["camera"]}}, Event ID
              '{{trigger.payload_json["after"]["id"]}}''
mode: single
4 Likes

Cool, thx so much.

I will have a shot to see how it goes.

Hi, just testing Telegram with Frigate for the first time, and have this running on my dev-nuc. Do I need to give access from internet (port forwarding) to my dev-nuc for this to work, ref the URL or should it still work by just using:

https://192.168.12.112:8123/api/frigate *** ?

I use the access from the Internet. My port is open already so that I can access and control HA from outside my home. I am using DuckDNS to set up a SSL connection

1 Like

Hi I can still receive photos notification, but I’m still not getting videos on telegram
@allenrong88 is it working for you?

Logs

Can't send file with kwargs: {'message': 'Video of alert', 'url': 'http://ccab4aaf-frigate:5000/api/events/1621081093.316226-dwpaga/kitchen/clip.mp4', 'timeout': 1000, 'caption': 'A person was detected on kitchen camera'}
Can't send file with kwargs: {'message': 'Video of alert', 'url': 'http://ccab4aaf-frigate:5000/api/events/1621081367.345592-yaoo5l/kitchen/clip.mp4', 'timeout': 1000, 'caption': 'A person was detected on kitchen camera'}
Can't send file with kwargs: {'message': 'Video of alert', 'url': 'http://ccab4aaf-frigate:5000/api/events/1621083291.687607-6zy6t7/kitchen/clip.mp4', 'timeout': 1000, 'caption': 'A person was detected on kitchen camera'}
Status code 404 (retry #1) loading http://ccab4aaf-frigate:5000/api/events/1621083291.687607-6zy6t7/kitchen/clip.mp4
Status code 404 (retry #2) loading http://ccab4aaf-frigate:5000/api/events/1621083291.687607-6zy6t7/kitchen/clip.mp4
Status code 404 (retry #3) loading http://ccab4aaf-frigate:5000/api/events/1621083291.687607-6zy6t7/kitchen/clip.mp4
Status code 404 (retry #4) loading http://ccab4aaf-frigate:5000/api/events/1621083291.687607-6zy6t7/kitchen/clip.mp4
Status code 404 (retry #5) loading http://ccab4aaf-frigate:5000/api/events/1621083291.687607-6zy6t7/kitchen/clip.mp4
Can't load data in http://ccab4aaf-frigate:5000/api/events/1621081093.316226-dwpaga/kitchen/clip.mp4 after 5 retries
Can't load data in http://ccab4aaf-frigate:5000/api/events/1621081367.345592-yaoo5l/kitchen/clip.mp4 after 5 retries
Can't load data in http://ccab4aaf-frigate:5000/api/events/1621083291.687607-6zy6t7/kitchen/clip.mp4 after 5 retries

My automation

  - alias: Notify of events
    trigger:
      platform: mqtt
      topic: frigate/events
    action:
      - service: notify.telegram
        data_template:
          message: 'A {{trigger.payload_json["after"]["label"]}} was detected.'
          data:
            photo:
              # this url should work for addon users
              - url: 'http://ccab4aaf-frigate:5000/api/events/{{trigger.payload_json["after"]["id"]}}/thumbnail.jpg'
                caption: 'A {{trigger.payload_json["after"]["label"]}} was detected on {{ trigger.payload_json["after"]["camera"] }} camera'
      - delay:
          hours: 0
          minutes: 0
          seconds: 53
          milliseconds: 0
      - service: notify.telegram
        data_template:
          message: Video of alert
          data:
            video:
              - url: 'http://ccab4aaf-frigate:5000/api/events/{{trigger.payload_json["after"]["id"]}}/{{trigger.payload_json["after"]["camera"]}}/clip.mp4'
                timeout: 1000
                caption: 'A {{trigger.payload_json["after"]["label"]}} was detected on {{ trigger.payload_json["after"]["camera"] }} camera'
    mode: single 

Yes I get it work perfectly now. I have attached my video bit as below.

  • service: telegram_bot.send_video
    data_template:
    target: ‘xxx’
    caption: ‘A {{trigger.payload_json[“after”][“label”]}} detected on {{trigger.payload_json[“after”][“camera”]}}’
    url: ‘http://HA_URL:8123/api/frigate/notifications/{{trigger.payload_json[“after”][“id”]}}/{{trigger.payload_json[“after”][“camera”]}}/clip.mp4’
    timeout: 1000
2 Likes

As for the homeassistant url,
Does it have to be https or http is sufficient?

I tried with telegram_bot.send_video and with notify.telegram method, but I have always the same result:

2021-06-01 12:48:51 WARNING (SyncWorker_10) [homeassistant.components.telegram_bot] Status code 404 (retry #1) loading http://192.168.xxx.xxx:xxxx/api/events/1622544520.350811-oko8y8/study/clip.mp4

It nees to be public url (yourown domain or duckdns) to work.

Does it work with Nabu Casa address?

Thanks for sharing your automation, works beautifully! Is there any ways to have a good quality image rather than the thumbnail?

I think you can increase the size of the thumbnail by adding the following lines to your frigate.yml file for each camera:

    snapshots:
      enabled: True
      crop: True
      height: 500

The height parameter determines the size of the snapshot.

1 Like

thank you!

Hi, can you share the full code?

Did you manage? Can you send please the working code?

It’s the same as I posted before, anyway here it is

- alias: Notify of events
  trigger:
    platform: mqtt
    topic: frigate/events
  condition: '{{ trigger.payload_json["type"] == "end" }}'
  action:
  - service: notify.telegram
    data_template:
      message: A {{trigger.payload_json["after"]["label"]}} was detected.
      data:
        photo:
        - url: http://ccab4aaf-frigate:5000/api/events/{{trigger.payload_json["after"]["id"]}}/thumbnail.jpg
          caption: A {{trigger.payload_json["after"]["label"]}} was detected on {{
            trigger.payload_json["after"]["camera"] }} camera
  - delay:
      hours: 0
      minutes: 0
      seconds: 45
      milliseconds: 0
  - service: notify.telegram
    data_template:
      message: Video of alert
      data:
        video:
        - url: https://yourduckdns.duckdns.org/api/frigate/notifications/{{trigger.payload_json["after"]["id"]}}/{{trigger.payload_json["after"]["camera"]}}/clip.mp4
          timeout: 1000
          caption: A {{trigger.payload_json["after"]["label"]}} was detected on {{
            trigger.payload_json["after"]["camera"] }} camera
  mode: single
1 Like