Plop, plop. Apple TV integration keeps taking a dump

Hi @_Mike - It’s exactly the same for me. My Apple TV, which is a 4th generation device, turns off every now and then because of power cuts. After that when I restart HA it’s picked up.

Yep @_Mike, exactly that. However, a HA restart doesn’t get mine back, it leaves the old devices, but detects new ones too. Only when I delete the old ones am I able to add them again.

Hi everyone,
Same here, I loose the apple tv control everytime it goes to sleep. Then I have to restart HA and reinstall the apple tv integration.
Any ideas on how to fix this please ?
Thanks :slight_smile:

To me it sounds kinda insane that you have to re-install then integration (I assume you mean removing it and adding it agin?). Restarting Home Assistant or reloading the integration should work just fine, but it should also recover automatically anyways. I however suspect that you are running into this error:

Which was fixed by:

Which in turn will be available in the next release. Please check logs confirm. If that is not the case, we’ll have to look deeper at the debug logs for the component.

1 Like

Hello @postlund,
Thank you for your answer.
It looks like this is going to solve my case (hoping so !).
I’ll keep you posted. :slight_smile:
Have a great evening !

@postlund Well, unfortunately 2021.4.0 does not fix my Apple TV integration issues. I get the following with all 3 of my Apple TV units after restarting them. Restarting HA fixes the issue. Until the next time I restart one of the Apple TV units.

Logger: homeassistant.components.apple_tv
Source: components/apple_tv/init.py:330
Integration: Apple TV (documentation, issues)
First occurred: 8:12:58 PM (2 occurrences)
Last logged: 8:13:06 PM

Failed to connect

Traceback (most recent call last): File
“/usr/src/homeassistant/homeassistant/components/apple_tv/init.py”, line 246, in _connect_loop await self._connect(conf) File “/usr/src/homeassistant/homeassistant/components/apple_tv/init.py”, line 330, in _connect self.atv = await connect(conf, self.hass.loop, session=session) File “/usr/local/lib/python3.8/site-packages/pyatv/init.py”, line 76, in connect await atv.connect() File “/usr/local/lib/python3.8/site-packages/pyatv/mrp/init.py”, line 703, in connect await self._protocol.start() File “/usr/local/lib/python3.8/site-packages/pyatv/mrp/protocol.py”, line 103, in start self.device_info = await self.send_and_receive(msg) File “/usr/local/lib/python3.8/site-packages/pyatv/mrp/protocol.py”, line 180, in send_and_receive return await self._receive(identifier, timeout) File “/usr/local/lib/python3.8/site-packages/pyatv/mrp/protocol.py”, line 188, in _receive await asyncio.wait_for(semaphore.acquire(), timeout) File “/usr/local/lib/python3.8/asyncio/tasks.py”, line 501, in wait_for raise exceptions.TimeoutError() asyncio.exceptions.TimeoutError

Logger: pyatv.mrp.protocol
Source: /usr/local/lib/python3.8/site-packages/pyatv/mrp/protocol.py:44
First occurred: 8:12:53 PM (2 occurrences)
Last logged: 8:12:53 PM

heartbeat 5 failed after 2 tries

image

I have submitted this issue:

1 Like

Thank you _Mike for pointing this out, I have the EXACT same issue with an Apple TV 4K tvOS 14.4 on Home Assistant core-2021.4.4… It happens from 2 to 6 times a week.
I really hope someone will find a fix for this soon. :slight_smile:

1 Like

@Ripper2909 I’m sorry to hear you’re having the issue too. Let me know if you find a workaround!

I have this issue as well; HA keeps finding new instances of the one AppleTV 4 that we have in the house. For the moment I have the Apple TV configured according to the regular setup, and I disabled the integrations’ search feature to stop if from discovering more. That does seem to prevent the integration from continually ‘discovering’ my AppleTV again and again.

One automation I made to “dirty fix” this is to reload the Apple TV integration everytime my TV is turned on.
Hope that helps while waiting for a real fix. :slight_smile:

1 Like

@Ripper2909 I didn’t know there was a way to do this! Can you please share your code?

All you have to do is to connect your Android TV as a media_player.
When this entity is not off, trigger an automation that reloads the Apple TV integration like this : Add service integration.reload - #44 by dmatora (thanks to @dmatora for this)

This tends to dirty fix a little bit the issues I’m having (like you) with this integration, but the issue still occurs from time to time (once a week max). At least it sometimes makes it still work when the integration crashes !

Note : if you delete and reinstall the integration, you’ll have to update the integration ID in your shell command, and then restart Hassio.

Just checking… You meant Apple TV, right?

Nope, Android TV.
The idea is to know if your smart TV (Android TV in my case) is turned on or not in order to reload the Apple TV integration.

Hope you’ll get it working.

Thanks for your help @Ripper2909. I have never used a shell command before, but I think I have it working. This is the sequence of events I see in Logbook after I execute the shell command:

image

Now I just need to figure out how to trigger it. I don’t have Android TVs. I wonder if I can trigger based on the Apple TV state being unavailable for x minutes?

@Ripper2909 If you are interested - I have this working perfectly now. As mentioned, I don’t have Android TV. But I have Harmony remotes on each TV. So I created a trigger for each remote: When a Harmony remote turns on, reload the corresponding Apple TV integration. I don’t know if the true “fix” is ever coming, as the Issue I submitted doesn’t seem to have any traction. But I am happy with this solution for now!

1 Like

I hope that I can fix this somehow in the near future (hopefully at least make it better). Currently working on some new stuff for pyatv that might be exciting to some people (got a bit bored about bugs, needed something fun for a change :stuck_out_tongue:). I think first version will ship within the next few days.

3 Likes

Can’t wait to see what you’re planning ! :smiley:

1 Like

Just pushed something:

3 Likes

Hello. I am experiencing the same issues. A restart of HA resolves the issue. But was there a permanent fix for this issue?