Skip to content

Instantly share code, notes, and snippets.

@asakusuma
Forked from hunterjm/frigate_0.10_notification.yaml
Last active October 2, 2022 20:06
Show Gist options
  • Save asakusuma/f2bc2980c2e6f8eba08cef9d3007e8f5 to your computer and use it in GitHub Desktop.
Save asakusuma/f2bc2980c2e6f8eba08cef9d3007e8f5 to your computer and use it in GitHub Desktop.
Frigate 0.1.5 Text To Speech
blueprint:
name: Frigate Text to Speech (0.1.5)
description: |
## Frigate Text to Speach
Forked from https://gist.github.com/hunterjm/8ff0005104dce3f28923294f49a443b1
Under construction
domain: automation
source_url: https://gist.github.com/asakusuma/f2bc2980c2e6f8eba08cef9d3007e8f5
input:
camera:
name: Frigate Camera
description: The name of the camera as defined in your frigate configuration.
notify_device:
name: Device
description: Audio device
default: false
selector:
entity:
domain: media_player
speech_message:
name: Speech Message
description: Message to broadcast
selector:
text:
type: text
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:
cooldown:
name: (Optional) Cooldown
description: Delay before sending another notification for this camera after the last event.
default: 30
selector:
number:
max: 300
min: 0
unit_of_measurement: seconds
loiter_timer:
name: (Optional) Loitering Notifications
description: >
Sends new loitering notification if a stationary object is detected for longer
than the specified time. 0 is off and will not send notifications.
default: 0
selector:
number:
max: 300
min: 0
unit_of_measurement: minutes
mode: parallel
trigger_variables:
camera: !input camera
trigger:
- platform: mqtt
topic: frigate/events
payload: "{{ camera }}/new"
value_template: "{{ value_json['after']['camera'] }}/{{ value_json['type']}}"
id: frigate-event
variables:
camera: !input camera
camera_name: "{{ camera | replace('_', ' ') | title }}"
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
cooldown: !input cooldown
loiter_timer: !input loiter_timer
fps_value: "{{ states('sensor.' + camera + '_camera_fps') }}"
fps: "{{ fps_value|int if is_number(fps_value) or 5 }}"
action:
- choose:
- alias: "Frigate Event"
conditions:
- condition: trigger
id: "frigate-event"
- "{{ is_state(this.entity_id, 'on') }}"
- "{{ not this.attributes.last_triggered or (now() - this.attributes.last_triggered).seconds > cooldown }}"
sequence:
- variables:
id: "{{ trigger.payload_json['after']['id'] }}"
object: "{{ trigger.payload_json['after']['label'] }}"
label: "{{ object | title }}"
# Dynamic Variables per event
initial_home: "{{ presence_entity != '' and is_state(presence_entity, 'home') }}"
initial_entered_zones: "{{ trigger.payload_json['after']['entered_zones'] }}"
- alias: "Notifications enabled for object label"
condition: template
value_template: "{{ not labels|length or object in labels }}"
- alias: "Notify on new object"
choose:
- conditions:
- "{{ not zone_only or initial_entered_zones|length > 0 }}"
- "{{ not zones|length or zones|select('in', initial_entered_zones)|list|length > 0 }}"
- "{{ not initial_home }}"
sequence:
service: tts.google_translate_say
data:
entity_id: !input notify_device
message: !input speech_message
- 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
- variables:
event: "{{ wait.trigger.payload_json }}"
loitering: "{{ loiter_timer and event['before']['motionless_count']/fps/60 < loiter_timer and event['after']['motionless_count']/fps/60 >= loiter_timer }}"
new_snapshot: "{{ update_thumbnail and event['before']['snapshot_time'] != event['after']['snapshot_time'] }}"
home: "{{ presence_entity != '' and is_state(presence_entity, 'home') }}"
presence_changed: "{{ presence_entity != '' and as_datetime(event['before']['frame_time']) < states[presence_entity].last_changed }}"
last_zones: "{{ event['before']['entered_zones'] }}"
entered_zones: "{{ event['after']['entered_zones'] }}"
zone_filter: "{{ not zone_only or entered_zones|length > 0 }}"
stationary_moved: "{{ event['after']['position_changes'] > event['before']['position_changes'] }}"
zone_only_changed: "{{ zone_only and (entered_zones|length > 0 and not last_zones|length) }}"
entered_zones_changed: "{{ zones|length > 0 and (zones|select('in', entered_zones)|list|length > 0 and not zones|select('in', last_zones)|list|length) }}"
update: "{{ new_snapshot and not loitering and not presence_changed and not zone_only_changed and not entered_zones_changed }}"
- alias: "Notify on loitering or significant change"
choose:
- conditions: "{{ loitering or (not home and zone_filter and (new_snapshot or presence_changed or stationary_moved or zone_only_changed or entered_zones_changed)) }}"
sequence:
service: tts.google_translate_say
data:
entity_id: !input notify_device
message: !input speech_message
until: "{{ not wait.trigger or wait.trigger.payload_json['type'] == 'end' }}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment