Sonos TTS Groups stop working

I have different notifications that play over my Sonos speakers in several automations. Recently, they stopped working correctly. Instead of them playing over the group of speakers, it only plays on the target speaker even though the speakers are grouped. I’m using Amazon TTS. If i disable the TTS action and replace it with a local media action, it works fine. Something broke amazon tts working with sonos groups. i’ve attached a test automation for an example of what i do.

alias: Test Sonos TTS Group
description: test
trigger: []
condition: []
action:
  - service: media_player.join
    data:
      group_members:
        - media_player.den_sonos
        - media_player.kitchen_sonos
        - media_player.office_sonos
        - media_player.master_bedroom_sonos
    target:
      entity_id: media_player.living_room_sonos
  - delay:
      hours: 0
      minutes: 0
      seconds: 5
      milliseconds: 0
  - service: media_player.volume_set
    data:
      volume_level: 0.55
    target:
      entity_id:
        - media_player.living_room_sonos
        - media_player.kitchen_sonos
        - media_player.den_sonos
        - media_player.master_bedroom_sonos
        - media_player.office_sonos
  - delay:
      hours: 0
      minutes: 0
      seconds: 2
      milliseconds: 0
  - service: tts.amazon_polly_say
    data:
      cache: true
      entity_id: media_player.living_room_sonos
      message: <speak> This is a test of the local broadcasting system. </speak>
    enabled: true
  - service: media_player.play_media
    target:
      entity_id: media_player.living_room_sonos
    data:
      media_content_id: media-source://media_source/local/the_clothes_are_dry.mp3
      media_content_type: audio/mpeg
    metadata:
      title: the_clothes_are_dry.mp3
      thumbnail: null
      media_class: music
      children_media_class: null
      navigateIds:
        - {}
        - media_content_type: app
          media_content_id: media-source://media_source
    enabled: false
  - delay:
      hours: 0
      minutes: 0
      seconds: 10
      milliseconds: 0
    enabled: true
  - service: media_player.media_play_pause
    data: {}
    target:
      entity_id: null
  - service: media_player.unjoin
    data: {}
    target:
      entity_id:
        - media_player.den_sonos
        - media_player.kitchen_sonos
        - media_player.living_room_sonos
        - media_player.master_bedroom_sonos
        - media_player.office_sonos
  - service: media_player.volume_set
    data:
      volume_level: 0.25
    target:
      entity_id:
        - media_player.living_room_sonos
        - media_player.kitchen_sonos
        - media_player.den_sonos
        - media_player.master_bedroom_sonos
        - media_player.office_sonos
mode: single

Sonos media_player.play_media support for the announce option was added in 2023.5 and TTS services automatically use this under the hood. The new announce behavior avoids the need to snapshot/regroup/etc and will play over any currently playing music without interruption.

The tradeoff is that you need to explicitly target all rooms/speakers where you’d like the announcement to play and they are called individually, so audio playback may not be perfectly synced. On the other hand, your announcements do not need to care about the current playback or grouping and most scripts/automations can be replaced with a single service call.

See Sonos - Home Assistant for more details, like how to set the volume of the announcement independently of the current music volume.

2 Likes

I have a single ‘speech engine’ script I call in an automation similar to yours that sets the sonos group and volume, with variable “message” data.

In place of the tts service, using the following seems to make the tts play on the sonos group simultaneously as per previous. Not sure how it may work with amazon tts (I’m using google/nabu casa). Hope that helps.

service: media_player.play_media
data:
  announce: false
  media_content_id: >
    media-source://tts/cloud?message="{{ message }}"
  media_content_type: music
target:
  entity_id:
    - media_player.sonos_master