TTS on Sonos as a resuable service

Hi,

I am using TTS (Google Translate) on Sonos in several automations, e.g. to say “washing machine is finished”. As the Sonos could actually be playing music, I would like to

  1. Turn the music down (this already happens automatically)
  2. Adjust the volume to a standard value for TTS
  3. Do the TTS announcement
  4. Turn the volume back to what it was before
  5. Resume the music

Further, as I do not want to repeat this in all automations, I would love to have some sort of reusable thing that I can parameterize with the actual text to announce and the devices it should say the text on.
as this sounds like a common feature to me, I wonder whether somebody has a good solution for this.

thanks in advance for any hints!

Best regards,
Jonas

I do what you described with a script but there’s a custom integration available as well.

1 Like

Take a look at the announce option. It’s documented in Sonos documentation.

I use an input text to feed announcements for speakers. In other words, the automation triggers off the input text, gets the values and announces it on the speaker. You could also use events which may be a cleaner option.

This announces it twice. It clears the text at the end. I think I was having problems with it announcing old messages on restarts.

- id: al announce queue
  alias: al announce queue
  mode: queued
  max: 10  
  trigger:
    - platform: state
      entity_id: input_text.al_announce_queue
  action:
    - condition: "{{trigger.to_state.state != 'announced' }}"
    - service: media_player.play_media
      data:
        entity_id: media_player.kitchen
        media_content_id: >
           media-source://tts/google_translate?message="{{ trigger.to_state.state }}"
        media_content_type: music
        announce: true
        extra:
          volume: 40          
    - delay: "00:00:05"
    - service: media_player.play_media
      data:
        entity_id: media_player.kitchen
        media_content_id: >
           media-source://tts/google_translate?message="{{ trigger.to_state.state }}"
        media_content_type: music
        announce: true
        extra:
          volume: 50
    - service: input_text.set_value
      data:
        entity_id: input_text.al_announce_queue
        value: "announced"
    - delay: "00:00:15"