Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Currently playing track stops when grouped #94

Closed
mylesagray opened this issue Jul 29, 2019 · 11 comments
Closed

Currently playing track stops when grouped #94

mylesagray opened this issue Jul 29, 2019 · 11 comments
Labels

Comments

@mylesagray
Copy link

mylesagray commented Jul 29, 2019

When grouping zones with a scene by turning the speaker attribute to on the currently playing track is stopped.

This is the case when the scene specified that sonos as coordinator and when it wasn’t coordinator.

I seem to be unable to reliably get it to group and continue playing, like I can in the Sonos app - am I missing something?

@ebaauw
Copy link
Owner

ebaauw commented Jul 29, 2019

Not sure what you mean. Could you post a screenshot of the scene?

Afaik, the order of characteristics in a scene is not defined, so it might be challenging to set the coordinator and join another zone player that coordinator it in a single scene.

@mylesagray
Copy link
Author

Sure thing - scene is here:

Scene

The problem I'm having is that when I run this scene, to group all speakers - whatever is playing stops and needs manually restarted.

When I'm in the Sonos app and I group all zones the music keeps playing.

@ebaauw
Copy link
Owner

ebaauw commented Jul 30, 2019

The Office Speakers are included twice? You haven't included setting the Power State of the Kitchen Sonos on?

So if I understand correctly, the Kitchen Sonos was playing before you activate this scene, but stops when you activate it The Kitchen Sonos wasn't setup as Sonos Coordinator.

What I think happens is that the speakers (incl. Kitchen) actually join the previous Sonos Coordinator which isn't playing anything. Or the other players don't join anything, because Kitchen is still, or has just become, a member of another group and because of that, cannot be joined. Or the Kitchen was a member of another zone, and stopped playing when it left that zone.

Could you list a screenshot from the Rooms view in the Sonos app from before, and from after activating this scene? What version of homebridge-zp are you on? Do you see any http status 500 messages in the log when activating the scene? Can you run homebridge -D and list the log from when activating the scene.

@mylesagray
Copy link
Author

Office Speakers are there twice because there are two Sonos zones in there (two play 1s and a connect) - I did include Power State of Kitchen Sonos, but it made no difference, playback would stop.

Correct - Kitchen Sonos was playing, when I run the above scene it stops, it seems that another Sonos may have been the coordinator and there is a race when the scene activates?

Here is the before:

Before

And after:

After

If I select the playing zone within the Sonos app and tell it to group "Everywhere" it continues to play. It is almost certainly a race condition that the grouping is done before the coordinator is set?

I am on the latest - 1.0.7.

Logs for Grouping scene:

[7/31/2019, 12:52:26 PM] [ZP] Office Speakers: On changed from false to true
[7/31/2019, 12:52:26 PM] [ZP] Office Speakers: set On from false to true
[7/31/2019, 12:52:26 PM] [ZP] Kitchen Sonos Sonos: set Sonos Coordinator from true to false
[7/31/2019, 12:52:26 PM] [ZP] Office Sonos: set Sonos Coordinator from false to true
[7/31/2019, 12:52:26 PM] [ZP] Office Speakers: On changed from false to true
[7/31/2019, 12:52:26 PM] [ZP] Office Speakers: set On from false to true
[7/31/2019, 12:52:26 PM] [ZP] Living Room Speakers: On changed from false to true
[7/31/2019, 12:52:26 PM] [ZP] Living Room Speakers: set On from false to true
[7/31/2019, 12:52:26 PM] [ZP] Kitchen Sonos Speakers: On changed from false to true
[7/31/2019, 12:52:26 PM] [ZP] Kitchen Sonos Speakers: set On from false to true
[7/31/2019, 12:52:26 PM] [ZP] Kitchen Sonos Sonos: Sonos Coordinator changed from false to true
[7/31/2019, 12:52:26 PM] [ZP] Kitchen Sonos Sonos: set Sonos Coordinator from false to true
[7/31/2019, 12:52:26 PM] [ZP] Office Sonos: set Sonos Coordinator from true to false
[7/31/2019, 12:52:26 PM] [ZP] Living Room Sonos: set On from false to true
[7/31/2019, 12:52:26 PM] [ZP] Kitchen Sonos Sonos: set On from false to true
[7/31/2019, 12:52:26 PM] [ZP] Office Speakers: set On from true to false
[7/31/2019, 12:52:26 PM] [ZP] Office Speakers: set On from true to false
[7/31/2019, 12:52:26 PM] [ZP] Kitchen Sonos Sonos: set Sonos Coordinator from true to false
[7/31/2019, 12:52:26 PM] [ZP] Office Sonos: set Sonos Coordinator from false to true
[7/31/2019, 12:52:26 PM] [ZP] Office Speakers: set On from false to true
[7/31/2019, 12:52:26 PM] [ZP] Living Room Sonos: set Sonos Group from Living Room to Office
[7/31/2019, 12:52:26 PM] [ZP] Living Room Sonos: set On from true to false
[7/31/2019, 12:52:26 PM] [ZP] Living Room Sonos: set Volume from 28% to 100%
[7/31/2019, 12:52:26 PM] [ZP] Kitchen Sonos Sonos: set Sonos Group from Kitchen Sonos to Office
[7/31/2019, 12:52:26 PM] [ZP] Kitchen Sonos Sonos: set On from true to false
[7/31/2019, 12:52:26 PM] [ZP] Kitchen Sonos Sonos: set Volume from 36% to 100%
[7/31/2019, 12:52:26 PM] [ZP] Kitchen Sonos Sonos: set Track from Hybrid - Black Treacle (Summer Mixtape) to 
[7/31/2019, 12:52:26 PM] [ZP] Office Sonos: set On from false to true
[7/31/2019, 12:52:27 PM] [ZP] Office Sonos: set Volume from 100% to 31%
[7/31/2019, 12:52:27 PM] [ZP] Kitchen Sonos Sonos: set Volume from 100% to 31%
[7/31/2019, 12:52:27 PM] [ZP] Living Room Sonos: set Volume from 100% to 31%
[7/31/2019, 12:52:27 PM] [ZP] Office Sonos: set On from true to false
[7/31/2019, 12:52:27 PM] [ZP] Office Sonos: set Volume from 29% to 31%

