Closed saputello2 closed 9 months ago
Thanks for the enhancement request. Could you please describe your use-case a little bit more?
I am currently uncertain if I can provide a substantially faster experience. Could you compare the speed of
atvremote -i 00:11:22:33:44:55 set_output_devices=66:77:88:99:00:11
set_output_devices=66:77:88:99:00:11
in this shell atvremote -i 00:11:22:33:44:55 cli
Thanks so much for replying.
I have a "Movie Time" automation that dims some lights, triggers a linear actuator that raises a projector, as well as lowers a screen. Because the Apple TV can't change its Default Audio Output to an Airplay device (other than a HomePod, etc.), I often have to change it manually to the WiiM Airplay device. (It seems that sometimes I don't have to, and I'm not exactly sure why.) It's not a big deal for me to change it manually, but my wife and kids are not as technically-tolerant as I am, and I've been looking for a way to automate the process of switching output devices when the "Movie Time" automation is triggered.
To answer your questions, I suppose I would like it to execute on the Apple TV startup, since there aren't any use cases other than sending audio through those specific Airplay speakers.
Also, there are no real speed requirements other than tripping up the automation. I've gone back and forth, but I've found that running the automation in the Home App, versus a Shortcut App shortcut, works much smoother.
Executing the code in shell does appear to be faster, but I can't say exactly how much faster (as I can't figure out how to see how long executing the code takes). Running the code otherwise take between 1.7-1.95s. I did notice, additionally, that while running the command, it was about twice as slow when specifying the device by name (-n) versus by identifier (-i).
Overall, I thought that adding the option to change output devices in Apple TV Enhanced would be a nice addition to your already great plugin, as I know many folks out there are annoyed by the fact that the default audio output on the Apple TV can't be changed to an Airplay device. This might be a workaround to "forget" that option isn't available.
Thanks much!
Ok, thanks for the infos.
But before I incorporate this change, I definetly need to make it possible to configure Apple TVs individually ...
Awesome. Thanks much!
Hi @saputello2,
so I have taken a look into that and it is quiet hard to achieve. I would appreciate it, if you would take a look at the feature in version v1.2.0-2.
Please follow the instruction here to set it up.
I am calling that feature experimental since there are a few things that make the experience not very smooth yet:
As you may have seen in the README there is a known issue for pyatv and therefore this plugin:
If using external speakers like HomePods as the default, the Apple TV is always reported as powered on. This is a known issue of the dependency pyatv, see https://github.com/postlund/pyatv/issues/1667. As a result, the Apple TV device will only be shown as off in HomeKit when powered off via the Apple TV device in HomeKit. After restarting the plugin the device will always be shown as on.
This applies for temporary devices as well, which are controlled by atvremote set_output_devices=
. In order to dodge the problem about having a faulty power state, I have implemented the default audio output feature in a way where the Apple TV will connect to the outputs when entering the playing state and disconnecting when leaving the playing state. This way, the user turns off the Apple TV when not playing, the power state should be reported correctly, because the Apple TV is no longer connected to an AirPlay output.
Some players, like the one from Netflix, report faulty devices states when connected to AirPlay devices. Therefore, when enabling default audio outputs in the plugin, it will result in a loop:
Nevertheless, I would like if you could try the feature with something like Disney+ or something were this issue does not occur. I would love to have some feedback.
Thanks much, @maxileith. I'll try it out tonight and get back to you asap.
Hi @maxileith. I was able to reproduce the scenario in the Netflix app. However, the "no longer connected to airplay" dialog only appeared once. No dialogues appeared in Hulu, Disney+, HBO, etc.
Otherwise, the functionality works as you described. When pressing play, the output device changes to the "default audio output" in the config, and when paused the output device reverts back. However, changing the output device significantly upon play/pause significantly impacts the user experience. I found that when pressing pause, it takes about 7-8 seconds before the output device switched to the AppleTV's default audio output; and when pressing play, it takes about 5-6 seconds to change to the "default audio output" in the config.
Perhaps I don't understand the issue (pyatv#1667). However, would it be possible to set_output_devices to airplay devices when the AppleTV wakes, and trigger set_output_devices to the default audio output upon sleep? If this is possible, then the AppleTV would report the correct power state when turned off.
Edit: I was able to reproduce this functionality by configuring Homebridge-Plugin-Command with the following:
cat ./appletv-enhanced/C869CD2428D2/credentials.txt
set_output_devices=00:22:6C:2B:34:2F && touch /tmp/atv_outputcat ./appletv-enhanced/C869CD2428D2/credentials.txt
remove_output_devices=00:22:6C:2B:34:2F && rm /tmp/atv_outputI'm clearly not sure if this is a good way to approach this, but it appears to work pretty well, and the power state of AppleTV Enhanced in the Home App appears to accurate.
However, would it be possible to set_output_devices to airplay devices when the AppleTV wakes, and trigger set_output_devices to the default audio output upon sleep? If this is possible, then the AppleTV would report the correct power state when turned off.
This is not possible since the Apple TV does not report when it is being put to sleep when connected to an audio device.
Your automation only works, because your are using the switches to turn_on or off your Apple TV.
If that works for you that is fine. I will remove this functionality from Apple TV Enhanced since there is no way of reliably determining the on / off state when connected to an audio device.
I cannot publish functionality that conflicts with core features of the plugin.
Hi @maxileith. Thanks so much for looking into this. The automation I have created does work quite well, so I'll stick with that -- I just thought that this may be a possible feature others might be interested in. My apologies if this was a diversion.
You don't need to apologize for suggesting a possible enhancement :)
@saputello2 you just gave me a solution to a problem I've been facing for months. I wanted an easy way to set the airplay 2 output in my Apple TV. Turns out I used your suggestion, created a button with "homebridge Plugin Command" that selects the desired output, in a Homebridge + Apple TV enhanced.
Used this JSON config below
{ "name": "SWITCH NAME", "turn_on": "/bin/bash -c './appletv-enhanced/.venv/bin/atvremote --id AA:BB:CC:DD:EE:FF --airplay-credentials $(< ./appletv-enhanced/AABBCCDDEEFF/credentials.txt) set_output_devices=11:22:33:44:55:66'", "turn_off": "true", "poll_check": "0d0h0m5s", "check_status": "false", "invert_status": "false", "accessory": "Command Accessory" }
thanks a lot!! I searched over web for months to find a solution for this. Im a totally programming newbie. haha
@maxileith congrats for your plugin. It is one of the best made for homebridge. It would be great if we could choose output, but It seems to be something pretty complicated and not reliable enough, totally get it. :)
Current Situation
Thanks for the great plugin!
Proposed Change
I was wondering if there's any way to include the pyatv command set_output_devices for the Apple TV. I was able to hack it a bit using homebridge-plugin-command and sending the following:
atvremote -i 00:11:22:33:44:55 set_output_devices=66:77:88:99:00:11
This allowed me to create an automation that triggers a homebridge switch to send the above command to the Linux terminal, which then changes the Apple TV from the Default Audio Output to an Airplay 2 Device (in this case, a WiiM player). It works quite well, but it's a little slow -- about a 3-5 second delay. Your plugin, on the other hand, pretty much works instantaneously.
Additional Context
No response