[Nearing Release] Sonos Advanced Controller

I think so. It doesn't seem like Sonos reuses the numbers from deleted stations/favorites. I've got a bunch of "gaps" in my numbers as well.

1 Like

Over the years I've added and deleted any number of stations and playlists to and from my favorites. Currently, any new favorites will have ID numbers over 600. With a hard limit of 70 favorites, I of course have gaps all over the place.

I've been following this closely and it looks to be a great addition.
I've been holding back on taking the plunge hoping it will be integrated into HPM.
This will make life easier for any updates etc. that may happen.
Are you considering integrating with HPM?
If not, I'll download and have a play.

Many thanks and keep up the great work. :+1:

I looked into HPM, and it doesn't work with libraries. There's some hack to put them inside a bundle, then add the bundle... but that doesn't work since the HPM developer utility doesn't allow adding bundles... So I probably will, but not until I have the app finished. It's just not worth trying to deal with the hassles of HPM until then.

I'm hopefully having a major revamp coming out this weekend anyway... with everything moved to LOCAL methods. I'm renaming it to Sonos Advanced Controller since it'll no longer actually be "Cloud". I've got about half of the commands moved over to local control. The "Add Player" code has all been re-written to use SSDP, too, so it works locally. Also working on putting @CompileStatic on everything I can so it runs faster.

5 Likes

Thanks for the swift reply.
I'll hold off for a few days.
It's no big issue not having it in HPM it just makes life easier for a lazy git like me.... :wink:

You are doing an awesome job with this. Do you sleep at all? :wink:

Keep up the stirling work. :+1:

Hey @Daniel.winks

I just wanted to share my enthusiasm for HPM; it's been a game-changer for me. The ease of installing, repairing, and uninstalling is a real time saver, not to mention those handy notifications for updates. :star2:

I get that libraries can be a bit tricky when used with HPM, but here's a suggestion: why not reach out to @tomw, who built Broadlink IR/RF remote integration? I believe this app uses HPM and libraries. Maybe there is some lesson learned to be shared. Hope this helps you in some way!

Looking forward to Sonos Advanced Controller!

Yeah, I noted that the ESPHome app also uses libraries in HPM via Bundles.

I'm sure I can get it figured out, and I'll toss it all into a GitHub action too, so I don't have to manually do anything. Right now my bundles are built that way.

There's no point in putting "Sonos Cloud Controller" on HPM at this point since I'm doing a near complete re-write and rebranding it "Sonos Advanced Controller". I've got around 80% of everything using local control at this point. Just working on the grouping/ungrouping stuff and it'll be ready to beta. Not much point in it being named something with "Cloud" in it when there's no longer any Cloud utilized.

Some other big improvements are that it will use far less persisted state and instead query things as needed, which should resolve some issues with the grouping/ungrouping. Also adding controls for bass, treble, and loudness, among a few other additions.

I've also found a ton of bugs that all seem to stem from people using some but not all of their speakers in the app. My current code would assume that every member in a group could be resolved to a device in Hubitat, which isn't the case if someone doesn't have a particular speaker added to the HE app. In these cases, it would get a null value and cause a ton of errors.

I've only ever used this personally with all of my speakers added in HE, but I recently picked up a Sonos Roam, and it wasn't added in HE, and I noted a bunch of null exceptions and tracked down the cause. So the new code will instead query the coordinator itself for its group members and use that instead, which works even if the group members aren't all added to HE as 'Sonos Advanced Player' devices.

1 Like

So I have a Roam now, and I noted this too. There's two options in the System menu for the Roam, for "Battery Saver" and "WiFi Power Save", which are enabled by default. Turning those both off seems to have the Roam act like any other Sonos in terms of grouping etc. With them on, I'd add it to a group and it'd show in the group on the official Sonos app and it would just not actually play anything, among other oddities. Turning those options off resolved all that, for what it's worth.

Just wish the Roam was a bit bigger. It's nice and portable, but I don't want to spend $450 on a Move. Maybe Ikea can come out with a $150 approx battery Sonos that's got a bit bigger drivers and battery.

Still, for a "working in the basement/yard" speaker, the Roam will work nicely. Broke the screen protector on my iPhone last summer using it in the yard with a cheapie BlueTooth speaker... with voice control on the Roam I can just drag it around and not need my phone. Lucked out that it was just the protector and not the screen too, since it fell on a rock.

1 Like

Hey Daniel.Winks,

Absolutely on board with the decision to wait for the local transition to be completed before the migration HPM, especially given the upcoming changes. I'd even go so far as to recommend waiting for Sonos Advanced Controller to hit public beta before making the move to HPM; I'm sure there'll be a few hurdles to navigate.

It's fascinating to follow your journey into the realm of local control, and I can't wait for the day when we have a seamlessly functioning Sonos system under local command (except for those Stream Radio station connections, of course).

This Sunday might just free up a bit for me to delve into some testing, and Monday is looking promising too. Given the challenges we've both faced in our setups, it seems like the perfect testing ground. Count me in if you need an extra pair of hands for some advance release testing!

Super pumped about integrating the app into my home production environment full-time. :star2:

Happy Local recoding!

4 Likes

Hi @daniel.winks
I thought I'd give this a go. Here is where I'm at'
I've created a developer account OK and got my Client Key and Client Secret.
I've downloaded 3 files into the library.
I've downloaded the Apps code and OAuth'd it.
I've downloaded 2 driver codes.
I then installed the app and went through the set up by connecting up to my user account and it says my account is connected.
Next I discovered my devices OK (2 of them).
At this point should it define these devices in my device list. I'm not seeing anything new defined.
I do already have them defined using the inbuilt Sonos Integration.
When I click on 'Sonos Virtual Group Devices' I receive this error.