Logs for ungrouping scene:

[7/31/2019, 12:51:39 PM] [ZP] Office Speakers: On changed from true to false
[7/31/2019, 12:51:39 PM] [ZP] Office Speakers: set On from true to false
[7/31/2019, 12:51:39 PM] [ZP] Office Speakers: On changed from true to false
[7/31/2019, 12:51:39 PM] [ZP] Office Speakers: set On from true to false
[7/31/2019, 12:51:39 PM] [ZP] Kitchen Sonos Speakers: On changed from true to false
[7/31/2019, 12:51:39 PM] [ZP] Kitchen Sonos Speakers: set On from true to false
[7/31/2019, 12:51:39 PM] [ZP] Living Room Speakers: On changed from true to false
[7/31/2019, 12:51:39 PM] [ZP] Living Room Speakers: set On from true to false
[7/31/2019, 12:51:40 PM] [ZP] Office Speakers: warning: set On: timed out
[7/31/2019, 12:51:40 PM] [ZP] Office Speakers: warning: set On: timed out
[7/31/2019, 12:51:40 PM] [ZP] Kitchen Sonos Speakers: warning: set On: timed out
[7/31/2019, 12:51:40 PM] [ZP] Living Room Speakers: warning: set On: timed out
[7/31/2019, 12:51:47 PM] [ZP] Living Room Sonos: set On from true to false
[7/31/2019, 12:51:47 PM] [ZP] Living Room Sonos: set Track from Hybrid - Black Treacle (Summer Mixtape) to 
[7/31/2019, 12:51:47 PM] [ZP] Office Sonos: set On from true to false
[7/31/2019, 12:51:47 PM] [ZP] Office Sonos: set Track from Hybrid - Black Treacle (Summer Mixtape) to 
[7/31/2019, 12:51:47 PM] [ZP] Office Sonos: set On from true to false
[7/31/2019, 12:51:47 PM] [ZP] Office Sonos: set Track from Hybrid - Black Treacle (Summer Mixtape) to 
[7/31/2019, 12:51:48 PM] [ZP] Office Sonos: set Sonos Group from Kitchen Sonos to Office
[7/31/2019, 12:51:48 PM] [ZP] Living Room Sonos: set Sonos Group from Kitchen Sonos to Living Room
[7/31/2019, 12:51:48 PM] [ZP] Office Sonos: set Sonos Group from Kitchen Sonos to Office
[7/31/2019, 12:51:50 PM] [ZP] Kitchen Sonos Sonos: set Volume from 31% to 36%
[7/31/2019, 12:51:50 PM] [ZP] Office Sonos: set Volume from 31% to 29%
[7/31/2019, 12:51:51 PM] [ZP] Living Room Sonos: set Volume from 31% to 28%
[7/31/2019, 12:51:51 PM] [ZP] Office Sonos: set Volume from 31% to 100%

@ebaauw
Copy link
Owner

ebaauw commented Jul 31, 2019

Office Speakers are there twice because there are two Sonos zones in there

