ebaauw / homebridge-zp

Homebridge plugin for Sonos ZonePlayer
Apache License 2.0
241 stars 20 forks source link

Lost connection after few hours of outage #163

Closed edelmaca closed 3 years ago

edelmaca commented 3 years ago

I am shutting down my Sonos system over night and if im not at Home. If I do so, every option to control my Sonos system (tv and speaker option) is disconnected after 6h, maybe less. The only way to get back the controls is to restart Homebridge. Is there a way to get the plug-in reconnect after a set amount of time or is this normally done automatically and I am experiencing a bug?

The log displays some text like "last seen 2000s ago, rebooting?!"

I appreciate any help.

Edit: Is there a way to get around this behavior other than not to shut down the devices every night?

edelmaca commented 3 years ago

Found the "duplicate" issues. #53 and #68 No solution for now, is this correct?

ebaauw commented 3 years ago

Sorry, I added a comment, but probably failed to save it. #53 is a good reference, I don't think #68 is related.

This has nothing to do with the duration of the outage; when the zone player reboots, it loses any subscriptions for notifications (second point in #53). Luckily the zone player reports bootSeq, so Homebridge ZP detects when the player has rebooted. It should re-subscribe when it has detected this, but that doesn't yet work, see #1.

You can probably still control the zone player after reboot from Homebridge ZP, but the current state won't be reflected in HomeKit, as the player no longer sends push notifications.

Indeed, the workaround is to restart Homebridge.

How are you powering down (and back up) the zone players? Manually or using some automation? In the latter case, you can restart Homebridge from the automation. In the first case: pending a structural solution, I could shutdown Homebridge when detecting that a zone player has rebooted. If you run Homebridge as a service, it should be restarted automatically. Would be a config.json option to enable this.

edelmaca commented 3 years ago

Thanks for your answer.

I do shut down my Sonos with an automation every evening after the last detected motion. It reboots in the morning with the first motion. So your first solution should work fine. It is running with hb-service. Is there a setting in place that is capable of restarting homebridge after redetecting a already known device? 🤔 How may I set up something like this?

The dynamic accessory thing would fix this problem for good, right? And you are working on it for quite some time now? I'm Looking forward to the day on which you will get it to work.

ebaauw commented 3 years ago

Is there a setting in place that is capable of restarting homebridge after redetecting a already known device?

Afaik, a plugin cannot restart Homebridge from within Homebridge; it can only stop Homebridge and hope that something like hb-service restarts it. Homebridge ZP already detects that a zone player has rebooted (that's what the log message is about).

The dynamic accessory thing would fix this problem for good, right?

It should. Not so much the dynamic accessories (they already work), but the whole startup/restart logic (basically all open issues, except the sleep time logic). The challenge is that this involves a lot of asynchronous logic: subscribing to notifications for a specific endpoint on the zone player, waiting for the first notification from that endpoint, subscribing to the next endpoint, etc. Not something you fix quickly on a rainy Sunday afternoon.

edelmaca commented 3 years ago

Is there a setting in place that is capable of restarting homebridge after redetecting a already known device?

Afaik, a plugin cannot restart Homebridge from within Homebridge; it can only stop Homebridge and hope that something like hb-service restarts it. Homebridge ZP already detects that a zone player has rebooted (that's what the log message is about).

How could I execute a stop of Homebridge for my issue? Do I have to dig deep or is this fairly easy to implement?

The dynamic accessory thing Sounds way to complicated for me. 🙈 I Hope you can get everything sorted out someday.

ebaauw commented 3 years ago

How could I execute a stop of Homebridge for my issue?

If you run the automation from HomeKit, I would use one of those plugins that allow you to execute a command on the OS, like https://github.com/luisiam/homebridge-cmdswitch2, and make that restart Homebridge through hb-service. Make sure to allow for enough time for all the zone players to have booted, before restarting Homebridge, or you might run into #139.

ebaauw commented 3 years ago

This has nothing to do with the duration of the outage

I stand corrected. Looking at the code, Homebridge ZP tries to re-subscribe the current subscriptions. That will work on a quick reboot of the zone player, but not when the subscriptions have expired, and couldn't be renewed, because the zone player is powered off.

edelmaca commented 3 years ago

This has nothing to do with the duration of the outage

I stand corrected. Looking at the code, Homebridge ZP tries to re-subscribe the current subscriptions. That will work on a quick reboot of the zone player, but not when the subscriptions have expired, and couldn't be renewed, because the zone player is powered off.

Hm, you suggested I could control the zone players without mirroring of functionality in HomeKit. But no, it doesn't matter what I do. On the next Morning I can't control them anymore. I Can't control my Sonos players from HomeKit anymore. I have to restart Homebridge.

ebaauw commented 3 years ago

I need to do some serious testing. The zone players are supposed to be powered on at all times, so I imagined this functionality would be needed only after a power outage, hence no priority.

edelmaca commented 3 years ago

Ok, no worries. It's good enough to know the issue is known and you somehow working on it. We can close this issue. The problem as is, is known already and I will try it with the command line plugin. Thanks for your time and the continuing good work.