Automation: play radio to a Sonos speaker group

Hello all,

I have an “issue” in my household, and I would like to solve this major issue with an automation.

We have, everyday Thursday, an cleaning help coming over to do some cleaning.
But she wants to listen to some radio whilst cleaning.

I do ocasionel forget to start the radio, while I’m not at home when she starts.

So I’ve created the automation bellow:
It start’s an radio stream via my Sonos favorites, and starts it on al the speakers I have.
(also sets the volume)

alias: Radio aan
description: ''
trigger:
  - platform: time
    at: '07:45:00'
condition:
  - condition: time
    weekday:
      - thu
action:
  - service: media_player.volume_set
    data:
      volume_level: 0.16
    target:
      device_id:
        - 0dda3fa727cc8ed6f56dce5f4b6f31ec
        - 22cd279ccc8cd7ff6463c532ba66932f
        - 695c9c17c77b698ccde373018697ada6
  - service: media_player.select_source
    data:
      source: '{{ (state_attr("sensor.sonos_favorites", "items").values() | list)[3]}}'
    target:
      device_id:
        - 22cd279ccc8cd7ff6463c532ba66932f
        - 695c9c17c77b698ccde373018697ada6
        - 0dda3fa727cc8ed6f56dce5f4b6f31ec
mode: single

This works just fine, but the streams are not in sync.
It’s as designed in this case.

I’m trying to found out how to create a Sonos speaker group and then stream an radio stream to that specific group.
And that’s where I’m completely stuck.

I did found: Grouping Sonos Speakers
But not sure where to start, and I don’t think this is the right solution for my problem.

Does anyone know how to start this ?

Greetings

You’re on the right track. Use media_player.join to group them together and then call select_source/play_media on one of any of the speakers in the new group. This will use the native grouping features of Sonos and play back in sync across all speakers in the group.

3 Likes

media_player.join did not work for me, found that there are some bugs in the particular service.
I tried sonos.join, and this did work

but thank you jjlawren for pointing me in the right direction :grin:!!

See bellow for the complete automation.
note: it is important that you use the previously selected ‘master’ in media_player.select_source.

alias: Radio aan
description: ''
trigger:
  - platform: time
    at: '07:45:00'
condition:
  - condition: time
    weekday:
      - thu
action:
  - service: media_player.volume_set
    data:
      volume_level: 0.21
    target:
      device_id:
        - 0dda3fa727cc8ed6f56dce5f4b6f31ec
        - 22cd279ccc8cd7ff6463c532ba66932f
        - 695c9c17c77b698ccde373018697ada6
  - service: sonos.join
    data:
      master: media_player.sonos_beam
      entity_id: media_player.keuken_sonos_2
  - service: media_player.select_source
    data:
      source: '{{ (state_attr("sensor.sonos_favorites", "items").values() | list)[3]}}'
    target:
      device_id:
        - 22cd279ccc8cd7ff6463c532ba66932f
mode: single

Note that sonos.join is deprecated and will be removed in the next release. You should see warnings in your logs every time you use it.

How did media_player.join not work for you?

I think my previous configuration was just not correct.

I now replaced ‘Sonos.join’ with ‘media_player.join’ left everything the same as in the config above, and it works.

Thanks for pointing that out.

1 Like

Hi,

I have a use case and I hope someone maybe have an idea.

Is it possible to add a drop down in the dashboard? I’d like to choose which speakers were used for playing music. It’s possible to create groups but I don’t want to create a group for every use case.

Thank you in advance!

Hi i have try similar automatization playing song over the sonos speaker in goup at time but it doesnt work for me. It works for one speaker, but if i add lines with media_player.join then it doesn’t work.

What im doing wrong?

alias: Playing sonos in group at 18:00
description: ""
trigger:
  - platform: time
    at: "18:00:00"
condition: []
action:
  - service: media_player.volume_set
    data:
      volume_level: 0.22
    target:
      device_id:
        - 7b8b78f044249c42b0be53c3ea3a3dce
        - 0fef6654897077098f93f9b479038027
  - service: media_player.join
    data:
      master: media_player.bathroom
      entity_id: media_player.tv_room
  - service: media_player.play_media
    data:
      media_content_id: FV:2/0
      media_content_type: favorite_item_id
    target:
      device_id:
        - 7b8b78f044249c42b0be53c3ea3a3dce
mode: single

Try

  - service: media_player.join
    data:
      group_members:
        - media_player.tv_room
    target:
      entity_id: media_player.bathroom
1 Like

Thank you very much it works great.

Hi, this returns the following error:

. Error calling SonosSpeaker.join on BoseP2: UPnP Error 501 received: Action Failed from 192.168.1.157

Has someone has the same problem?
Thanks.