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 sleep mode. - condition: state entity_id: input_boolean.sleep_mode state: "off" # Combine partials for speech message. - service: script.say_discretely data_template: 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') or is_state('input_boolean.speech_notifications', 'off') or is_state('input_boolean.georgi_home', 'off') %} script.telegram_say {% else %} script.sonos_blast {% endif %} data_template: title: "💬 *Speech Module*" # For telegram only message: "{{ message }}" telegram_say: alias: Speech - Telegram say sequence: - service: notify.telegram data_template: title: "{{ title }}" 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 now().strftime('%H')|int < 6 and now().strftime('%H')|int > 1 %} 0.2 {% else %} 0.5 {% 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:02 - service: script.sonos_blast data_template: message: "{{ message }}" - delay: 00:00:05 - service: sonos.restore data_template: with_group: yes entity_id: media_player.master_bedroom