Frigate video via Telegram

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

Ok, thanks a lot. So this works for the pics but not the video?

It’s for both

Ok since for me had always hard time using notify, I use other service
telegram_bot.send_photo
telegram_bot.send_video

but is not working, anyone knwos what is wrong?


  - alias: Notify of events
    trigger:
      platform: mqtt
      topic: frigate/events
    condition: '{{ trigger.payload_json["type"] == "end" }}'
    action:
    - service: telegram_bot.send_photo
      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
        target: '-29091xxxx'
    - delay:
        hours: 0
        minutes: 0
        seconds: 45
        milliseconds: 0
    - service: telegram_bot.send_video
      data_template:
        message: Video of alert
        data:
          video:
          - url: https://xxxx/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
          target: '-29091xxxxx'
    mode: single