core: Sonos : UPnP Error 501 and Large Sonos Installations
The problem
I have 20+ Sonos devices that always work great via the Sonos applications. However, they almost never work via the HA Sonos integration. I am constantly receiving this error in the HA logs:
Failed to request visible zones from IP ADDRESS: UPnP Error 501 received: Action Failed from IP ADDRESS
Very rarely, I see the devices show up as working in HA… but, they usually start throwing the above 501 error and/or go unavailable within a few minutes of interacting with them via HA. They continue to work fine in the Sonos apps before, during, and after these errors occur.
I’m happy to provide logs and try anything to resolve the issue.
I seem to be having the same issue as #70194… That issue describes all of the issues and my environment pretty well. I also have a lot of Sonos devices and UniFi network equipment. I have tried everything from that thread including the adjustments to STP within the UniFi environment.
#61003 and #43190 also seem to be similar issues which were never fully resolved.
#70194 is the closest to what I am experiencing where we both have a large Sonos system on a UniFi network architecture… but all of these issues seem to revolve around having a large Sonos installation.
I also found this thread in the HA forums which is describing similar issues. Some of the more recent comments mention UniFi network components and large Sonos networks.
It’s also worth mentioning that the Sonos Cloud integration always seems to work fine as well, but obviously doesn’t have the full Sonos functionality. Thanks @jjlawren !!
What version of Home Assistant Core has the issue?
core-2022.11.4
What was the last working version of Home Assistant Core?
No response
What type of installation are you running?
Home Assistant OS
Integration causing the issue
Sonos
Link to integration documentation on our website
https://www.home-assistant.io/integrations/sonos/
Diagnostics information
config_entry-sonos-347495fd55deaa8ed6ce64fc5992d3ee.json.txt
Example YAML snippet
No response
Anything in the logs that might be useful for us?
Logger: homeassistant.components.sonos
Source: components/sonos/__init__.py:191
Integration: Sonos (documentation, issues)
First occurred: 7:58:43 PM (1296 occurrences)
Last logged: 9:28:31 PM
Failed to request visible zones from 10.10.10.111: UPnP Error 501 received: Action Failed from 10.10.10.111
Failed to request visible zones from 10.10.10.139: UPnP Error 501 received: Action Failed from 10.10.10.139
Failed to request visible zones from 10.10.10.250: UPnP Error 501 received: Action Failed from 10.10.10.250
Failed to request visible zones from 10.10.10.192: UPnP Error 501 received: Action Failed from 10.10.10.192
Failed to request visible zones from 10.10.10.128: UPnP Error 501 received: Action Failed from 10.10.10.128
Additional information
No response
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 1
- Comments: 33 (11 by maintainers)
Thank you! For the first time, all of my Sonos devices are available on startup
Pull again, things were still out of sync. Sorry, it’s been a long day.
I posted my theory on what’s happening over here. I have a rough idea on how to address this in HA (no library changes necessary), but it’s not a super trivial change as it requires a bit of redesign. I hope to find time over the holidays but no promises.
For anyone following this thread, I was able to use @jjlawren 's test script to reproduce the UPnP 501 errors and this is what I found:
After a lot of trial and error… I think @jjlawren is on to something with the payload size being the determining factor causing the UPnP 501 error. I tried many different configurations to get different payload sizes and whenever the payload was 16403 or above, polling ZGS would fail, and I would get the UPnP 501. If the payload was 16313 or lower, polling ZGS would succeed and no error. I don’t know exactly what the max payload for polling is, but it is somewhere between 16314 and 16403. These results are very repeatable, I can change the system configuration by one Sonos device to either go above or drop below these values and the polling either fails or succeeds based on the payload size of the polling callback. Of course, I tried many other payload sizes above and below the range here (with the same results), but here is the relevant data to determine max payload of the polling callback:
15487 Success 15996 Success 16313 Success 16403 Fail 16418 Fail 16594 Fail 16608 Fail 16823 Fail
One other note on this, I think the reason I was able to power cycle the system and then use the HA integration for a while is that if all the Sonos devices get powered off and then powered on again, the payload size is going to be effectively “reset”. It will take time for the system to rebuild and for the payload to get above ~16313, so I believe I was just seeing the integration working while Sonos was rebuilding it’s network. Once the payload got above that max size, I would start seeing those UPnP 501 errors again.
Also, the subscription callbacks never fail regardless of payload size… only polling ZGS fails above a max payload that is somewhere between 16314 and 16403.
https://github.com/home-assistant/core/pull/85411 should address this issue and hopefully make the integration a bit more efficient for everyone.
The custom component has been updated to share the same code as that PR for easier testing. Please report any problems with the current state if you encounter any.
For anyone that’s using the custom component, please pull the latest as I’ve (hopefully) fixed a few bugs I’ve uncovered after updating tests. Once things look good I’ll get the changes into the built-in integration.
Thanks again for all your hard work @jjlawren, I and the community appreciate it and hope you have a wonderful holiday
I have a WIP fix for early testing if anyone is feeling like living on the edge. I’ve ported it over to my custom component repo based on top of 2022.12.8. Here’s how to install:
After this you should have a directory named
/config/custom_components/sonos/with the contents of everything you see here.Note: this branch does not yet support manual configurations (e.g., Sonos IPs hardcoded in the
configuration.yaml). One of the discovery methods (SSDP, ZeroConf) must work to test this WIP fix.Thanks @jjlawren !
I think it’s exciting we’ve discovered so much about an issue which has seemingly been around forever and nobody has figured out. The fact that we’ve even made progress on this has me much more optimistic than when I opened the issue. Please enjoy your holidays and if this gets fixed anytime in the future then that would be amazing. 👍
If you’re on the HA Discord you can find me there with the same name.
@cmaglio Yes, I have 27 Sonos devices (so under the ‘32 device limit’). They always all work fine using the Sonos app but I’ve love to have working scripts, automations and Custom Sonos Card in HA.