Skip to content

Instantly share code, notes, and snippets.

@denysdovhan
Created August 9, 2024 16:33
Show Gist options
  • Save denysdovhan/ca80df4688a77e5ca113e4fc542823ee to your computer and use it in GitHub Desktop.
Save denysdovhan/ca80df4688a77e5ca113e4fc542823ee to your computer and use it in GitHub Desktop.
Annoucement script boilerplate
blueprint:
name: Announcement
author: denysdovhan
description: >
This is a generic announcement with randomly generated phrases.
# source_url: TODO
domain: script
input:
default_tts:
name: TTS Service
description: Target TTS service to generate announcement audio
required: true
example: tts.google_en_com
selector:
entity:
filter:
domain: tts
default_notifier:
name: Notifier
description: Specify who should be notified
required: true
example: notify.notify
selector:
entity:
multiple: true
filter:
domain: notify
default_speaker:
name: Speaker
description: Target speaker to play an announcement
example: media_player.living_room_homepod
required: true
selector:
entity:
multiple: true
filter:
domain: media_player
notifier_conditions:
name: Notifier conditions
description: Conditions to be checked before sending a notification
required: false
selector:
condition:
speaker_conditions:
name: Speaker conditions
description: Conditions to be checked before playing an announcement
required: false
selector:
condition:
fields:
title:
name: Title
description: A title for a push-notification
required: false
selector:
text:
messages:
name: Messages
description: One of these messages will be randomly picked for an announcement
required: true
selector:
object:
openings:
name: Opening messages
description: One of these greetings will be randomly picked for an announcement a prefixed to a randomly picked message
required: false
default: []
advanced: true
selector:
object:
speak:
name: Speak
description: Play announcement on the specified speakers (true by default)
required: false
default: true
advanced: true
selector:
boolean:
send_notification:
name: Send notification
description: Send notification to specified devices (true by default)
required: false
default: true
advanced: true
selector:
boolean:
notify_data:
name: Notification data
description: Optionally pass additional data for a notification
required: false
advanced: true
default:
url: /localave/home
selector:
object:
force_to_speak:
name: Force to speak
description: Bypass all conditions and force speaking on speakers (false by default)
required: false
default: false
advanced: true
selector:
boolean:
custom_tts:
name: TTS Service
description: Override TTS service to generate announcement audio
required: false
advanced: true
example: tts.google_en_com
selector:
entity:
filter:
domain: tts
custom_service:
name: Custom Notifier
description: Override notifier to send a notification
required: false
advanced: true
example: notify.mobile_app_iphone
selector:
entity:
multiple: true
filter:
domain: notify
custom_speaker:
name: Custom Speaker
description: Override speaker to play the announcement
required: false
advanced: true
example: media_player.bedroom_speaker
selector:
entity:
multiple: true
filter:
domain: media_player
variables:
default_tts: !input default_tts
tts: >
{% if custom_tts | default("") %}
{{ custom_tts }}
{% elif default_tts | default("") %}
{{ default_tts }}
{% else %}
unknown: No TTS entity provided.
{% elif %}
default_notifier: !input default_notifier
notifier: >
{% if custom_notifier | default("") %}
{{ custom_notifier }}
{% elif default_notifier | default("") %}
{{ default_notifier }}
{% else %}
unknown: No notifier entity provided.
{% elif %}
default_speaker: !input default_speaker
speaker: >
{% if custom_notifier | default("") %}
{{ custom_notifier }}
{% elif default_notifier | default("") %}
{{ default_notifier }}
{% else %}
unknown: No speaker entity provided.
{% elif %}
notifier_conditions: !input notifier_conditions
speaker_conditions: !input speaker_conditions
message: >
{% if openings and messages %}
{{ (openings | random) ~ ' ' ~ (messages | random) }}
{% else %}
{{ (messages | random) }}
{% endif %}
sequence:
- alias: Play announcement on speakers
choose:
- alias: Normal audio announcement
conditions:
- '{{ speak is true }}'
- '{{ speaker_conditions }}'
sequence:
- action: tts.speak
target:
entity_id: '{{ tts }}'
data:
media_player_entity_id: '{{ speaker }}'
message: '{{ message }}'
- alias: Enforced audio announcement
conditions:
- '{{ speak is true }}'
- '{{ force_speak is true }}'
sequence:
- action: tts.speak
target:
entity_id: '{{ tts }}'
data:
media_player_entity_id: '{{ speaker }}'
message: '{{ message }}'
- alias: Send a notification
if:
- '{{ notify is true }}'
- '{{ notifier_conditions }}'
then:
- action: '{{ notifier }}'
data:
title: '{{ title }}'
message: '{{ message }}'
data: '{{ notify_data }}'
mode: parallel
icon: mdi:bell-badge
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment