Apple TV Integration - tvOS 15 Beta

@postlund I am really happy with the integration!! I’ve seen some nice features are coming up so I can’t wait until the updates are coming in again! For me, it’s one of the best parts of my home automation to automatically control audio, lights and more when watching something! Auto-pause when my doorell rings is another great use!

Is it correct that at the moment there is no way to turn on/off the AppleTV from HA with just a button (like the new physical remote)? Is this something that looks achievable or are there limitations to this?

Also: I have installed the integration from HACS before the december release. What is the best way to remove that and use the built in version from now on? (haven’t upgraded to the new beta). I like new features, but rather wait a little longer for the finished release :wink:

I got my Gen 2 to connect but it doesnt display anything in the media device and it doesnt control anything. Have you functionality on Airport Express?

Nope, that’s where I got stuck too and then I removed it from HA. I would airplay a song to it and nothing happened in HA. But honestly, that’s all an Airport Express can do. It’s not a Homepod and therefore doesn’t have media controls or even a volume.

Could anybody show me a couple examples of streaming a local file and TTS example scripts?

I can’t seem to figure it out.

I got it, im not sure why i wasn’t seeng it lol

Thanks for these automations. I was able to recreate them using the GUI. I have not quite mastered the art of writing yaml. I was able to recreate your autmoations with exception of turning Input Booleans on and off instead of switches. However, it still doesn’t work for me. I think because I don’t have the states defined. Where is that done? I just typed in “standby” and “unavailable” in the “to” and “from” fields, but I don’t think those are actually defined anywhere.

I am hoping I can find that and finish this up. Being able to use the remote to control on, off, and the entire Apple TV; while still using my virtual switch to control my home and other automations would make it much easier for me to tell my girlfriend and daughters what to do.

Thanks again @Patrick1610 for the help with the automation. I also didn’t say it before, but thank you @postlund for the incredible integration that allows me to use my Apple TV to control other Homekit automations. Much appreciated sir.

1 Like

I have not defined anything myself, just using what the integration provides.
Maybe this is easier. The first two screenshots are both triggers in one automation (On), the third is a seperate automation (Off).

For the ‘On’ automation there also is a condition. This makes sure it doesn’t on when going from Standby to Unavailable or vice versa (which is a risk when using the ‘From’ as trigger).

I just occurred to me @postlund why duplicate entries show up in integrations, it is so simple as to boggle the mind for why I didn’t notice it before: Integrations is still auto-discovering devices based on the old Apple TV code and then when your tvOS 15 beta is integrated, you get it there too. I know you mentioned on GIT that you kept thinking you fixed the problem and didn’t know why it kept popping up, I bet that is why.

Duplicate discovered devices is a known bug but I’m still not entirely sure why it happens. Although, I was hoping the changes made in core fixed it in the latest version. Are you seeing this problem with 2.2.0?

When you load a custom component with the same name as a built in integration, it will replace the built in integration completely. The underlying problem has something to do with identifiers not being verified correctly.

1 Like

No, not right now. The last update was giving me non-stop errors with the Apple TV integration so I purged everything from the storage file, removed the integration and wiped it all out. I just re-installed today and so far it looks right, although it’s not detecting some of my Apple TV’s, just the speakers and a couple of the TV’s.

In case you are wondering if I’m a good test case, I probably am :slight_smile: . 6 Apple TV’s, 8 HomePods (mini and full sized), five Mac’s (since you also now detect Apple Music on a Mac). Don’t even get me started on the various other Apple crap I have. I’m an Apple junkie :joy:.

As I mentioned above, most of my Apple TV’s (mix of v14 and v15) don’t show up on auto detection. I updated a v14 to v15 to see if that made a difference and it did not. I get the following confusing message when I manually add by IP address. Interestingly, I put in the IP and it properly detects the name of the Apple TV, prompts for three sets of PIN’s and all looks good but then this message and there’s no configured AppleTV device in my integrations.


So finally I decided to make step forward and upgrade. I up[dated Apple TV 4k to 15.2 (I was previously on 14.x), I’ve seen in HACS that version 2.2 of Apple TV beta is vailable, so I upgrade too. Old device removed, HA restarted and now I’m stuck at pairing. None of codes displayed on Apple TV is working while entering to integration configuration screen. Log shows pairing error:

2021-12-18 09:38:17 ERROR (MainThread) [custom_components.apple_tv.config_flow] Authentication problem
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/pyatv/support/", line 33, in error_handler
    return await func(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/pyatv/protocols/companion/", line 80, in finish_pairing
    resp = await self.protocol.exchange_auth(
  File "/usr/local/lib/python3.9/site-packages/pyatv/protocols/companion/", line 145, in exchange_auth
    return await self._exchange_generic_opack(frame_type, data, identifier, timeout)
  File "/usr/local/lib/python3.9/site-packages/pyatv/protocols/companion/", line 168, in _exchange_generic_opack
    self.send_opack(frame_type, data)
  File "/usr/local/lib/python3.9/site-packages/pyatv/protocols/companion/", line 190, in send_opack
    self.connection.send(frame_type, opack.pack(data))
  File "/usr/local/lib/python3.9/site-packages/pyatv/protocols/companion/", line 96, in send
    raise exceptions.InvalidStateError("not connected")
pyatv.exceptions.InvalidStateError: not connected

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

Traceback (most recent call last):
  File "/config/custom_components/apple_tv/", line 424, in async_step_pair_with_pin
    await self.pairing.finish()
  File "/usr/local/lib/python3.9/site-packages/pyatv/protocols/companion/", line 64, in finish
    await error_handler(
  File "/usr/local/lib/python3.9/site-packages/pyatv/support/", line 41, in error_handler
    raise fallback(str(ex)) from ex
pyatv.exceptions.PairingError: not connected

How to get this fixed? As I see lots of people integrated ATV succesfully, seems I’m doing something wrong…

That’s a strange error, not sure what has happened there. Please open an issue in the pyatv repo and we’ll start the investigation from there.

Done: Unable to configure Apple TV - does not accept PIN · Issue #1548 · postlund/pyatv · GitHub

Sorry if this documented somewhere, but I can’t figure it out. Is it possible to start Apple Music playing something on the HomePod?

Thanks @Patrick1610. I have set mine up just like that. See attached. Unfortunately, the automations aren’t working for me. The curious thing is if I look at the media_player history, I don’t see standby or unavailable. I see play, paused, and idle.

That’s strange. In my case, idle is on but not playing, standby is when I put the AppleTV to sleep. When I turn it on it goes back to idle until I play something.

I have two OG homepods connected to my Apple TV that are dedicated speakers. I do not have the homepods added to Home Assistant. But I noticed last night that when I turned my Apple TV off, the media player in Home Assistant showed the last music that had been playing on the homepod long ago as paused. I suspect that is why I am not seeing standby. I don’t know if my use case will work with your method.

Yes, if you have HomePods connected to your Apple TV it will not go to standby but stay idle or something similar.

There is currently no support for that. It has been requested but I have no idea how to implement it.

Gotcha. I guess, I will have to continue using the homekit switch to turn on the TV. Not willing to give up the homepods. Thanks for the work on this integration.