ebaauw / homebridge-zp

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

Playback controls don't work when streaming from Airplay Source #185

Closed rfiorentino1 closed 2 years ago

rfiorentino1 commented 2 years ago

Issue

If starting a stream from an I-device through airPlay 2, the plugin cannot control play/pause, or next/previous track. Is this an airplay/sonos limitation, or something else? Odd thing is, it can be controlled from the Sonos app itself. For me, play/pause just advances to the next track for some reason.

ebaauw commented 2 years ago

That’s odd. Normally, the zone player indicates when it can accept play, pause, or next/previous track, and both the Sonos app and Homebridge ZP adjust accordingly. Do you see the input changing to Airplay in HomeKit? If not try restarting Homebridge and see if that solves the issue. Otherwise, please capture and attach a debug log file, see https://github.com/ebaauw/homebridge-hue/wiki/FAQ#homebridge

rfiorentino1 commented 2 years ago

Hi Erik,

This has become rather interesting. I restarted homeBridge because of something else yesterday, and the issue still persisted, both yesterday and today. But when I restarted in debug mode, everything worked perfectly. I went back out of debug mode, and back in again, and finally got it to reproduce itself, so seems to be semi-consistent. I'll apologize in advance for the ridiculous length of this log, as well as the persistent errors from Rainbird; I know why they're occurring, I just haven't gotten a chance to fix it yet. If there's some way of me shortening/filtering the logs so you don't have to sift through so much, please let me know and I'd be happy to do it. homebridge.log-2.txt

Another thing to note: I'm using another HB plugin, called "Sonos Multi-Room" to handle grouping within HomeKit, because I couldn't get the Sonos coordinators to function properly within ZP. Multi-room also lets you specify priority zones for each room, which can come in handy. That's the other Sonos reference in the logs though.

On the surface, it looks like the track change parameter is either stuck on 1, or changes inside HomeKit but doesn't actually change what's playing. The title of the track also doesn't change consistently, and it showed only the living room as being set to airplay, while the other zones that were grouped with the living room showed "leave kitchen and 3 others" etc.

Please let me know if there's anything else I can do to help, thank you so much for looking into this, much appreciated.

ebaauw commented 2 years ago

I'll apologize in advance for the ridiculous length of this log

Don't worry. As long as you attach the file instead of copy/paste-ing the contents, I can handle it.

[10/26/2021, 6:52:30 PM] [Pico] Back Porch Pico - Off single press
[10/26/2021, 6:52:30 PM] [Sonos] Back Porch Sonos: Track Change changed from 0 to 1
[10/26/2021, 6:52:30 PM] [Sonos] Back Porch Sonos: set Track Change from 1 to 0

I assume you map the Off button on the pico to next track? Indeed the Track Change characteristic is changed from HomeKit, but nothing seems to happen. After 0.5 settings, the characteristic reverts to 0 (by design, so a next change can be input).

[10/26/2021, 6:51:42 PM] [Sonos] RINCON_F0F6C192799901400 [Back Porch]: notify MediaRenderer/AVTransport/Event
[10/26/2021, 6:51:42 PM] [Sonos] Back Porch Sonos: set currentTransportActions from ["Set","Stop","Pause","Play","Next","Previous"] to ["Stop","Play"]
[10/26/2021, 6:51:42 PM] [Sonos] Back Porch Sonos: set currentValidPlayModes from [""] to ["CROSSFADE"]

According to the log, the Back Porch Sonos cannot accept Next Track at the moment, so Track Change cannot do anything. Other than explicitly logging a warning in that case, there's little I can do, I'm afraid.

I'm using another HB plugin, called "Sonos Multi-Room" to handle grouping within HomeKit

That shouldn't be an issue; Homebridge ZP won't see what other Sonos clients you're using and this would be no different from using the Sonos app.

[10/26/2021, 6:51:41 PM] [Sonos] Back Porch Sonos: set Sonos Group from "Back Porch" to "Master Bathroom + 3"
[10/26/2021, 6:51:41 PM] [Sonos] Back Porch Sonos: set Sonos Group from "Master Bathroom + 3" to "Master Bathroom"
[10/26/2021, 6:51:41 PM] [Sonos] Living Room Sonos: set Sonos Group from "Living Room + 1" to "Master Bathroom + 3"
[10/26/2021, 6:51:41 PM] [Sonos] Living Room Sonos: set Sonos Group from "Master Bathroom + 3" to "Master Bathroom"
[10/26/2021, 6:51:41 PM] [Sonos] Master Bathroom Sonos: set Sonos Group from "Master Bathroom" to "Master Bathroom + 3"
[10/26/2021, 6:51:41 PM] [Sonos] Master Bedroom Sonos: set Sonos Group from "Master Bedroom" to "Master Bathroom + 3"

