ebaauw / homebridge-zp

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

Pre-defined Speaker Grouping #50

Closed Garywoo closed 5 years ago

Garywoo commented 6 years ago

Just a suggestion for making life easier for those of us who repeatedly group the same speakers together on a daily basis.

I propose the implementation of a configuration where groups containing multiple speakers could be defined, and expose a Homekit switch accessory for each of these groups. When turned on, the defined speakers in that accessories 'group' would be grouped together in a Sonos group.

When turned off, the defined speakers would be removed from the Sonos group.

I understand there are considerations to be made for existing groups when 'turning on' the Sonos group, and how this should be handled. I for one, would be perfectly happy to have all the speakers in the defined group, leave any current groups they are in when the switch is turned on, and group together into the pre-defined group. When turning off, If other speakers outside of the defined list of speakers have been added to the group, these could either also be ungrouped, or if you wanted to get fancy, a new group could be created which contains only the speakers outside of the defined list of speakers in the group you that has just been turned off (although I think this might be overkill).

The idea for this has come from playing with the web application speakerscenes.com, where pre-defined groups of speakers, aka 'scenes' can be triggered. This implementation uses the Sonos web API. Having a similar control in Homekit would be very useful in my option.

What are your thoughts on this?

ebaauw commented 6 years ago

You can accomplish this already using HomeKit scenes. Simply create a scene switching on the Speaker services of the zones you want to group. In the Home app, you can turn off the scene and the zones are ungrouped again.

Garywoo commented 5 years ago

I have found that using scenes in this way is quite cumbersome if you want to manage multiple groups, even if only one is active at a time. My suggestion would enable support for multiple groups with ease.

For example - my current use case:

With homebridge-zp right now, I have to create multiple automations that fire minutes apart to first un-group everything, then re-group the desired speakers, i.e:

  1. Before alarm - Un-group all
  2. Before alarm - group bedroom + bathroom
  3. After alarm - Un-group all
  4. After alarm - group kitchen speakers

With this described automation-flow, I'm still running into the issue described in #40, where the platform coordinator speaker ends up joining the first group created after un-grouping all speakers.

I believe that a switch to perform pre-defined grouping would allow for more robust grouping, and would remove the need to un-group everything before creating a new group, and think such a feature is worth considering.

ebaauw commented 5 years ago

I have found that using scenes in this way is quite cumbersome if you want to manage multiple groups

Yes. In its current setup, homebridge-zp effectively handles only one group. I understand your use case, and would like to support multiple groups through homebridge-zp. I don't think having pre-defined groups is the answer, though. I want homebridge-zp to mimic, as much as possible, the functionality of the Sonos app in HomeKit. Defining pre-defined groups (in config.json?) is beyond that scope.

It's been quite challenging to match the Sonos functionality to HomeKit. Sonos uses hypermedia controls, where the zoneplayer informs the app what actions are possible at this moment. HomeKit requires a fixed configuration, that is only supposed to change with firmware upgrades. That's why I came up with the current implementation: use each zoneplayer as fixed group (coordinator), and, through the Speaker service, allow another zoneplayer to join this group.

Instead of using the opaque concept of a "platform coordinator" (which I never really liked anyway, because it's not transparent to the user), I could probably list the possible groups (or rather: coordinators) per zoneplayer, and allow the user to pick the coordinator to join. That would probably forego the functionality for a coordinator to leave the group to a new coordinator. To leave the group, simply select the zoneplayer itself as new coordinator.

I'm not sure how best to expose this to HomeKit. If I were to expose each potential group (per zoneplayer) as a switch, Apple's Home app would support this. However, for n zoneplayers, you would see extra tiles. I could use a custom characteristic instead, but then you would need to use another HomeKit app (like Eve) to join or leave a group, or to define a HomeKit scene to do so. Instead of using switches, maybe I could create a dropdown list (i.e. a string characteristic with a fixed list of values), but I'm not sure if that can be used in scenes.

Alternatively, I could list the potential members per zoneplayer (or rather: coordinator). This would result in "only" n(n - 1) extra tiles. When selecting a zoneplayer, it would join the group, potentially stealing it from another group (when it was already a member of another group) or leaving its group to a new coordinator (when it was the coordinator of its own group). When deselecting a zoneplayer, it would become a standalone group. Using a dropdown list would not be possible here, since you want to be able to select multiple members.

ebaauw commented 5 years ago

Did some testing: it would seem that a string characteristic cannot be included in a HomeKit scene, so using a drop-down list is a no go.

I had another idea this morning. Maybe expose the platform coordinator explicitly (as a switch on each Sonos service) and allow users to set it. That way, in the morning, you could assign the bedroom as platform coordinator, and group the bathroom to it, while leaving the kitchen group intact. Not sure if HomeKit scenes keep order (you want to set the coordinator first), so you might need two schedules (one to set the platform coordinator, one to join the bathroom).

ebaauw commented 5 years ago

Could you try v0.3.6-0 (install through sudo npm -g i homebridge-zp@beta)? It provides a new characteristic, Sonos Coordinator in each Sonos service. This allows you to set the platform coordinator, so zoneplayers will join this group when setting the Speaker service On characteristic.

Garywoo commented 5 years ago

I'm now running homebridge-zp v0.3.6-0, however I do not see a Sonos Coordinator characteristic in any of the Sonos services. I restarted both of my Homebridge instances after updating. Should I be doing something else to show the new characteristic?

ebaauw commented 5 years ago

I had to stop and restart Eve before it showed. HomeKit doesn’t like configuration changes.

Garywoo commented 5 years ago

I've force quit and relaunched both the Eve and Controller apps, but neither are showing the new characteristic. I'll try restarting my Apple TVs when I get home to see if that helps.

Garywoo commented 5 years ago

This is working now. Turns out I had conflicting local and global versions - whoops.

Repeated testing by manually triggering the following scenes is working very well indeed! The Kitchen group remains unaffected and intact during the grouping and ungrouping of the Bedroom + Bathroom speakers.

I'll continue testing with daily automation and report any issues I encounter. Thank you very much for solving my problem!

ebaauw commented 5 years ago

Cool. I'll bring out a non-beta release with this shortly.