🎙️ Sonos Grouping and Ungrouping using Motion Detection

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.
GitHub Link

Original Post by MarvinS

Version: 1.0

Group a Sonos device to a main device when presence (e.g. motion) is detected and the main device is playing music.
Can be extended with custom conditions, for example, only group the Sonos when you’re not asleep.

The Automation Process:

  • In this example we will use a motion sensor as the trigger but you can use one or multiple Binary Sensors as the trigger/s.
  • Triggers on a motion sensor and adds the Sonos speaker (target) in the room to a group (source).
  • When no motion is detected, a time delay is activated and removes the Sonos player from the group Automatically.
  • The Sonos speaker will remain GROUPED if the motion sensor detects motion before the time delay removes the Sonos speaker from the group. It will then reset the time delay after last motion is detected.
  • You have the option to add “Custom conditions”. This allows you to extend this blueprint with more advanced YAML syntax.
  • You have the option to set the “Allow TV” option. When selected, the target Sonos Speaker will join the group even if the group is playing audio from the TV.
  • You have the option to adjust the “Time Delay”. This will increase or decrease the amount of time it will take before the target Sonos Speaker will leave the group again.

:star2: Contributors

  • MarvinS - The original author
  • omni - Updated the blueprint for the 2022.5 update
1 Like

Any chance you could update it so the joined speakers can have their volume set?

I join a TV speaker to the group, but it always joins real loud, from the kids playing music.

2 Likes

This is great!
is there a trick to not have a fixed source speaker, so just join any playing speaker?

thanks!

Hi @legovaer

Im extending this blueprint with an option to set the volume. which worked, but i want to make it pretty and dont change the volume if none has been set.
and that last part i cant get to work. As this is my first work on a script or blueprint in home assistant ever can i get a bit of help?

using this code:

          - alias: "Set volume if set"
            service: >
              {% if volume != "0" %}
                media_player.volume_set
              {% else %}
              {% endif %}
            target:
              entity_id: !input sonos_target
            data:
              volume_level: !input volume

But if i dont specify a value for volume its setting it to 0, instead of not changing it.

Full code is here: Home Assistant Blueprint that joins and leaves Sonos speakers on motion · GitHub

Like i said, my first time :slight_smile:

1 Like

Are you able to show an example of the format for custom conditions please? I’m looking to have a boolean that is set to on, before it joins.

Hello,

Is it possible to specify several Sonos speakers here as a source for grouping?
I have 3 rooms and would like to group them one by one as you go into the rooms.
The whole thing should be dynamic, since the room where the music was played changes here and there.
I tried changing multiple to true in the blueprint for source, but it didn’t work.

If you split the blueprint at the moment, the last speaker will simply be grouped out again.

It would be better if the speakers were gradually grouped together and then gradually removed from the group again.

The whole thing really has potential

Thank you for that

Hi, did you manage to get the “last part” working? If I understand you currently you want the “long press on play” that you can do on each device, right? It will join the last active session. Would be a great feature to have

Hi!

i didnt. im still looking for help :slight_smile:

Hi, I have been playing with this and I can get the name of the entity by doing this

{{ (expand(states.media_player) | selectattr('state','eq','playing') | sort(attribute='last_updated', reverse='true') | map(attribute='entity_id') | list)[0] }}

This just finds the last updated media players entity name. This should be similar to what a long press on the playbutton on a sonos device actually does.

What I fail to understand is how to then use the entity (that I now have as a string) in the blueprint above. Can I make a sensor return an entity? Greateful for all help here. Thanks