[app:12645](http://192.168.0.24/logs#)2024-01-06 18:40:46.546[error](http://192.168.0.24/logs#)org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object '[]' with class 'java.util.ArrayList' to class 'java.util.Map' due to: groovy.lang.GroovyRuntimeException: Could not find matching constructor for: java.util.Map() on line 409 (method groupPage)

I'm obviously doing something wrong so I was wondering if you could point me in the right direction.
Many Thanks, Bob.

Hey, all new version should be out soon... it doesn't use ANY of that cloud stuff, so there's no need for client key, secret, OAuth, and of that.

Also has a lot of improvements to the player creation and group creation pages.

Give me a bit here and I'll get it posted.

2 Likes

OK thanks.
I'll hold fire until you release your updates.
I'm in no hurry as I have Sonos working up to a point but it is very basic.
I'll go back to my beer and the football (soccer to some). :wink:

Alright everyone, big new release.

First, ALL cloud-related stuff is removed, as everything works locally now. I'm renaming this to "Sonos Advanced" as there's no longer anything "Cloud" about it.

Second, Group Devices have been improved with "switch" capability, and accurately reflect whether the group is "on" or not. I'm working on an improvement to how "Group Players" works, too. Presently, it creates an all new group, with no stream playing. I'll leave this in place as-is. "Join Players To Coordinator" does just that, joins them without interrupting any stream on the coordinator. Also leaving that as-is. But I'm working on a new button, name TBD, that will group all the players together into a new group, and if and only if there's a single stream playing on any one of the players, bring that stream into the new group. If there's 2 or more of the "follower" devices playing, then there's no real way to know which stream to pull in, so in those cases I'll just have it not pull one in.

So if you have "bedroom" and "living room" as a Sonos Group device, with living room as coordinator, and the living room speaker is idle, but the bedroom speaker has a stream playing, there will be a command that will pull them into a group with living room as coordinator still, but rather than being an all-new group with no stream, or having the (non-existent) stream from living room, it'll snag the bedroom stream and move it to the living room when it becomes coordinator.

Similarly, I'll be adding a "Split Group" button that takes whatever stream is playing and starts it playing on each of the members of the group, but with them being a stand-alone coordinator of their one-device "group".

Well, at least I'll add these if functionally it's possible. I'm like 95% sure it is, but I haven't actually dug into it. But it's the next thing I have planned.

I've set up everything on my end for HPM integration, just waiting on my pull request to be approved and merge my repository into the official repository list. In the meanwhile, you can manually add it as a custom repository using this link.

I've also added support for setting bass, treble, and loudness. Looking into being able to set some of the Arc/Beam specific stuff too, as they have a few extra config settings for home theater related stuff. Namely, I want to automate turning "Night Sound" and "Speech Enhancement" on and off. I haven't found where the UPnP control for this exists, if at all, so it'll take some investigation.

I have zero idea whether or not you can in-place upgrade the code... I've got 2 Hubitats, and on my main one, I've only ever had iterative updates as I program things, and on my "testing" hub, I've only tested the all-new all-local version from a "fresh" install via HPM. That said, the way the app works in regard to child devices and their DNIs hasn't changed since I added "current state" a long while back, so it'll probably be OK to update the app/driver code from the old "Sonos Cloud" stuff to the new "Sonos Advanced" ones. But if it doesn't work, then the only thing I can really suggest is just adding "Sonos Advanced" side-by-side to the old app and moving any Rules and stuff over to the new child devices.

This new version uses all-new drivers, and a new app. The old "Sonos Cloud" ones are left in place on GitHub, so if you want to manually upgrade, you'll want to copy/paste in the code from the new drivers and app into your current app and driver code and overwrite it.

Or install the new one side-by-side and move things over... that's probably safer.

Edit: Also forgot, "current state" also now includes "currently playing" album art. Yippie.

5 Likes

So "bundles" are easy to remove. Just click on "Bundles" on the left side of HE, click on the bundle, and at the bottom is a "Delete" button. I don't think deleting a bundle removes any of the libraries, apps, or drivers the bundle installed. So you'll want to go through each of those one by one and remove them, too.

Ok thanks for the headups!

Perhaps a stupid question, but can this work well side by side with the built in app?
Want to make sure playing with this doesn't disrupt my current automations using the built-in version.

And THANK YOU for building this!! The native app is lacking so I also have a bunch of automations that tie into SONOS HTTP running no an rPI to get some of the grouping and join commands working for my needs.

It should be fine. The only thing I can think is that there's probably a limit to the number of "subscriptions" a speaker will allow at once. But since I haven't seen an issue of this, and every "app" does their own subscriptions anyway, I doubt one more will hurt. It should have the same impact on the built-in Sonos app that, say, opening the Sonos app on your phone would cause.

There might be an issue with the built-in one caused by the fact that both use the "magic" 39501 port for routing the "NOTIFY" messages to the app, but I ran both for a while without any trouble.

I've been running just my Sonos Advanced for a while now exclusively. I don't think there's anything the built-in one does that mine doesn't at this point, and quite a lot mine does that it doesn't, obviously.

2 Likes

I think I found a bug. When using the load favorite:

No mater what I select (repeat all, repeat once, none), I'm always getting 'repeat once' which just cycles the first song of the favorite/playlist I chose.

1 Like

Indeed. Looks like I had those still hard-coded from when I originally only had a "load favorite". should be fixed now.

1 Like