Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TTS option for android dnd/silence override #221

Merged
merged 2 commits into from
Jun 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 88 additions & 2 deletions Frigate Camera Notifications/Beta
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,21 @@ blueprint:
- "{{'true' if is_state('sun.sun', 'above_horizon') else 'false' }}"
- "{{ event['after']['top_score'] |float(0) > 0.8 }}"
custom_value: true
tts:
name: Use TTS to override silent/dnd modes on specific phones.
description: |
Some phones (the Samsung galaxy line, in particular,) disable the ability to use `alarm_stream` as a means to bypass the current sound settings. This option allows TTS to announce the alert instead, which does bypass the sound settings.
default: false
selector:
boolean:
tts_helper:
name: Entity to store ids already alerted by TTS
description: |
In order for TTS to honor alert_once settings, create a text helper (/config/helpers), which will be used to store the ids for any tts alerts that have gone out. Set the maximum character count to 250 to store the latest 25 alert ids. Then select it here
default: ""
selector:
entity:
integration: input_text
alert_once:
name: Alert Once (Optional)
description: Only the first notification for each event will play a sound. Updates, including new thumbnails, will be silent. iOS users who use Critical Notifications above will still hear default critical sounds for updates.
Expand Down Expand Up @@ -866,6 +881,8 @@ action:
# other things that can be templated and might need info from the event
critical_input: !input critical
critical: "{{ true if critical_input == 'true' else true if critical_input == True else false }}"
tts: !input tts
tts_helper: !input tts_helper
custom_filter: !input custom_filter
icon: !input icon
group: !input group
Expand All @@ -890,6 +907,8 @@ action:
camera(formatted): {{camera}}({{camera_name}}),
Base URL: {{base_url}},
critical: {{critical}},
tts: {{tts}}
helper: {{tts_helper if tts else 'N/A'}},
alert once: {{alert_once}},
Update Thumbnails: {{update_thumbnail}},
Video: {{video}},
Expand Down Expand Up @@ -1072,7 +1091,7 @@ action:
title: "{{title}}"
message: "{{message}}"
data:
tag: "{{ id }}{{'-loitering' if loitering}}"
tag: "{{ id }}"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a reson this was changed. I personally have never enabled loitering but if there is something i should know please let me know.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was on the "new" event notification. It was inconsistent with the other two notification types in the section, and I don't believe you can get a new event that is also loitering, anyways. It would have to be an update, since loitering is some amount of time since the event began, right?

group: "{{ group }}"
color: "{{color}}"
# Android Specific
Expand Down Expand Up @@ -1118,6 +1137,38 @@ action:
uri: "{{url_3}}"
icon: "{{icon_3}}"
destructive: true

- if: "{{tts and (not tts_helper or not alert_once or (tts_helper and id not in states(tts_helper)))}}"
then:
sequence:
- choose:
- conditions: "{{ not notify_group_target }}"
sequence:
- device_id: !input notify_device
domain: mobile_app
type: notify
message: "{{'TTS'}}"
data:
tag: "{{ id }}{{'-tts'}}"
channel: "{{'alarm_stream' if critical else channel}}"
alert_once: "{{ alert_once }}"
tts_text: "{{message}}"
default:
- service: "notify.{{ notify_group_target }}"
data:
message: "{{'TTS'}}"
data:
tag: "{{ id }}{{'-tts'}}"
channel: "{{'alarm_stream' if critical else channel}}"
alert_once: "{{ alert_once }}"
tts_text: "{{message}}"
- service: input_text.set_value
data:
value: |
{% set newIds = id + '|' + states(tts_helper) %}
{{ newIds[:250] }}
target:
entity_id: input_text.tts_notifications
- repeat:
sequence:
- wait_for_trigger:
Expand Down Expand Up @@ -1157,6 +1208,7 @@ action:
sub_label_changed: "{{ update_sub_label and sub_label != sub_label_before }}"
critical_input: !input critical
critical: "{{ true if critical_input == 'true' else true if critical_input == True else false }}"
tts: !input tts
title: >
{% if sub_label and update_sub_label %}
{{title | replace('A Person', sub_label|title) | replace('Person', sub_label|title)}}
Expand Down Expand Up @@ -1201,7 +1253,8 @@ action:
Android Sound: {{'disabled by alert once' if alert_once else 'enabled'}},
iOS url: /api/frigate{{client_id}}/notifications/{{id}}/{{camera + '/clip.mp4' if video|length>0 and wait.trigger.payload_json['type'] == 'end' else attachment }}
video: "{{video}}"
critical: {{critical}},
critical: {{critical}},
tts: {{tts}}
Triggers:
New Snapshot: {{'True' if event['before']['snapshot']['frame_time'] != event['after']['snapshot']['frame_time'] else 'False'}}{{' - Disabled' if not update_thumbnail}}
Presence Changed: {{presence_changed}},
Expand Down Expand Up @@ -1403,4 +1456,37 @@ action:
uri: "{{url_3}}"
icon: "{{icon_3}}"
destructive: true

- if: "{{tts and (not tts_helper or not alert_once or (tts_helper and id not in states(tts_helper)))}}"
then:
sequence:
- choose:
- conditions: "{{ not notify_group_target }}"
sequence:
- device_id: !input notify_device
domain: mobile_app
type: notify
message: "{{'TTS'}}"
data:
tag: "{{ id }}{{'-loitering-tts' if loitering}}"
channel: "{{'alarm_stream' if critical else channel}}"
alert_once: "{{ alert_once }}"
tts_text: "{{message}}"

default:
- service: "notify.{{ notify_group_target }}"
data:
message: "{{'TTS'}}"
data:
tag: "{{ id }}{{'-loitering-tts' if loitering}}"
channel: "{{'alarm_stream' if critical else channel}}"
alert_once: "{{ alert_once }}"
tts_text: "{{message}}"
- service: input_text.set_value
data:
value: |
{% set newIds = id + '|' + states(tts_helper) %}
{{ newIds[:250] }}
target:
entity_id: input_text.tts_notifications
until: "{{ not wait.trigger or wait.trigger.payload_json['type'] == 'end' }}"