Apple TV Integration - tvOS 15 Beta

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.

image

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/__init__.py", line 33, in error_handler
    return await func(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/pyatv/protocols/companion/auth.py", line 80, in finish_pairing
    resp = await self.protocol.exchange_auth(
  File "/usr/local/lib/python3.9/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.9/site-packages/pyatv/protocols/companion/protocol.py", line 168, in _exchange_generic_opack
    self.send_opack(frame_type, data)
  File "/usr/local/lib/python3.9/site-packages/pyatv/protocols/companion/protocol.py", line 190, in send_opack
    self.connection.send(frame_type, opack.pack(data))
  File "/usr/local/lib/python3.9/site-packages/pyatv/protocols/companion/connection.py", 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/config_flow.py", line 424, in async_step_pair_with_pin
    await self.pairing.finish()
  File "/usr/local/lib/python3.9/site-packages/pyatv/protocols/companion/pairing.py", line 64, in finish
    await error_handler(
  File "/usr/local/lib/python3.9/site-packages/pyatv/support/__init__.py", 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.

Hello, thank you for the ongoing development. The last versions took me a huge step forward, especially starting apps! Everything worked quite well for me, but now I am getting this error:
„… Remote is blocked“
Is there any advice to get it working again? Restarting HA and ATV did not work yet.

I’m a bit curious about what is possible via HomeKit, mainly as I haven’t explored that route yet. Exactly what does that switch do and where does it come from?

Where do you see that error?

Edit: Do you see any other errors? Please check the log.

I use scripts to start atv and apps on the atv. The errors are shown on the screen and in the log on manual start of any script for the atv.
After restarting HA again I now get this in the log:
Unable to send commands, not connected to Wohnzimmer Apple TV

… and on interacting with the device controls in lovelace.

Strange, after playing arround a bit in lovelace I got the error at first, but now it works again …

Does this help?


Logger: homeassistant.components.websocket_api.http.connection
Source: custom_components/apple_tv/media_player.py:409 
Integration: Home Assistant WebSocket API (documentation, issues) 
First occurred: 13:37:06 (1 occurrences) 
Last logged: 13:37:06

[139716114453216] remote_control is blocked
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 185, in handle_call_service
    await hass.services.async_call(
  File "/usr/src/homeassistant/homeassistant/core.py", line 1495, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1530, in _execute_service
    await handler.job.target(service_call)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 209, in handle_service
    await self.hass.helpers.service.entity_service_call(
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 663, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 896, in async_request_call
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 700, in _handle_entity_call
    await result
  File "/config/custom_components/apple_tv/media_player.py", line 409, in async_media_play
    await self.atv.remote_control.play()
  File "/usr/local/lib/python3.9/site-packages/pyatv/support/shield.py", line 71, in _guard_method
    raise BlockedStateError(f"{func.__name__} is blocked")
pyatv.exceptions.BlockedStateError: remote_control is blocked

I see similar logs like:
Apps blocked
audio blocked
Features blocked

And also this:


Logger: homeassistant.util.logging
Source: util/logging.py:105 
First occurred: 13:37:03 (1 occurrences) 
Last logged: 13:37:03

Exception in _async_disconnected when dispatching 'apple_tv_disconnected_90:DD:5D:AD:E3:98': () Traceback (most recent call last): File "/config/custom_components/apple_tv/__init__.py", line 113, in _async_disconnected self.async_device_disconnected() File "/config/custom_components/apple_tv/media_player.py", line 165, in async_device_disconnected self.atv.push_updater.stop() File "/usr/local/lib/python3.9/site-packages/pyatv/support/shield.py", line 71, in _guard_method raise BlockedStateError(f"{func.__name__} is blocked") pyatv.exceptions.BlockedStateError: push_updater is blocked

Trying to get the integration up and working, get to the 4 digit pin code and fails - ATV is on a seperate vlan to Homeassistant. Are there certain ports/allowances needed to get this working?

I am using a dummy switch (Home Assistant input boolean) that let’s automations know whether the TV is on.

For example, when I turn the TV on, I would like to dim some of the lights in the living room. And when I turn them off, I’d like for the lights to go back to full brightness.

I also have some other more complex automations that look to see if the TV power is on. As another example, when I normally go to bed and no one is here with me, my automation sets an alarm, starts, playing music and shuts off all of the lights in the house. But when my daughters or girlfriend are here, I don’t want to shut off all of the lights if they are still watching the TV. So my automation looks to see if the TV is on, if it is then I just turn off my bedroom lights. Otherwise, I turn off all of the lights.

I have found the helper switches in Home Assistant to exponentially expand the possibilities for homekit automations in my home. I know my more complex automations annoy my girls though and I can’t get them to use the switch in homekit. They just use the remote. So it is always my goal to try to make automations that don’t rely on them actually having to do anything different than usual.

In this case though, what I am after is just not possible. So I will just keep trying to train them.