Jump to content
View in the app

A better way to browse. Learn more.

Universal Devices Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Join Command for Sonos

Featured Replies

@bpaauwe

@bpwwer

Bob, Would you be willing/able to add a join function to the Sonos Polyglot plug in? I realize you forked this over from the ST-Sonos plugin which incorporated the join function. Issue with the ST version as you recall was that the way the individual units were queried messed up the order and as such units would join other units randomly.

Happy to pay for your time on this request

Thanks in advance

Edited by pjjameso
User name

The Sonos plug-in and the ST-Sonos plug-in were completely separate efforts.

I ported the Sonos plug-in from PG2 to PG3 for UDI since the original author seemed to have abandoned it.

The original author of ST-Sonos handed it over to me after he decided to stop writing plug-in and I think moved on to other HA technologies.

I'm generally OK with trying to fix issues, but adding features is quite a bit more work for code I didn't originally write. I also don't have any Sonos devices so not only do I have to rely on others, like you, to test any changes I make. I also need some direction on how this should work within the plug-in. I understand the general concept of a join(), but how that should be implemented on a speaker node and what it should look like are where I'd need help. I can't run the plug-ins beyond making sure they load, without any Sonos devices, I can't create nodes.

Another thing, looking at the library that the plug-in is using, it's using a version of the library from 2019. I don't know if it's possible to update to the latest version without re-writing the plug-in.

I'm willing to try, but I'm not sure it's possible without me having the actual devices.

  • Author

Thank you Bob for your thoughtful response. Fully appreciate how difficult it would be to update code without a device to test. Im thinking the easiest way to progress, if you are willing, is to modify the ST-Sonos plug-in as it has all the features of the Sonos plug-in but with the join command included.

The issue with ST-Sonos is that the numeration of the individual Sonos units keeps changing. So when I create a program and the if statement is executed the then statement may join with another Sonos unit vs the one originally saved in the program. I have even tried to delete all the sonos units except for the two I want to join based upon the program but all the units keep reappearing.

Buttkicker - [ID 0032][Parent 0001][Not Enabled]

If

'Emporia / Bmt UPS' Killowatts >= 0.4000 kW

Then

Set 'ST-Sonos / Buttkicker' Join Basement

Else

- No Actions - (To add one, press 'Action')

Let me know if you want to step back from this request or take a look and see if its a quick fix or much more involved.

I've played around with ST-Sonos and modified it to create fake zones and speaker nodes. I'm not sure I can explain this well with just text but I'll try.

The Sonos zone topology is dynamic. As you do joins/unjoins and if speakers go on/off line Sonos changes the topology. IoX/PG3 can adapt to those changes somewhat but the problem becomes very apparent if you try to use programs to change that topology.

Say you have 4 speakers and none have been joined. This will give you a topology that looks like:

zone 1 / speaker 1 
zone 2 / speaker 2
zone 3 / speaker 3
zone 4 / speaker 4

You create a program that says join speaker 4 to speaker 2. Now your topology looks like:

zone 1 / speaker 1
zone 2 / speaker 2 & speaker 4
zone 3 / speaker 3

Now you go back to the program interface and you only have 3 options to join with instead of 4. Any program that made use of zone 4 will fail because zone 4 no longer exists in your topology.

IoX programs created with one topology will possibly make no sense if that topology no longer exists.

There's no way from PG3 to fix programs created in IoX, it doesn't have any way to do that. So I can't really see anyway to resolve the issue your having. The ST-Sonos plug-in mostly adapts to the change in topology but there isn't any way to communicate this to IoX and IoX has no way to adapt.

  • Author

Bob, is there a way to place an option box in polyglot to not create specific nodes? Thinking I would just delete all the nodes except for the two I want have joined. I have manually deleted them but as you noted they keep reappearing.

The answer is probably a qualified yes. Both plug-ins are designed to do auto discovery of the speakers on your network. The Sonos (not ST-Sonos) plug-in does give the option to manually add speakers, but it does this after doing the auto discovery, not in place of.

It would be possible to add custom parameter support to the ST-Sonos plug-in where you specify which speakers you want. Then during auto discovery it would only add nodes for speakers that it found that matched what you configured. I don't really want to try this, I'd be modifying code I don't fully understand without being able to really test.

It would be a lot easier to modify the Sonos plug-in to only do auto discovery if no speakers were manually specified. This could be a breaking change that effects other users of this plug-in. Also we're back to me trying to add the join command too. Of the two options, I'd rather attempt this as I feel more comfortable modifying the Sonos plug-in vs. the ST-Sonos plug-in.

