Closed emst00 closed 4 years ago
I have the same issue - the problem was, that the Apple TV (Home Hub) was used to play music to Airplay Speakers. After that the logicalDeviceCount
was 1 even though the Apple TV was shutdown.
In this case isGroupLeader
and isAirplayActive
are true.
DeviceInfo DeviceInfoMessage {
airplayReceivers: [ 'TVAirPlay' ],
uniqueIdentifier: 'xxx',
name: 'Apple TV Schlafzimmer',
localizedModelName: 'AppleΒ TV',
systemBuildVersion: '17L256',
applicationBundleIdentifier: 'com.apple.mediaremoted',
protocolVersion: 1,
lastSupportedMessageType: 78,
supportsSystemPairing: true,
allowsPairing: true,
systemMediaApplication: 'com.apple.TVMusic',
supportsACL: true,
supportsSharedQueue: true,
supportsExtendedMotion: true,
sharedQueueVersion: 2,
deviceUID: 'xxx',
managedConfigDeviceID: 'xxx',
deviceClass: 4,
logicalDeviceCount: 1,
isProxyGroupPlayer: true,
groupUID: 'xxx',
isGroupLeader: true,
isAirplayActive: false,
systemPodcastApplication: 'com.apple.podcasts',
enderDefaultGroupUID: 'xxx'
}
@Kienz Those are great findings! Have you figured out a way to determine whether the Apple TV is off despite logicalDeviceCount: 1
?
I've changed the this._isOn = logicalDeviceCount > 0
to the following.
if (m.payload.logicalDeviceCount === 0 || m.payload.logicalDeviceCount > 0) {
if (
(m.payload.logicalDeviceCount > 0 && !m.payload.isProxyGroupPlayer) ||
(m.payload.logicalDeviceCount > 0 && m.payload.isProxyGroupPlayer && m.payload.isAirplayActive)
) {
this._isOn = true;
} else {
this._isOn = false;
}
this.emit('isOnChanged');
}
Have to check the different variants. With this code the Apple TV is displayed Off. But have to check what happens when AirPlay to a Speaker over HomeKit is started.
@Kienz Have you already checked whether your solutions works for all cases?
I think everything works - but not sure if I tested all cases. :#
I integrated your checks into the plugin and published a beta version:
npm install -g homebridge-apple-tv-remote@beta
Has anyone had issues with the beta version? Does it enhance the on/off detection for you?
Hi @lukasroegner, just installed the beta, but t seems to be versioned as homebridge-apple-tv-remote v0.7.7
?
My config is like:
{
"name": "Apple TV Platform",
"devices": [
{
"name": "AppleTV",
"credentials": "token",
"isPlayPauseSwitchEnabled": true,
"playPauseSwitchName": "playPause"
}
],
"platform": "AppleTvPlatform"
}
I've only configured a PlayPause switch since im interested to control some lights based upon its state. (on play -> lights off, pause lights on). After some testing with a Harmony remote, which play/pauses the Apple TV, the PlayPause switch is not always in sync with the actual status of the AppleTV. The switch even changes its state while doing nothing. Like now a movie is playing, the PlayPause switch has state on
, but after a few minutes it changed to state off
and while writing this it changed back to state 'on' again ... and now its 'off' again ...
How do I enable debugging, so I can provide the logs?
@RaymondMouthaan see #7. There are several issues when detecting Play/Pause state:
You can see the raw message coming from the Apple TV with the appletv
command line tool. If you recognize a pattern, which can enhance the play/pause state, feel free to send me your findings.
Has anyone had issues with the beta version? Does it enhance the on/off detection for you?
I tried the beta version. My power switch does not behave adequately at all. I think the latest version is more stable. Sometimes the status stops changing and I restart homebridge, after that everything works perfectly again for a while.
@RaymondMouthaan I published a new beta version (0.8.0) on NPM. Changes:
appletv state
command)-D
to get all messages received by the plugin in the log output)@lukasroegner just for reference https://github.com/lukasroegner/homebridge-apple-tv-remote/issues/7#issuecomment-623089316.
Just installed beta 0.8.0 and enabled debug option -D to homebridge, this gives enormous amount of information, which is to much to handle ...
However I disabled the debug logging and it looks much more stable then before! The homebridge-apple-tv-remote PlayPause switch seems to follow the actual AppleTV device state as it suppose to do, which is awesome!
Tested also with Prime Video, which is shows exact behaviour, so it looks like you smashed this bug π―
I'll test for next coming days, to see if weird behaviour will occur and keep you informed.
Thanks so far for all effort you took in this project and the quick responses!
@RaymondMouthaan That's great! As soon as your testing is completed, I'll integrate the beta branch into master. Can you also check whether the on/off state is now working properly for you?
@lukasroegner as for now PlayPause state is working perfectly fine and stable π
Combined with OnOff switch it looks like the OnOff switch perfectly follows the actual state of the Apple TV device. However one thing I noticed is that PlayPause doesn't turn off when the device is turned off, while is should - after all, it can never be played when the device is turned off. I guess when OnOff is off than also PlayPause should be turned off :)
update: same behaviour happens when no OnOff switch is configured - when the Apple TV gets turned off by remote, the PlayPause switch gets turned on ...
@RaymondMouthaan New beta version 0.8.1: When the plugin detects that the state of the Apple TV switched to off, the play state is also switched to off. Please check if that works properly for you
@lukasroegner wow that was quick .. Im on it π
Two scenarios
When a movie is playing: turning off the Apple TV by remote - switches off OnOff switch but turns on PlayPause switch of the plugin π
When a movie is paused: turning off the Apple TV by remote - switches off OnOff switch but turns on PlayPause switch of the plugin π
update: I did some more testing but the issue remains for both scenarios.
@RaymondMouthaan New beta version 0.8.1: When the plugin detects that the state of the Apple TV switched to off, the play state is also switched to off. Please check if that works properly for you
You are an amazing developer! Thank you very much for your work. I'll test everything today!
@RaymondMouthaan New beta version 0.8.1: When the plugin detects that the state of the Apple TV switched to off, the play state is also switched to off. Please check if that works properly for you
There's still something wrong. Apple tv itself went to sleep, but the power and pause button status remained on. Turned off the TV, it turns off the apple tv via hdmi cec, but in the home app the power switch and pause are all also enabled.
@sergoo-lbt Please start homebridge with -D
parameter and let the Apple TV go to sleep again. During waiting, you should get at least one (large) log entry per minute. I can evaluate the logs to see what data is sent by the Apple TV when it goes to sleep.
@sergoo-lbt Please start homebridge with
-D
parameter and let the Apple TV go to sleep again. During waiting, you should get at least one (large) log entry per minute. I can evaluate the logs to see what data is sent by the Apple TV when it goes to sleep. Here's what I was able to understand. Basically, everything works. But it takes a very long time to change the power state and pause, about a minute. I guess I just didn't wait for them to be fully updated. It turns out that if you turn on the power or pause key several times in a row, the status will not have time to update. I'll try again. I just shared my thoughts. I'm trying to figure out how it all works. I'll attach the logs, but I apologize for the screenshots, I just don't have access to my computer right now.
When I took screenshots, the apple tv was turned off.
So, I did another update of the beta version (0.8.2):
I also tested this version extensively, here are my findings:
Background info: The Apple TV should send messages to the plugin whenever the device state changes (important for detecting on/off state). This, however, does not seem to work reliable. Thus, I implemented a "heartbeat" some time ago, which actively requests the current device state from the Apple TV (this works fine). The current interval is 60 seconds (i.e. every minute the on/off state is updated reliably. You can change the interval with an undocumented config property: in the root of the plugin configuration, add "heartbeatInterval": 10
for a 10 second interval. This can increase the responsiveness, however, will also increase network traffic.
@sergoo-lbt From your logs, I assume that you also have the issue that the on/off state is not updated instantly when turning off the Apple TV. Try (a) the new version, which requests device info update when the play state changes, and (b) to decrease the heartbeat interval.
@lukasroegner, thanks for a new beta. Just updated to this beta (0.8.2) and I'll test it and keep you informed. Good to know about this undocumented heatbeatInterval
, i'll leave it as is, but might change it if some weird behaviour occurs.
@lukasroegner, I did as you said. Added a heartbeat, 10 seconds. I'll attach the result. I did not wait for the change in the power status. With a pause, everything seems to be working fine!
@lukasroegner , I still waited. He updated the status himself. But it was really long, 12 minutes...
@lukasroegner , What is the minimum value of "heartbeatInterval"?
@lukasroegner , Apple tv has been turned off for 10 minutes. The log is always the same.
@sergoo-lbt Even with smaller heartbeat interval, the plugin does not get the Apple TV responses back properly (can be seen from the logs). I would suggest to do a restart of the Apple TV, it seems that there is something wrong.
Rebooted apple tv. Not help. Only restarting homebridge temporarily helps.
@sergoo-lbt Have you tried to change the setup (different Homebridge host, Wi-Fi vs. cable) to determine the cause of your issue?
Only restarting homebridge temporarily helps.
Does that mean that the delay is not present when starting up Homebridge and occurs after some time?
@sergoo-lbt Have you tried to change the setup (different Homebridge host, Wi-Fi vs. cable) to determine the cause of your issue?
You can't connect the cable. I'll experiment with the host! Thanks!
Only restarting homebridge temporarily helps.
Does that mean that the delay is not present when starting up Homebridge and occurs after some time?
Yes, that's right! The status is still updated, but after a very long period of time.
@lukasroegner, here all seems to work stable now .. as for me you can release the beta :-)
Beta is now merged into master, new version 0.8.3 on NPM.
Beta is now merged into master, new version 0.8.3 on NPM.
Awesome! π
Thank you for this plug-in, I find it very helpful. My switch gets stuck to "on" the majority of the time when the AppleTV is off and can't figure out why. I enabled debug mode and this is what I get:
[4/25/2020, 9:02:05 PM] [Apple TV Platform] [AppleTV] Sending heartbeat... [4/25/2020, 9:02:05 PM] [Apple TV Platform] [AppleTV] Connecting... [4/25/2020, 9:02:05 PM] [Apple TV Platform] [AppleTV] Force reconnect: false [4/25/2020, 9:02:05 PM] [Apple TV Platform] [AppleTV] Retry count: 10 [4/25/2020, 9:02:05 PM] [Apple TV Platform] [AppleTV] Already connected [4/25/2020, 9:02:05 PM] [Apple TV Platform] [AppleTV] On/off switch updated to true