Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save jakesOneFourSeven/cc8fab1e8712a34dbd596ebd355d76ea to your computer and use it in GitHub Desktop.

Select an option

Save jakesOneFourSeven/cc8fab1e8712a34dbd596ebd355d76ea to your computer and use it in GitHub Desktop.
Frigate - Telegram Notification
blueprint:
name: Frigate - Telegram Notification with Generative AI comments
description: Create automations to receive Snapshots and Clips from Frigate
domain: automation
input:
camera:
name: Frigate Camera
description: "Select the camera entity that will trigger notifications. \nIf you do not see cameras listed in the drop down, check you have the frigate integration installed.\nNote: The automation relies on this matching your frigate config (by default it does).\n"
selector:
entity:
integration: frigate
domain:
- camera
device_class:
- camera
multiple: false
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, leave "false" to receive notification. '
selector:
select:
options:
- 'true'
- 'false'
multiple: false
sort: false
custom_value: false
default: 'false'
prompt:
name: Gemini Prompt
description: Customise your AI prompt for the image analysis.
default: Very briefly describe what you see in this image from my cctv camera. Your message needs to be short to fit in a phone notification. Don't describe stationary objects or buildings. Only describe animals, vehicles or persons.
ai_entity:
name: AI Task Entity (Optional)
description: Select the Google/Gemini or OpenAI entity to use for the image analysis. Defaults to the system default if left blank.
default:
selector:
entity:
domain: ai_task
multiple: 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:
multiple: false
source_url: https://gist.github.com/jakesOneFourSeven/cc8fab1e8712a34dbd596ebd355d76ea
mode: single
max_exceeded: silent
trigger_variables:
input_camera: !input camera
camera: '{{ input_camera | replace(''camera.'', '''') }}'
trigger:
- platform: mqtt
topic: frigate/events
payload: '{{ camera }}/new'
value_template: '{{ value_json[''after''][''camera''] | lower | replace(''-'',''_'') }}/{{ value_json[''type'']}}'
id: frigate-event
variables:
id: '{{ trigger.payload_json[''after''][''id''] }}'
input_camera: !input camera
camera: '{{ input_camera | replace(''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
clip_local_file: '/config/www/clip_{{ id }}.mp4'
snapshot_file: '/config/www/snapshot_{{ id }}.jpg'
condition:
- '{{ input_camera is not none and input_camera | string | length > 0 }}' # Ensure the camera input is defined.
- '{{ 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:
# Use a unique filename for the snapshot
- service: camera.snapshot
data:
entity_id: !input camera
filename: '{{ snapshot_file }}'
- delay: 0.5
- service: ai_task.generate_data
target:
entity_id: !input ai_entity
data:
task_name: Frigate Snapshot Analysis
# Use the user's custom prompt from input
instructions: !input prompt
# Use the new attachment selector
attachments:
- selector:
file:
path: '{{ snapshot_file }}'
response_variable: generated_content
- service: telegram_bot.send_photo
data:
target: '{{ target_chat }}'
disable_notification: '{{ notification }}'
caption: '{{ generated_content.data }}' # Use .data for the generated text
file: '{{ snapshot_file }}'
- 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: downloader.download_file
data:
overwrite: true
url: '{{base_url}}/api/frigate/notifications/{{id}}/{{camera}}/clip.mp4'
filename: 'www/clip_{{ id }}.mp4'
- service: telegram_bot.send_video
data:
target: '{{ target_chat }}'
disable_notification: '{{ notification }}'
caption: '{{ generated_content.data }}' # Use .data for the generated text
file: '{{ clip_local_file }}'
until: '{{ wait.trigger.payload_json[''type''] == ''end'' }}'
@jakesOneFourSeven
Copy link
Author

jakesOneFourSeven commented Nov 24, 2025

Had to update the code due to changes in how Gemini is used in HA. Re-import the blueprint and add the following to Configuration.yaml

homeassistant:
media_dirs:
# Alias name: Full absolute path to the directory
frigate_snaps: /config/www

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