I've uploaded a version of the Sonos plug-in to the non-production store. This version supports adding specific speakers and doing so, disables the auto detection of speakers. I've added the join/unjoin commands.

I've tested it as much as I can by creating a speaker simulator, but that really just allows me to create the nodes, it doesn't allow me to test the join/unjoin commands as I can't figure out the communication needed to do that.

To add specific speakers, you use a similar method to adding speakers manually, by adding custom parameters:

key = only_<unique> where <unique> will be the unique speaker address. For example: only_living

value = {"name": "<speaker name>", "host": "192.168.1.43"} where <speaker name> is the name of the speaker (and will be the node name)

You can add as many as you want, but I think only the first 5 will currently work.

There are a number of cases that I don't account for and have no idea what will happen if you attempt them. You are supposed to only join a speaker to a coordinator, but that's what causes all the trouble with ST-Sonos, which speakers are coordinators changes dynamically. My implementation in the Sonos plug-in ignores that. It will allow you to attempt to join a speaker with any other configured speaker. If that speaker is not a coordinator, it should ignore the request, but may crash. I believe unjoin will fail silently if the speaker is not currently joined, but again, it could crash.

The list of speakers generated for programs should be always be the same (for the same configuration).

I think this handles your use case so try it out and let me know.

  • Author

Bob, As expected the join command is not working... On another note, I missed something as each time I restart the sonos plugin if finds all the speakers. Was there something I needed to add to stop the auto discovery?

Im heading out of town for a couple of weeks so wont be able to reply to you after tonight. Appreciate the effort, I will ping you when I return if you are still interested in pursuing a solution

I'm lurking here as I (and everyone else with Sonos speakers, I assume) have the same issue with the random joining.

However, I use ST-Sonos rather than the Sonos plug-in. But I'm willing to switch if successful.

If this can't be "fixed", can it be accomplished through Network Resources instead? I believe it's possible to pause/play/next/previous/shuffle + volume up/down, but I'm not sure certain speakers can be joined.

Thanks,

Ross

The problem is that the Sonos topology is dynamic and IoX programs are not. ST-Sonos maintains a list of "coordinators" which are speakers that manage a grouping. You can only join a speaker to a coordinator. IoX programs that use the join command also use that list, but since IoX doesn't ever use strings, it uses the index to the coordinator name on the current list. If the coordinator list changes (which it may as speakers join/unjoin or go on/off line, or the plug-in is restarted) and the program executes, it will execute using the original index into the list as it was at the time of program creation. When that index no longer represents the same speaker/coordinator, you have problems.

The ST-Sonos plug-in is correctly representing the Sonos topology. But IoX provides no way to update a program's parameter list dynamically.

What I'm attempting to do with the Sonos plug-in is to create a fixed, never changing list for the programs. When the plug-in starts, it creates a list of speakers (not coordinators). It then uses this list as the parameter to IoX programs. Since the list is always fixed (well as long as you don't allow the plug-in to restart and dynamically build the list) the program's parameter index should always point to the same speaker.

The main problem with this is that since it is a list of speakers and not coordinators, if the program executes and tries to join with a speaker that is not currently a coordinator, it's going to fail. However the program is trying to do what you asked it to do.

I don't think you'd have the same issue with network resources as I think you'd be specifying the coordinator name embedded into the network resource and not an index into a changing list of coordinators.

The only way this could be "fixed" is if IoX programs would save the name instead of the index in the program. But given the IoX design, I'm not sure it's even possible without completely re-designing IoX's program infrastructure.

I'll continue to try and get my changes to the Sonos plug-in to work, but I'll need debug logs since I can't test much beyond creating some fake nodes. An including the time frame you ran the test helps because debug logs can be 20,000 lines or more and searching them for when you were testing can be difficult.

@pjjameso When the custom parameters are correct, it should skip the auto detect of speakers an it should display a notice in PG3 that it did skip auto detect. Here's my configuration.

image.png

With this configuration I get two speaker nodes; Office Speaker and Basement Speaker. No Living Room Speaker node is created since using the "sonos_" prefix in the key is handled as part of the auto-detect code in the plug-in. So I'm pretty sure it is bypassing the auto-detect code. But since I have no real speakers, I can't be 100% sure.

Create an account or sign in to comment

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.