home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
73.71k stars 30.84k forks source link

Apple TV integration constantly requires reconfiguration after tvOS 17 install #100572

Open mikesalz opened 1 year ago

mikesalz commented 1 year ago

The problem

Upgraded my 3 Apple TVs to tvOS 17 today, and now they require constant reconfiguration.

What version of Home Assistant Core has the issue?

core-2023.9.2

What was the last working version of Home Assistant Core?

core-2023.9.2

What type of installation are you running?

Home Assistant Container

Integration causing the issue

Apple TV

Link to integration documentation on our website

https://www.home-assistant.io/integrations/apple_tv

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

Not sure yet, but this might only manifest after restarting the Apple TV.

home-assistant[bot] commented 1 year ago

Hey there @postlund, mind taking a look at this issue as it has been labeled with an integration (apple_tv) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `apple_tv` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign apple_tv` Removes the current integration label and assignees on the issue, add the integration domain after the command.

(message by CodeOwnersMention)


apple_tv documentation apple_tv source (message by IssueLinks)

postlund commented 1 year ago

Check that AirPlay permissions is set to "Everyone on the same network", they like to change that on updates.

mikesalz commented 1 year ago

@postlund Thanks for the suggestion. Unfortunately that did not help. The setting was already enabled. I tried disabling and then re-enabling it just to be certain. I then reconfigured the Apple TV in Home Assistant. It worked until I restarted the Apple TV, just like before. I even tried completely removing the Apple TV and re-adding it. Same. It works until you restart. Is tvOS 17 working for you, even after restarts?

postlund commented 1 year ago

That sounds a bit strange to me. I haven't updated yet, my schedule right now is pretty insane so I haven't had the time. I will try that soon though and see what happens. Can you check the logs? Should be something there.

mikesalz commented 1 year ago

home-assistant_2023-09-19T17-55-37.566Z.log I enabled debug logging and then reconfigured a couple of Apple TVs. Then I restarted them a couple of times and was asked to reconfigure again. Attached is the log. Please let me know if I can do anything else to help debug!

mikesalz commented 1 year ago

@postlund I made one other observation. After the integration fails and asks for reconfiguration - If I restart HA the integration works again until the next Apple TV restart.

kwithus commented 1 year ago

I have the same problem

mikesalz commented 1 year ago

Hi @postlund - Just curious if you have had a chance to look into this yet? Please let me know what else I can do to help debug. Thanks!

postlund commented 1 year ago

Hi @postlund - Just curious if you have had a chance to look into this yet? Please let me know what else I can do to help debug. Thanks!

Not yet, probably tomorrow.

BarneyHam commented 1 year ago

Just to say - really appreciate this being looked at - same thing happening for me

poudenes commented 1 year ago

Hi all,

I found out when I reboot my AppleTV the connection is lost and have to pair the AppleTV again in HA

tetragram55 commented 1 year ago

I have the same problem but on v16

mikesalz commented 1 year ago

Hi @postlund - Just curious if you have had a chance to look into this yet? Please let me know what else I can do to help debug. Thanks!

Not yet, probably tomorrow.

@postlund With fingers crossed, I installed 2023.10.1 today hoping that this issue would be resolved. But unfortunately it is not. I guess you've been too busy to look into it yet. Again, please let me know what I can do to help. I appreciate it!

kwithus commented 1 year ago

Funny enough my Apple TV integration is currently working again, without any changes on my side. I now updated to 10.1 and it is still working

muhlba91 commented 1 year ago

mine cannot even find my apple tv. with tvos 16 this was working; then i removed the integration due to the upgrade to tvos 17 beta; i try since weeks to add it again with no success (airplay is enabled for everyone).

mikesalz commented 1 year ago

Unfortunately this integration has become nearly useless. Every time I restart one of my Apple TVs - which is daily - the integration fails. Reloading the integration does not work. But restarting HA does fix the issue. @postlund Is this something you are looking into? Haven't heard anything from you in a couple of weeks?

kwithus commented 1 year ago

yes, it’s strange. sometimes it works sometimes not. although it sometimes helps to restart HA, it also sometimes starts to work again out of nowhere and also it stops out of nowhere

poudenes commented 1 year ago

I don't have this issue anymore. Update ha multiple times and reboot but everything is working here...

kwithus commented 1 year ago

maybe we should add info about versions of ATV and TVOS i have ATV Gen 3 and TvOS 17.0 and I have the problems

mikesalz commented 1 year ago

Good call, @kwithus!

I have three Apple TVs. Two are Apple TV 4K (2nd generation) and one is Apple TV 4K (3rd generation). All not working correctly on TVOS 17. And all did work correctly on TVOS 16.x.

muhlba91 commented 1 year ago

i have an ATV 4k (3rd gen) and tvOS 17. with tvOS 16 all worked without any issues - now i can't even pair it = the integration doesn't find the ATV at all.

poudenes commented 1 year ago

Apple TV 4 Firmware: 17.0

Home Assistant 2023.10.1 Supervisor 2023.10.0 Operating System 10.5 Frontend 20231005.0 - latest

No issues

postlund commented 1 year ago

I don't really see this behavior myself that often (it happens every now and then, but not very often as said). I believe one issue is that sometimes connecting to the device fails because of a timeout for some reason. If this happens during connect, it will currently be re-raised as an AuthenticationError and Home Assistant will trigger a reconfig because of that. The idea is just to let that exception pass-through, which instead will just trigger an error and allow the integration to make another connection attempt. I opened an issue about this here https://github.com/postlund/pyatv/issues/2242.

It would help a lot if you that are experiencing this would check your logs and compare the output with the one in the issue above, just so we can conclude it is the same problem. It looks something like this in the log:

Skärmavbild 2023-10-15 kl  19 42 18
mikesalz commented 1 year ago

Hi @postlund - Thank you for looking into this! Here is my full error, which does match what you have shared. Please let me know if I can provide any other information which could be of help.

Authentication failed for Family Room Apple TV, try reconfiguring device Traceback (most recent call last): File "/usr/local/lib/python3.11/asyncio/tasks.py", line 490, in wait_for return fut.result() ^^^^^^^^^^^^ File "/usr/local/lib/python3.11/asyncio/locks.py", line 213, in wait await fut asyncio.exceptions.CancelledError

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/usr/local/lib/python3.11/site-packages/pyatv/protocols/companion/protocol.py", line 121, in _setup_encryption await pair_verifier.verify_credentials() File "/usr/local/lib/python3.11/site-packages/pyatv/protocols/companion/auth.py", line 135, in verify_credentials resp = await self.protocol.exchange_auth( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pyatv/protocols/companion/protocol.py", line 145, in exchange_auth return await self._exchange_generic_opack(frame_type, data, identifier, timeout) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pyatv/protocols/companion/protocol.py", line 170, in _exchange_generic_opack unpacked_object = await self._queues[identifier].wait(timeout) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pyatv/support/collections.py", line 130, in wait await asyncio.wait_for(self._event.wait(), timeout) File "/usr/local/lib/python3.11/asyncio/tasks.py", line 492, in wait_for raise exceptions.TimeoutError() from exc TimeoutError

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/apple_tv/init.py", line 227, in connect_once await self._connect(conf, raise_missing_credentials) File "/usr/src/homeassistant/homeassistant/components/apple_tv/init.py", line 329, in _connect self.atv = await connect(conf, self.hass.loop, session=session) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pyatv/init.py", line 136, in connect await atv.connect() File "/usr/local/lib/python3.11/site-packages/pyatv/core/facade.py", line 681, in connect if await setup_data.connect(): ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pyatv/protocols/companion/init.py", line 573, in _connect await api.connect() File "/usr/local/lib/python3.11/site-packages/pyatv/protocols/companion/api.py", line 143, in connect await self._protocol.start() File "/usr/local/lib/python3.11/site-packages/pyatv/protocols/companion/protocol.py", line 108, in start await self._setup_encryption() File "/usr/local/lib/python3.11/site-packages/pyatv/protocols/companion/protocol.py", line 127, in _setup_encryption raise exceptions.AuthenticationError(str(ex)) from ex pyatv.exceptions.AuthenticationError

postlund commented 1 year ago

@mikesalz That is excellent, thank you! I have made the necessary changes and made a release, just need to bump pyatv into Home Assistant.

IceBotYT commented 1 year ago

This is the error I'm getting that's prompting the reconfiguration. This is only happening on one Apple TV, the other two work.

Authentication failed for Basement, try reconfiguring device
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/asyncio/tasks.py", line 490, in wait_for
    return fut.result()
           ^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/asyncio/locks.py", line 213, in wait
    await fut
asyncio.exceptions.CancelledError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/pyatv/protocols/companion/protocol.py", line 121, in _setup_encryption
    await pair_verifier.verify_credentials()
  File "/usr/local/lib/python3.11/site-packages/pyatv/protocols/companion/auth.py", line 152, in verify_credentials
    await self.protocol.exchange_auth(
  File "/usr/local/lib/python3.11/site-packages/pyatv/protocols/companion/protocol.py", line 145, in exchange_auth
    return await self._exchange_generic_opack(frame_type, data, identifier, timeout)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pyatv/protocols/companion/protocol.py", line 170, in _exchange_generic_opack
    unpacked_object = await self._queues[identifier].wait(timeout)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pyatv/support/collections.py", line 130, in wait
    await asyncio.wait_for(self._event.wait(), timeout)
  File "/usr/local/lib/python3.11/asyncio/tasks.py", line 492, in wait_for
    raise exceptions.TimeoutError() from exc
TimeoutError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/apple_tv/__init__.py", line 227, in connect_once
    await self._connect(conf, raise_missing_credentials)
  File "/usr/src/homeassistant/homeassistant/components/apple_tv/__init__.py", line 329, in _connect
    self.atv = await connect(conf, self.hass.loop, session=session)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pyatv/__init__.py", line 136, in connect
    await atv.connect()
  File "/usr/local/lib/python3.11/site-packages/pyatv/core/facade.py", line 681, in connect
    if await setup_data.connect():
       ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pyatv/protocols/companion/__init__.py", line 573, in _connect
    await api.connect()
  File "/usr/local/lib/python3.11/site-packages/pyatv/protocols/companion/api.py", line 143, in connect
    await self._protocol.start()
  File "/usr/local/lib/python3.11/site-packages/pyatv/protocols/companion/protocol.py", line 108, in start
    await self._setup_encryption()
  File "/usr/local/lib/python3.11/site-packages/pyatv/protocols/companion/protocol.py", line 127, in _setup_encryption
    raise exceptions.AuthenticationError(str(ex)) from ex
pyatv.exceptions.AuthenticationError
IceBotYT commented 1 year ago

This is the error I'm getting that's prompting the reconfiguration. This is only happening on one Apple TV, the other two work.

Authentication failed for Basement, try reconfiguring device
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/asyncio/tasks.py", line 490, in wait_for
    return fut.result()
           ^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/asyncio/locks.py", line 213, in wait
    await fut
asyncio.exceptions.CancelledError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/pyatv/protocols/companion/protocol.py", line 121, in _setup_encryption
    await pair_verifier.verify_credentials()
  File "/usr/local/lib/python3.11/site-packages/pyatv/protocols/companion/auth.py", line 152, in verify_credentials
    await self.protocol.exchange_auth(
  File "/usr/local/lib/python3.11/site-packages/pyatv/protocols/companion/protocol.py", line 145, in exchange_auth
    return await self._exchange_generic_opack(frame_type, data, identifier, timeout)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pyatv/protocols/companion/protocol.py", line 170, in _exchange_generic_opack
    unpacked_object = await self._queues[identifier].wait(timeout)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pyatv/support/collections.py", line 130, in wait
    await asyncio.wait_for(self._event.wait(), timeout)
  File "/usr/local/lib/python3.11/asyncio/tasks.py", line 492, in wait_for
    raise exceptions.TimeoutError() from exc
TimeoutError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/apple_tv/__init__.py", line 227, in connect_once
    await self._connect(conf, raise_missing_credentials)
  File "/usr/src/homeassistant/homeassistant/components/apple_tv/__init__.py", line 329, in _connect
    self.atv = await connect(conf, self.hass.loop, session=session)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pyatv/__init__.py", line 136, in connect
    await atv.connect()
  File "/usr/local/lib/python3.11/site-packages/pyatv/core/facade.py", line 681, in connect
    if await setup_data.connect():
       ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pyatv/protocols/companion/__init__.py", line 573, in _connect
    await api.connect()
  File "/usr/local/lib/python3.11/site-packages/pyatv/protocols/companion/api.py", line 143, in connect
    await self._protocol.start()
  File "/usr/local/lib/python3.11/site-packages/pyatv/protocols/companion/protocol.py", line 108, in start
    await self._setup_encryption()
  File "/usr/local/lib/python3.11/site-packages/pyatv/protocols/companion/protocol.py", line 127, in _setup_encryption
    raise exceptions.AuthenticationError(str(ex)) from ex
pyatv.exceptions.AuthenticationError

I didn't notice the error above was the exact same, my bad! 😅

kevinhaas commented 1 year ago

i have an ATV 4k (3rd gen) and tvOS 17. with tvOS 16 all worked without any issues - now i can't even pair it = the integration doesn't find the ATV at all.

Upgrade to 17 is also what killed the integration for myself. I reset my appletv for an unrelated issue and HA discovered it instantly after the reset.

mikesalz commented 1 year ago

@mikesalz That is excellent, thank you! I have made the necessary changes and made a release, just need to bump pyatv into Home Assistant.

@postlund When do you envision the pyatv version will be bumped in HA? 2023.11?

postlund commented 1 year ago

@mikesalz I plan on making a new release today and hopefully have it included in the next minor 2013.10.x release.

kwithus commented 1 year ago

@mikesalz I plan on making a new release today and hopefully have it included in the next minor 2013.10.x release.

Well, installed 2013.11, problem still persists. Couple of weeks ago I thought it was already solved as the integration was suddenly back to work, but after couple of days it was again broken and it still is. For my HomePods the integration does work, but for the ATV itself it keeps to break up

mikesalz commented 1 year ago

I usually skip the .0 releases. I'll update to 2023.11.1 when it is released and report back as to whether this is working for me.

mikesalz commented 1 year ago

I installed 2023.11.1 yesterday, and so far everything is looking good. When I restart one of my Apple TVs, I can sometimes see the integration trying to reconnect and it occasionally results in an error in the logs. But the important thing is that the integration reconnects each time, rather than completely failing. Thanks @postlund !

kwithus commented 1 year ago

Unfortunately, for me it’s still not working, although I am on 2023.11.1 as well. Even worse, now it’s not only the ATV, one (of three) HomePod doesn’t respond either now. All on 17.1, however the one not working is a HomePod2, the others are HomePod Mini

muhlba91 commented 1 year ago

same here - still no change. HA doesn‘t find the ATV at all.

postlund commented 1 year ago

Not finding the Apple TV and requiring reconfiguration are different issues. I have not seen the reconfiguration problem so far. Connection failures will still happen, but they should not leave the integration in an unusable state (i.e. It should recover at some point without any manual intervention).

@muhlba91 what's your network setup like? Using VLANs?

muhlba91 commented 1 year ago

no VLAN here; i scraped it due to such issues in the past.

HA runs in a k8s cluster virtualized on a Proxmox host which is connected to a 10Gb switch and directly connected to the Wifi AP. The AP is basically besides the ATV (it‘s the version without ethernet).

the k8s cluster is also the reason why auto-discovery of/for integrations on the network doesn‘t work properly and i have to put the static IP address of ATV in when setting up the integration. doing so returns „No devices found on the network“.

ATV airplay is set to everyone, and airplay from other Apple devices works across Apple accounts.

until the tvOS 17 beta everything worked well, then the integration stopped working and i removed it as i wanted to set it up new -> since then no chances to achieve that. i‘m still running on tvOS beta versions though. i had an ATV 4k 1st gen before, and then switched a few months ago to ATV 4k 3rd gen - neither of them worked to het them setup in HA.

kevinhaas commented 1 year ago

The only thing that got it to work for me was factory resetting my 4k 3rd gen; nothing else would get it to show in HA. It was discovered by HA as soon as the reset completed. This is a PITA but anyone who wants it working and is still having issues might want to give it a shot.

Still working for me after updating to 17.1

issue-triage-workflows[bot] commented 9 months ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

poudenes commented 9 months ago

For me there are no issues at all anymore....

kwithus commented 9 months ago

Still same problems here

IceBotYT commented 9 months ago

I'm having the problem where one of my TVs go frequently unavailable, but it doesn't require constant reconfiguration anymore

OCNice commented 8 months ago

I upgraded to 17.4 yesterday, Still doesn't work for me. I guess I'll try resetting.

ste-fle commented 7 months ago

I'm having a similar problem, especially with Homepod (Minis) (everything on 17.4, but indeed might have startet with 17.0) - they constantly lose their connection / state in HA and I frequently have to reload the integration for each of them to get their current state working again.

poudenes commented 7 months ago

Strange. Because I don't have those issues at all...

ste-fle commented 7 months ago

It seems that this always happens when one of them is restarted manually (due to some Airplay or Homekit issues) - afterwards their status won't be visible in HA anymore unless the integration is also reloaded for that particular HomePod.

normalee1993 commented 4 months ago

Has there been any development/news on this issue? I currently have a work around to reload the integration every time my Sony tv gets turned on which turns the Apple TV turned via eARC. It seems that once the Apple TV powers off, it loses its connection status to home assistant.

This happened around the time of tvOS 17 coming. Happy to collect logs if needed to help out.

mikesalz commented 4 months ago

This was "fixed" a while ago, so it does not constantly require reconfiguration as I mentioned in my initial bug description. But as several have pointed out, the integration often disconnects/fails after a restart of the ATV. I created a workaround also - Any time my Harmony remote starts the TV activity, it reloads the ATV integration. That seems to be working. But I don't think we should have to do these kinds of workarounds. @postlund thoughts?

BaconPhat commented 4 months ago

Same here- I took the update to TV-OS17, just updated the latest HASS 2024.7.0, it seems to have made things worse. I have restarted my HA multiple times, things work for a bit, then HA boots out all things Apple TV

poudenes commented 4 months ago

Strange... Here latest tvos and latest HA (update from yesterday) and everything is working great....