Sonos Group Comments

Hi all,

Set Up:

I have a fair few sonos speakers around the house, all connected to OH
I also have a doorbell that is connected through Alexa, (thanks for the idea @rlkoshak), which triggers an item switch ON if press.

The idea is to get certain sonos speakers to play a sound / speak when the doorbell is pressed to alert us.

I have created a rule, which does just this, Blockly code below:

This works surprisingly well, but is just a bit clumsy.

Essentially, I’ve got a gSonosDoorbell group where the speakers I want to use are in. The rule checks to see if the doorbell item, (aArloDoorBellPress), is ON, and if it is it then gets the name of each member of the group in turn and sends them commands:

It plays mp3s from the Doorbell playlist on Sonos, (I did this so I can put whatever I want in there, doorbell, dog barking etc)
It sets the volume
It tells the speaker to play
It repeats the mp3 in the playlist
It sends me a notification
After 25 seconds it stops everything.

This works well and upon triggering the rule the speakers play the doorbell sound, the doorbell then repeats a couple of times more before the 25 second timer ends.

The issue is that they just ride roughshod over anything that is playing at the time, doesn’t return the speaker to the original state and, as the rule take a few (milli) seconds to run through each member, the doorbell isn’t at the same time on all speakers causing a cacophony of doorbells through the house.

It does mean that we won’t miss the doorbell but it will come with a moaning wife, which I don’t want!


I know it’s possible to group speakers within the sonos app, which syncronises the sound played and when I was playing with the same process through the Alexa app it managed to pause what was playing, play the doorbell and then return to what it was previously playing…

I don’t want to get too technical with the rule and find that it takes 5/10 seconds to set up and run as by that time the person ringing will have left but I would really like it to be a more elegant solution as I can see the basis of this rule being useful elsewhere in my system for announcements etc.

So, is there a better way to write the rule or perhaps to grab the existing settings, group the speakers, do the doorbell, and then ungroup them back. OR is there some sort of ‘announcement’ function or channel that I could use to better effect?

Anyone out there managed something similar or have any guidance? TIA

Rather than sending the commands to each speaker in turn, you can setup a group for the speakers and send the commands to the group instead. Not sure if it will help improve the performance, but worth a try.


Thanks, I’ve got them in a group in OH but couldn’t work out how to send commands to the group as a whole, that’s why I set the rule to go through the members one by one.

I was hoping to be able to set the group members as a Sonos speaker group somehow and then I could sent the commands to it rather than each speaker…I just can’t work out if that is possible from OH.

I know it’s possible as I’ve seen widgets that group speakers…off to trawl the community forum once more :slightly_smiling_face:

You would need to create individual groups for each item type. E.g. one group for all volume items, one group for all media control items etc.

However openhab will still send individual commands to each speaker, it would “just” make your rule easier.

You mentioned that you can group the speakers within the sonos app. Try to include this sonos-group as a speaker into OH and send your command to this new speaker group

Ah, sorry, misunderstood you…yes, that would be a neater solution and an easier rule, thanks. I’ll keep it in mind if my plan a below doesn’t work out.

I’m going to try to work out what command to send to group the speakers from OH to within sonos, if I can do that then I’m on to a winner I think. I believe, once I’ve got OH setting up a sonos group it will then sync the playing, (as it does if I were using the sonos app directly), and then can just pass it group volume etc.

I’ve found a few widgets and rules in the community that seem to do it so just need to decompile them to dig out the little but that I want.

Have a look into the documentation, the notificationsound channel is explicitly listed and the difference between notification and playlist explained

I’ve got most of the way there…after some deep diving into some code…

So, I’ll post more when I’m 100% comfortable with it all but you have to set one speaker as the local coordinator, then Add the other speakers to it to create a group.

Then you can send the local coordinator the volume / uri etc and it will play in sync for the whole group.

My head is now mush so I’ll carry on tomorrow and post the results.

EDIT - Turns out it doesn’t need to be a local coordinator after all…it’s all about how you add speakers to the group…see below.

So, here’s where I’m at…

So, things I’ve learnt. Sonos is VERY particular about how you interact with it.

The _NotificationSound channel is great to get Sonos to pause any music that is playing, play the notification, and then resume the music.

That works peachy if you only want to send the notification to one speaker.

If you want to play the notification to a group of speakers then it’s a bit more complicated.

To group a set of speakers you must pick one speaker and add others to it using the _Add channel.
The command isn’t the item name but the RINCON name of the sonos speaker itself.
When you add speakers into a group they automatically audio sync meaning that once grouped you only have to send the notification / volume etc commands to the first speaker, (the one you added the others to).

To ungroup the speakers you have to use the _StandAlone channel.
Good - the first speaker, (the one you added the others to), will resume exactly where it left off before the notification.
Bad - the other speakers will return to the same song / album etc you were listening to but will remain paused, (it seems the notification pauses the current thing when the speaker is brought into a group of speakers).

There are _save and _restore channels that are supposed to save and restore each speakers settings but in reality saving the speaker settings blocks you from adding it to a group. The _Save channel seems to lock the speaker to its setting rendering it useless to any further commands.

So, now to my rule. It’s still a work in progress but it works as I want it to, (except one thing which I’ll come onto in a bit), so it will now just be a case of refining the rule and making it more generic should I want to add / remove speakers…maybe some OH grouping etc.

The rule -

I check to see if the trigger item is ON, ie the doorbell has been pressed.

I set the name and RINCON to variables. I then check to see if the speakers were playing or paused so I can return them to the same state at the end.

I then _Add the other speakers to create a group
I send a doorbell sound to the _NotificationSound channel
I also send a message to the TV and my phone
After 25 seconds, (seemed a good amount of time for the doorbell to chime):
I turn the doorbell trigger item OFF
I ungroup the speakers
I wait 2 seconds to allow Sonos to return the speakers to their original song etc.
Then I give them the original play / pause state

I’ve nested that into a timer so that if the person at the door pushes the doorbell again it will keep playing the doorbell.


Now to my issue, I can’t get the damn rule to play the OH doorbell in the sounds/doorbell.mp3 file. I’ve set the callbackURL in the binding to the url of my OH instance, (in a docker on a Synology), and you can see the url entry on the rule. I’ve tried various different urls to see if I need to be explicit, ie docker/openhab/conf/sounds/doorbell.mp3 etc but nothing works.

The closet I think I’ve come is what is in the rule currently as it makes sonos pop up an error for about a second:


You wouldn’t believe how long it took me to spot the error, it really is a blink and you miss it pop up in sonos player.

Anywho, there it is for now FWIW. If anyone has any tips on the doorbell sound please let me know!