mirror of
https://github.com/GeorgeSG/sarah.git
synced 2026-05-02 23:54:25 +00:00
133 lines
4.1 KiB
YAML
133 lines
4.1 KiB
YAML
# https://www.home-assistant.io/integrations/telegram
|
|
# https://www.home-assistant.io/integrations/telegram_chatbot
|
|
telegram_bot:
|
|
- platform: polling
|
|
api_key: !secret telegram_token
|
|
allowed_chat_ids:
|
|
- !secret telegram_georgi_chat_id
|
|
|
|
# https://www.home-assistant.io/integrations/tts
|
|
tts:
|
|
- platform: amazon_polly
|
|
aws_access_key_id: !secret aws_polly_client_id
|
|
aws_secret_access_key: !secret aws_polly_client_secret
|
|
region_name: us-east-1
|
|
voice: Amy
|
|
engine: neural
|
|
|
|
input_boolean:
|
|
speech_notifications:
|
|
name: Speech notifications
|
|
icon: mdi:chat
|
|
|
|
sarah_talking:
|
|
name: SARAH talking
|
|
icon: mdi:chat
|
|
initial: off
|
|
|
|
script:
|
|
say:
|
|
alias: Speech · Say
|
|
sequence:
|
|
# Don't talk while in night mode.
|
|
- condition: template
|
|
value_template: "{{ not is_state('input_select.house_mode', 'night') }}"
|
|
# Combine partials for speech message.
|
|
- service: script.say_discretely
|
|
data_template:
|
|
title: "{{ title | default('💬 *Speech Module*') }}"
|
|
message: >-
|
|
{%- if partials is defined -%}
|
|
{%- for partial in partials -%}
|
|
{{ partial }}{{ " " }}
|
|
{%- endfor -%}
|
|
{%- else -%}
|
|
{{ message }}
|
|
{%- endif -%}
|
|
|
|
say_discretely:
|
|
alias: Speech · Say discretely
|
|
sequence:
|
|
# Figure out whether to talk or send a text.
|
|
- service_template: >
|
|
{% if (is_state('media_player.master_bedroom', 'playing')
|
|
and is_state('binary_sensor.sonos_recoverable', 'off'))
|
|
or is_state('input_boolean.speech_notifications', 'off')
|
|
or is_state('input_boolean.georgi_home', 'off') %}
|
|
notify.telegram
|
|
{% else %}
|
|
{% if is_state('media_player.master_bedroom', 'playing')
|
|
and is_state('binary_sensor.sonos_recoverable', 'on') %}
|
|
script.sonos_say
|
|
{% else %}
|
|
script.sonos_blast
|
|
{% endif %}
|
|
{% endif %}
|
|
data_template:
|
|
title: "{{ title | default('💬 *Speech Module*') }}" # For telegram only
|
|
message: "{{ message }}"
|
|
|
|
sonos_blast:
|
|
alias: Speech · Sonos blast
|
|
sequence:
|
|
# Mark SARAH as talking.
|
|
- service: input_boolean.turn_on
|
|
entity_id: input_boolean.sarah_talking
|
|
# Don't shout :)
|
|
- service: media_player.volume_set
|
|
entity_id: media_player.master_bedroom
|
|
data_template:
|
|
volume_level: >-
|
|
{% if volume_level %}
|
|
{{ volume_level }}
|
|
{% else %}
|
|
{% if now().strftime('%H')|int < 6 and now().strftime('%H')|int > 0 %}
|
|
0.2
|
|
{% else %}
|
|
0.4
|
|
{% endif %}
|
|
{% endif %}
|
|
# Say message.
|
|
- service: tts.amazon_polly_say
|
|
data_template:
|
|
entity_id: media_player.master_bedroom
|
|
message: "{{ message }}"
|
|
# Wait for phrase to be over and mark as not talking.
|
|
- delay: 00:00:01
|
|
- wait_template: "{{ is_state('media_player.master_bedroom', 'paused') }}"
|
|
timeout: 00:02:00
|
|
- service: input_boolean.turn_off
|
|
entity_id: input_boolean.sarah_talking
|
|
|
|
sonos_say:
|
|
alias: Speech · Sonos say
|
|
sequence:
|
|
- service: sonos.snapshot
|
|
data_template:
|
|
with_group: yes
|
|
entity_id: media_player.master_bedroom
|
|
- delay: 00:00:01
|
|
- service: script.sonos_blast
|
|
data_template:
|
|
message: "{{ message }}"
|
|
volume_level: "{{ volume_level }}"
|
|
- wait_template: "{{ is_state('input_boolean.sarah_talking', 'off') }}"
|
|
timeout: 00:02:00
|
|
- service: sonos.restore
|
|
data_template:
|
|
with_group: yes
|
|
entity_id: media_player.master_bedroom
|
|
|
|
automation:
|
|
- alias: Speech · Telegram · Action · Do nothing
|
|
trigger:
|
|
platform: event
|
|
event_type: telegram_callback
|
|
event_data:
|
|
command: "/do_nothing"
|
|
action:
|
|
- service: telegram_bot.delete_message
|
|
data_template:
|
|
message_id: "{{ trigger.event.data.message.message_id}}"
|
|
chat_id: "{{ trigger.event.data.chat_id }}"
|