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.

Hi together,

since a few days I’m in the HA-world, very komplex but very interesting.

I have seen this very interesting post, which is also interesting for me.

Setup: I have 3 sonos speaker in the room. Is it possible to create a code, which I can start with a button with the following requirement:

  • every single speaker should have a preset (directly in the code) volume-setting

Background: when I’m in the kitchen the kitchen-speaker is near to me and the loudness is maybe to high and the other ones to quit, because they are more far away from me.

With a second button/ scene, for example while eating the dining speaker is nearer than the other ones, so the speaker then should have a other volume setup than in the first situation (cooking in the kitchen).

I`ve tried to adjust the code above to my situation:

type: horizontal-stack
cards:
  - type: tile
    entity: sensor.0x00158d0009ef2161_battery
    icon: mdi:music
    color: pink
    hide_state: true
    name: Play Sonos - Küche
    tap_action:
      action: service
        - service: media_player.volume_set
          data:
            volume_level: 0.22
          target:
            device_id:
              - media_player.ti_kuche
              - media_player.ti_esszimmer
              - media_player.ti_wohnzimmer
        - service: media_player.join
          data:
            group_members:
              - media_player.ti_kuche
          target:
            entity_id: media_player.ti_esszimmer
            entity_id: media_player.ti_wohnzimmer
        - service: media_player.play_media
          data:
            media_content_id: FV:2/0
            media_content_type: favorite_item_id
          target:
            device_id:
              - media_player.ti_kuche
   mode: single

…as expected it doesnt work because I'm new and dont know too much :frowning:

I hope you can help me :slight_smile:

Thank you so much for your time and your help!
Kind regards
Niklas