TTS Cloud Say across multiple Sonos Media Players

Havent fixed my doorbell since they depricated sonos.join and Wife got annoyed at me for not fixing this… and now i cant seem to rec-create what worked.

I join all my Sonos together but cant get tts.cloud_say to broadcast across the group.

Can someone give me feedback as to where I am going wrong??

alias: "TTS: Doorbell (MP3)"
sequence:
  - service: media_player.volume_set
    target:
      entity_id:
        - media_player.lounge_s
        - media_player.corridor_s
        - media_player.kitchen_s
    data:
      volume_level: 1
  - service: media_player.join
    metadata: {}
    data:
      group_members:
        - media_player.office_s
        - media_player.corridor_s
    target:
      entity_id: media_player.lounge_s
  - service: tts.cloud_say
    data:
      entity_id: media_player.lounge_s
      message: There is someone at the Front Door 1
mode: single

I used to do this but now it doesnt work

alias: "TTS: for dads phone"
sequence:
  - service: media_player.volume_set
    metadata: {}
    data:
      volume_level: 1
    target:
      entity_id:
        - media_player.lounge_s
        - media_player.corridor_s
        - media_player.office_s
  - service: media_player.join
    data:
      group_members:
        - media_player.office_s
        - media_player.corridor_s
    target:
      entity_id:
        - media_player.lounge_s
  - service: tts.cloud_say
    data:
      entity_id: media_player.lounge_s
      message: Incoming message from Dad
      cache: true
  - delay:
      hours: 0
      minutes: 0
      seconds: 3
      milliseconds: 0
  - service: tts.cloud_say
    data:
      entity_id: media_player.lounge_s
      message: "{{ states.input_text.test.state }}"
mode: single

About a year ago, the Sonos integration gained a feature to overlay TTS/alerts on top of music (instead of replacing current playback) and allowing to set groups/volume per-call. You should be able to simplify your script considerably. Try something like this instead:

alias: "TTS: for dads phone"
sequence:
  - service: media_player.play_media
    target:
      entity_id:
        - media_player.lounge_s
        - media_player.corridor_s
        - media_player.office_s
    data:
      announce: true
      media_content_type: "music"
      media_content_id: media-source://tts/cloud?message="{{ states.input_text.test.state }}"
      extra:
        volume: 80
mode: single

A couple notes on the above:

  1. This uses media_player.play_media + a special TTS media_source URL to allow the volume to be set per-call. If you don’t need to change the current volume you can simply use the TTS service as before. This method will play the announcement at the provided volume (80% in the above example) and automatically return it to the previous level.
  2. Groups are ignored when using announce: true, so you need to explicitly list each speaker you want the announcement to play on.
  3. If you need to call the TTS service multiple times in a row with different messages, you may need to add delays between them as the first service call will return immediately.

The documentation around this is in the Sonos examples.

1 Like