Skip to content

Instantly share code, notes, and snippets.

@girs1982
Last active June 23, 2024 20:11
Show Gist options
  • Save girs1982/22ce4e673da372fe7f33870433c49e81 to your computer and use it in GitHub Desktop.
Save girs1982/22ce4e673da372fe7f33870433c49e81 to your computer and use it in GitHub Desktop.
fregateTG.yaml
blueprint:
name: Frigate - Telegram Notification By Gansta
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, leave "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 receive notifications for.
default: []
selector:
object: {}
labels:
name: (Optional) Trigger Objects
description: A list (-) of objects you wish to receive 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:
payload: "{{ trigger.payload_json | default({}) }}"
id: "{{ payload.get('after', {}).get('id', 'undefined') }}"
camera: "{{ payload.get('after', {}).get('camera', 'undefined') }}"
camera_name: "{{ camera | replace('_', ' ') | title }}"
target_chat: !input "target_chat"
object: "{{ payload.get('after', {}).get('label', 'undefined') }}"
label: "{{ object | title }}"
entered_zones: "{{ payload.get('after', {}).get('entered_zones', []) }}"
type: "{{ payload.get('type', 'undefined') }}"
base_url: !input "base_url"
base_url_valid: "{{ 'http://' in base_url or 'https://' in 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') }}"
- "{{ base_url_valid }}"
action:
- service: system_log.write
data:
message: "Payload received: {{ trigger.payload_json }}"
level: info
- service: system_log.write
data:
message: "Variables: id={{ id }}, camera={{ camera }}, camera_name={{ camera_name }}, target_chat={{ target_chat }}, object={{ object }}, label={{ label }}, entered_zones={{ entered_zones }}, type={{ type }}, base_url={{ base_url }}"
level: info
- service: telegram_bot.send_photo
data:
target: "{{ target_chat }}"
disable_notification: "{{ notification == 'true' }}"
caption: "Person Detected. Camera: {{ camera_name }}"
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 == 'true' }}"
caption: "Person Detected. Camera: {{ camera_name }}"
url: >-
{{ base_url }}/api/frigate/notifications/{{ id }}/{{ camera }}/clip.mp4
until: "{{ wait.trigger.payload_json['type'] == 'end' }}"
@girs1982
Copy link
Author

it frigate blue print for home assistant

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