This is kinda odd: Back Porch and Living Room join the Master Bathroom group, but the group name of the Master Bathroom Zone hasn't yet been updated. I think they were in the Living Room group before?

When Kitches joins a bit later, it seems to sort out:

[10/26/2021, 6:51:42 PM] [Sonos] Back Porch Sonos: set Sonos Group from "Master Bathroom" to "Master Bathroom + 4"
[10/26/2021, 6:51:42 PM] [Sonos] Kitchen Sonos: set Sonos Group from "Living Room + 1" to "Master Bathroom + 4"
[10/26/2021, 6:51:42 PM] [Sonos] Living Room Sonos: set Sonos Group from "Master Bathroom" to "Master Bathroom + 4"
[10/26/2021, 6:51:42 PM] [Sonos] Master Bathroom Sonos: set Sonos Group from "Master Bathroom + 3" to "Master Bathroom + 4"
[10/26/2021, 6:51:42 PM] [Sonos] Master Bedroom Sonos: set Sonos Group from "Master Bathroom + 3" to "Master Bathroom + 4"

I couldn't get the Sonos coordinators to function properly within ZP. Multi-room also lets you specify priority zones for each room, which can come in handy.

Typically with Homebridge ZP, you would create a HomeKit scene, setting Sonos Coordinator (on the Sonos service) for the target group, and setting On (on the speaker service) of the new member(s). See also https://github.com/ebaauw/homebridge-zp/issues/94#issuecomment-516969748.

rfiorentino1 commented 2 years ago

Interesting. Do you know what could cause ZP to think that a track change cannot be excepted? Because if I were to do it from within the Sonos app, it works normally. Also strange to me that it works flawlessly sometimes, and other times not at all, but only with AirPlay as the source. All other sources work consistently, every time. Wondering if anyone else can replicate this?

I’m not sure what’s going on with that living room and master bathroom grouping thing, that’s also interesting. Thank you for referring me to the other issue regarding the coordinator, that explains a lot. One more thing, after I restarted homebridge out of debug mode, ZP seemed to rebuild itself completely. This meant that all of my Eve scenes/rules had no actions, because it thought those zp Devices didn’t exist anymore. I had to reconfigure every scene/automation, but have no idea what could’ve caused this, and would hate to have to randomly redo all of this automation/mapping if that were to happen again. Thank you for taking the time to respond to these issues and develop this plugin, it’s much appreciated.

ebaauw commented 2 years ago

Do you know what could cause ZP to think that a track change cannot be excepted?

The zone player sending the AVTransport event. There’s a lot happening at 6:51:42. It might be a timing issue, that the event from before the Back Porch has fully joined the group is handled after Homebridge ZP has registered the device under the group. However, the other players seem to send a similar AVTransport event. Maybe that is specific to Airplay?

I noticed in the code I’m actually checking the possible actions on the member zone instead of on the coordinator zone. However, the commands are sent to the coordinator zone. Maybe that could be the difference between the Sonos app vs Homebridge ZP.

One more thing, after I restarted homebridge out of debug mode, ZP seemed to rebuild itself completely. This meant that all of my Eve scenes/rules had no actions, because it thought those zp Devices didn’t exist anymore.

That happens when the zone players cannot be reached when Homebridge ZP starts. Especially tricky for battery-powered players. See #139.

rfiorentino1 commented 2 years ago

Hmmm. And if you’re checking the actions on member zones, instead of the coordinator, would it matter that I have no coordinators set within ZP, even though there are grouped players? I would imagine this would be the same as setting groups from Sonos, instead of directly in ZP, so I wouldn’t think that would affect anything. But if I’m the only one experiencing this issue, maybe there’s something wrong with my setup…

i’ve also noticed that when switching between TV, airplay, etc, the inputs in HomeKit don’t always change with the actual source. Wondering if that has something to do with this too, because airplay is seen as an input, while all other sources are not.

rfiorentino1 commented 2 years ago

A few more updates: Everything has been working great with airplay/controlling it for a little while, but today it stopped again. this time I had the iOS music app pulled up, and noticed that when I paused a zone player from ZP, the music app still showed as playing. I had to manually restart playback from the phone to hear audio. Restarting homebridge, and/or restarting an airplay stream also seems to fix the issue. Not sure if any of this is helpful, but wanted to let you know

ebaauw commented 2 years ago

noticed in the code I’m actually checking the possible actions on the member zone instead of on the coordinator zone. However, the commands are sent to the coordinator zone. Maybe that could be the difference between the Sonos app vs Homebridge ZP.

Using the coordinator values since v1.4.9.