I didn't realise it was possible to have multiple zones with the same name. This will confuse the hell out of homebridge-zp, which registers zones under the zone name. It will take me some considerable effort to change that to registering zones under the id of the master zone player. Even then, the Homebridge log using zone names would continue to be confusing. For now, could you please change the name of the of the zones?

Your screenshots looks very different from the Sosos app on my devices. Maybe because of SoundCloud? I expected to be able to see what zone was the coordinator after the scene, instead of just "Everywhere".

It is almost certainly a race condition that the grouping is done before the coordinator is set?

Yes. Looking at the log, the first Office Sonos steals the role of Sonos Coordinator from the Kitchen Sonos, when the Office Speakers is turned on.

[7/31/2019, 12:52:26 PM] [ZP] Office Speakers: On changed from false to true
[7/31/2019, 12:52:26 PM] [ZP] Office Speakers: set On from false to true
[7/31/2019, 12:52:26 PM] [ZP] Kitchen Sonos Sonos: set Sonos Coordinator from true to false
[7/31/2019, 12:52:26 PM] [ZP] Office Sonos: set Sonos Coordinator from false to true

Not sure why they don't simply join the Kitchen Sonos group, maybe the Kitchen Speakers are off? This shouldn't happen, the Speakers should be forced on when the zone player is Sonos Coordinator.

Next, the Speakers for the other players, including Kitchen are turned on, and they join the Office group:

[7/31/2019, 12:52:26 PM] [ZP] Office Speakers: On changed from false to true
[7/31/2019, 12:52:26 PM] [ZP] Office Speakers: set On from false to true
[7/31/2019, 12:52:26 PM] [ZP] Living Room Speakers: On changed from false to true
[7/31/2019, 12:52:26 PM] [ZP] Living Room Speakers: set On from false to true
[7/31/2019, 12:52:26 PM] [ZP] Kitchen Sonos Speakers: On changed from false to true
[7/31/2019, 12:52:26 PM] [ZP] Kitchen Sonos Speakers: set On from false to true

Next, the Kitchen Sonos Coordinator is switched on, and Kitchen takes over from Office:

[7/31/2019, 12:52:26 PM] [ZP] Kitchen Sonos Sonos: Sonos Coordinator changed from false to true
[7/31/2019, 12:52:26 PM] [ZP] Kitchen Sonos Sonos: set Sonos Coordinator from false to true
[7/31/2019, 12:52:26 PM] [ZP] Office Sonos: set Sonos Coordinator from true to false
...
[7/31/2019, 12:52:26 PM] [ZP] Office Speakers: set On from true to false
[7/31/2019, 12:52:26 PM] [ZP] Office Speakers: set On from true to false

I'm not sure what's happening next, I really need the homebridge -D output here. I think the GroupManagement events are coming in, from the other zone players joining Office, and homebridge-zp copies the coordinator state.

[7/31/2019, 12:52:26 PM] [ZP] Living Room Sonos: set On from false to true
[7/31/2019, 12:52:26 PM] [ZP] Kitchen Sonos Sonos: set On from false to true
...
[7/31/2019, 12:52:26 PM] [ZP] Living Room Sonos: set Sonos Group from Living Room to Office
[7/31/2019, 12:52:26 PM] [ZP] Living Room Sonos: set On from true to false
[7/31/2019, 12:52:26 PM] [ZP] Living Room Sonos: set Volume from 28% to 100%
[7/31/2019, 12:52:26 PM] [ZP] Kitchen Sonos Sonos: set Sonos Group from Kitchen Sonos to Office
[7/31/2019, 12:52:26 PM] [ZP] Kitchen Sonos Sonos: set On from true to false
[7/31/2019, 12:52:26 PM] [ZP] Kitchen Sonos Sonos: set Volume from 36% to 100%
[7/31/2019, 12:52:26 PM] [ZP] Kitchen Sonos Sonos: set Track from Hybrid - Black Treacle (Summer Mixtape) to 
[7/31/2019, 12:52:26 PM] [ZP] Office Sonos: set On from false to true
[7/31/2019, 12:52:27 PM] [ZP] Office Sonos: set Volume from 100% to 31%
[7/31/2019, 12:52:27 PM] [ZP] Kitchen Sonos Sonos: set Volume from 100% to 31%
[7/31/2019, 12:52:27 PM] [ZP] Living Room Sonos: set Volume from 100% to 31%
[7/31/2019, 12:52:27 PM] [ZP] Office Sonos: set On from true to false
[7/31/2019, 12:52:27 PM] [ZP] Office Sonos: set Volume from 29% to 31%

It would seem the Office Sonos has no current input selected, but is still On. Not sure how that's possible.

However the Sonos Coordinator role is once again stolen from Kitchen. Not sure if this is by the first or second Office Sonos.

