Frigate 0.16 beta 4 generative AI home assistant notification. For use with telegram

Updated Telegram Notification Automation for GenAI

Hey everyone! I’ve been working on my original notification automation for GenAI and decided to focus this version exclusively on Telegram. Telegram’s a powerful, free platform for text-message-like notifications, and I’ve found it super powerful for this use case. This update is tailored specifically for Telegram and leverages its bot API for fast, dynamic notifications. I’m pretty excited about how it’s come together!

Why Telegram?
It’s free, supports bot-driven automation, and allows message editing for real-time updates, making it perfect for this kind of dynamic notification setup.

What’s Changed

  • Immediate Notifications with Edits: Sends a basic notification as soon as an event is detected, then updates it with the GenAI description once it’s ready. It’s a clean way to get instant alerts with details added later.
  • Camera-Specific Topics: I’ve set up unique topics in my Telegram group for each camera, which keeps alerts organized and helps me focus on high-priority cameras.
  • Post-Event Updates: The setup could also handle updates like face or license plate recognition within a 60-second window, which you can adjust as needed.

How It Works

  1. A notification hits your Telegram channel when an event is triggered.
  2. The bot edits the message to add the GenAI description once it’s processed.

Setup

  • Create a Telegram channel or group.
  • Set up a Telegram bot using BotFather.
  • Configure the automation with your bot token and chat ID.

The Automation

Here’s the updated YAML. Note: The strange spacing in the message templates is required for Telegram’s formatting.

alias: Notification of camera events
triggers:
  - topic: frigate/events
    trigger: mqtt
conditions:
  - condition: template
    value_template: "{{ trigger.payload_json['type'] == 'end' }}"
  - condition: template
    value_template: "{{ trigger.payload_json['after']['entered_zones'] | length > 0 }}"
actions:
  - variables:
      event_id: "{{ trigger.payload_json['after']['id'] }}"
      camera: "{{ trigger.payload_json['after']['camera'] }}"
      label: "{{ trigger.payload_json['after']['label'] }}"
      # These thread_id's are specific topics for each camera in my group. 0 being the general channel.
      thread_id: >-
        {% if camera == 'driveway_cam' %} 28534 
        {% elif camera == 'front_1' %} 28523 
        {% elif camera == 'doorbell' %} 28494 
        {% elif camera == 'garage' %} 28493 
        {% elif camera == 'rear_garage_1' %} 36239 
        {% elif camera == 'shop' %} 36241 
        {% elif camera == 'shop_shed' %} 36243 
        {% elif camera == 'rear_parking_pad_cam' %} 36242 
        {% else %} 0 {% endif %}
  - action: telegram_bot.send_photo
    data:
      message_thread_id: "{{ thread_id }}"
      url: >-
        http://10.0.1.11:8123/api/frigate/notifications/{{ event_id }}/thumbnail.jpg
      caption: >
        <b>Camera Alert</b> 🚨

        ├ <i>Camera:</i> {{ camera }}

        └ <i>Event:</i> {{ label }} detected


        <a href="https://pub.domain.com/api/frigate/notifications/{{ event_id }}/snapshot.jpg">📷 View Snapshot 📷</a>


        <a href="https://pub.domain.com/api/frigate/notifications/{{ event_id }}/clip.mp4">🎥 View Clip 🎥</a>
      parse_mode: html
      disable_web_page_preview: true
    response_variable: telegram_response
  - wait_for_trigger:
      - topic: frigate/tracked_object_update
        value_template: >
          {{ value_json['type'] == 'description' and value_json['id'] == event_id }}
        trigger: mqtt
    timeout: "60"
    continue_on_timeout: false
  - repeat:
      for_each: "{{ telegram_response.chats }}"
      sequence:
        - action: telegram_bot.edit_caption
          data:
            chat_id: "{{ repeat.item.chat_id }}"
            message_id: "{{ repeat.item.message_id }}"
            message_thread_id: "{{ thread_id }}"
            url: >-
              http://10.0.1.11:8123/api/frigate/notifications/{{ event_id }}/thumbnail.jpg
            caption: >
              <b>Camera Alert</b> 🚨

              ├ <i>Camera:</i> {{ camera }}

              └ <i>Event:</i> {{ label }} detected ┐

              {{ wait.trigger.payload_json['description'] }}

              <a href="https://pub.domain.com/api/frigate/notifications/{{ event_id }}/snapshot.jpg">📷 View Snapshot 📷</a>

              <a href="https://pub.domain.com/api/frigate/notifications/{{ event_id }}/clip.mp4">🎥 View Clip 🎥</a>
            parse_mode: html
            disable_web_page_preview: true
mode: queued

Notes

  • This version is built for Telegram only, relying on its bot API, and message editing ability, so it’s not meant for other platforms.
  • The 60-second edit window can be adjusted to your liking.
  • GenAI descriptions are mostly for fun, as the devs pointed out. It’s a bit of a gimmick, but I’m enjoying messing around with it.
  • You have to loop through the telegram_response object, which is oddly a single-message array. I couldn’t find a cleaner way to access the values.
1 Like