Sonos unavailable after reboot, error 412 Precondition Failed on ZoneGroupTopology/Event

After rebooting, after installing HA 2024.3.3 on my Rpi4, all my Sonos speakers/entities became unavailable.

Home assistant log states:

2024-03-26 19:15:24.213 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/sonos/__init__.py", line 482, in _async_handle_discovery_message
    await self.async_subscribe_to_zone_updates(discovered_ip)
  File "/usr/src/homeassistant/homeassistant/components/sonos/__init__.py", line 211, in async_subscribe_to_zone_updates
    sub = await soco.zoneGroupTopology.subscribe()
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/soco/events_asyncio.py", line 374, in _async_wrap_subscribe
    await subscribe(requested_timeout, auto_renew)
  File "/usr/local/lib/python3.12/site-packages/soco/events_asyncio.py", line 507, in _async_make_request
    response = await self.event_listener.session.request(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohttp/client.py", line 693, in _request
    resp.raise_for_status()
  File "/usr/local/lib/python3.12/site-packages/aiohttp/client_reqrep.py", line 1060, in raise_for_status
    raise ClientResponseError(
aiohttp.client_exceptions.ClientResponseError: 412, message='Precondition Failed', url=URL('http://192.168.2.216:1400/ZoneGroupTopology/Event')

The ip mentioned is of one of my sonos speakers.

Rebooting the speakers or HomeAssistant doesn’t help. I’ve removed the integration and waited for HA to ‘discover’ Sonos, after which I re-added the integration. Now no speakers are shown at all and the error above occurs for all speakers.

My sonos speakers have been working flawless for the past few months. What can I do to try and debug/solve this issue?

Are your speaking in groups in the Sonos app? Can you reach the speakers in your Sonos app as well?

Thanks for your reply. All speakers are perfectly reachable in the app. Only my soundbar and two Symfonisk-speakers are grouped, my Era100 and ConnectAmp are not grouped.

I’ve tried to set my local HomeAssistant address to Automatic and by manually adding the ip address of my Pi, to no result. My HomeAssistant is connected to NabuCasa cloud.

(I strangely feel like I’m talking to myself every time I see your name lol)

So, are the speakers on one subnet and HA is on another? I had a TON of problems when I did that with mine. I finally ended up moving them back to my main subnet and firewalling the hell out of them.

Scanning over this, it looks like it might be a networking issue: Sonos devices keep becoming unavailable · Issue #88341 · home-assistant/core · GitHub

So, are the speakers on one subnet and HA is on another?

Yes, all devices are in the 192.168.2 range

… it looks like it might be a networking issue: Sonos devices keep becoming unavailable · Issue #88341 · home-assistant/core · GitHub

Thanks! That topic didn’t show up when I googled the issue.
Contributors mention STP over RSTP, but I’m not sure where to configure that.

Another suggestion is to check <sonos-ip>:1400/support/review, but all connections seem fine.

Jhemak mentions that this error message means a subscription mismatch between HA and the Sonos speaker, which should resolve in 20 minutes. In my case, hours have past but the error message in the log remains.
Should I remove the integration, wait for 20 minutes and then add it again?

Jevimenten suggests to put all speakers in one group and restart HomeAssistant.
That didn’t help for me either.

I’d move them over to your main VLAN (which I’m guessing is 192.168.1.0). Then, if you want, you can put some firewall rules around them to prevent them from speaking to the cloud or configure your DNS to black hole them.

That’s usually set in your switch settings (if you are using a managed switch). If you are using something like a Unifi or TP-Link Omada, you can find it in the switch settings. If you are on a consumer router, you probably won’t have those settings.

I’m currently not using vlans. My router (provided by my isp) serves all ips in the 192.168.2 range. The STP/RSTP-setting is nowhere to be found on my router.

Can you go back to an old version and see if it works there? That would allow us to determine if it’d an environmental issue (e.g. it fails in both versions), or if it’d a problem with the new version.

You may also want to submit a bug.

Thank you for your suggestion. I tried several backups, eventually going back to 2024.3.0. Strangely the issue persists, no matter what backup I use.

Positive side effect: My three speakers are back under my sonos integration, but they are again all “Unavailable”. (after removing the integration and re-adding it, no speakers were found at all).

This eliminates that newer HA-subversions caused the issue, but it doesn’t help me any further.

I will try to power-cycle all speakers, keeping them all simultaeously disconnected from power for about 10 minutes or so. Perhaps that “resets” the Sonos-local-infrastructure.

There is an issue here. Trying to digest it now.

This is an error coming back from the Sonos device itself. Almost always this occurs when renewing an existing subscription that the speaker has “forgotten” for some reason, such as when existing subscription network callbacks start to fail. I’m honestly not sure why it would be thrown during the initial subscription, which is what the traceback is showing in the original post.

Has anything changed in your setup, especially related to your network? New equipment, moved router/AP/Sonos locations, etc?

In rare edge cases I’ve run into odd behaviors that I can’t seem to explain that are unfortunately resolved by power cycling the speakers. Possibly the Sonos firmware getting into a bad state I guess.