[7/31/2019, 12:52:26 PM] [ZP] Kitchen Sonos Sonos: set Sonos Coordinator from true to false
[7/31/2019, 12:52:26 PM] [ZP] Office Sonos: set Sonos Coordinator from false to true
[7/31/2019, 12:52:26 PM] [ZP] Office Speakers: set On from false to true

@ebaauw ebaauw added the bug label Jul 31, 2019
@ebaauw
Copy link
Owner

ebaauw commented Jul 31, 2019

I've been doing some additional testing, but it would seem that the logic around joining and leaving zone groups has become too complex over the years, even for me. We started out with just using the On characteristic of the Speaker service. Later we added the SonosCoordinator characteristics to the Sonos service. As of v1, we added the Input Source for the television accessory.

I think it's time for a redesign:

  • The On characteristic of the Speaker service should match the first input of the television accessory. It's value is:
    • true when the zone is a non-coordinator member of a zone group. In this case the input reads "Leave current coordinator"; and
    • false when it's a coordinator (of either a standalone group, or of a group with other members). In this case the input reads "Join target coordinator", unless the zone is the target coordinator, in which case the input is hidden.
  • Setting the Speaker service On matches selecting the "Join target coordinator" input: the zone joins the group of the target coordinator. You cannot set On when the zone is the target coordinator.
  • Clearing the Speaker service On matches selecting the "Leave current coordinator" input: the zone becomes coordinator of a standalone group, leaving its current group. Typically this resets the input for the new standalone group.
  • Neither setting nor clearing the Speaker service On changes the target coordinator.
  • At any given time, only one zone can be the target coordinator. This is the only zone for which the SonosCoordinator characteristic in the Sonos service is set.
  • There should always be a target coordinator, so you cannot set Sonos Coordinator to false. You can only set SonosCoordinator of the new target coordinator to true. The target coordinator is persisted across Homebridge restarts.
  • The target coordinator should never be a non-coordinator member zone, or other zones cannot join it. When SonosCoordinator is set while the zone is a member of another group, it takes over as coordinator for that group. This will cause a brief hiccup when the group was playing, as the new coordinator starts buffering the input stream.
  • To set the target coordinator from the TV accessory, select View TV Settings from the Settings screen. I think this is better than using one of the unused keys in the Remote widget, to prevent accidentally switching the target coordinator.

With this design, it will no longer be possible for a coordinator to abandon the group to a new coordinator by clearing On (because it is already false). Instead, you first need set SonosCoordinator of the new coordinator, which causes On of the old coordinator to be set, as it becomes a member.

Normally, setting SonosCoordinator takes effect immediately, as the whole concept of "target coordinator" is unique to homebridge-zp. Only when the new target coordinator was a member of a group, it takes a while to change coordinators. In theory, I could block HomeKit during the transition (hopefully preventing it form issuing another characteristic change), but that's tricky and prone to Unreachable accessories when done wrong.

Doing some testing with Eve and with Matthias' Home app, it would seem that the characteristics are applied in the order in which the were added to the scene (even thought neither app shows the order). You might want to re-create you scene, making sure the SonosCoordinator is set first.

@mylesagray
Copy link
Author

Okay I did two things and one of them seems to have fixed it - recreated the scene adding the Coordinator service first, and secondly, not adding the Speaker Power on service for the Sonos I wanted to be the coordinator (in this case Kitchen).

The music continued to play when executing the scene - so either it’s the order of adding the coordinator or not adding the speaker service for the target coordinator that made it work.

@ebaauw
Copy link
Owner

ebaauw commented Jul 31, 2019

Cool. I think it's the order, but as I mentioned above, there's something odd about how setting the speaker service on currently influences the target coordinator.

ebaauw added a commit that referenced this issue Aug 4, 2019
Bug fix:
- Logic around `SonosCoordinator`, see #94.
ebaauw added a commit that referenced this issue Aug 4, 2019
Bug fix:
- Logic around `SonosCoordinator`, see #94.
- Handle multiple zones with same name, see #96.
- Only subscribe to `ZoneGroupTopology` evenst of "associated" zone player, cf. Sonos app.
ebaauw added a commit that referenced this issue Aug 4, 2019
Bug fix:
- Logic around `SonosCoordinator`, see #94.
- Handle multiple zones with same name, see #96.
@ebaauw
Copy link
Owner

ebaauw commented Aug 4, 2019

v1.0.8 should work according to the re-design in my post above.

@mylesagray
Copy link
Author

Installed 1.0.8 - so now if I create a scene, regardless of order we should be good to go?

@ebaauw
Copy link
Owner

ebaauw commented Aug 7, 2019

No, the order still matters, but setting the Speakers on will no longer change the sonos coordinator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants