Apple TV Integration - tvOS 15 Beta

Did the non-beta get updated with the latest HA release today? Mine still isn’t working. I only updated my atv last week and avoided the beta because I assumed HA update would have the fix.

Hi @postlund. Hoping to either post a new bug, or any insights into what I’m doing wrong.

My HA environment:

  • HASSIO 2021.10.7
  • Apple TV Beta v1.6.0
  • Debug logging enabled for pyatv and custom_components.apple_tv

My Apple TV:

  • tvOS 15.1.1

When I attempt to add the Apple TV integration (Configuration → Add Integration – Apple TV) I see two different behaviors:

Behavior 1:
After clicking “Add Integration”, the pop-up screen will stall on “Please wait while the integration is being set up”. What shows in logs at this point:

2021-11-02 21:22:21 ERROR (MainThread) [homeassistant.config_entries] Error occurred loading configuration flow for integration apple_tv: cannot import name 'ATTR_CONNECTIONS' from 'homeassistant.const' (/usr/src/homeassistant/homeassistant/const.py)
2021-11-02 21:22:21 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 709, in async_create_flow
    integration.get_platform("config_flow")
  File "/usr/src/homeassistant/homeassistant/loader.py", line 532, in get_platform
    cache[full_name] = self._import_platform(platform_name)
  File "/usr/src/homeassistant/homeassistant/loader.py", line 537, in _import_platform
    return importlib.import_module(f"{self.pkg_path}.{platform_name}")
  File "/usr/local/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 972, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 850, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/config/custom_components/apple_tv/__init__.py", line 12, in <module>
    from homeassistant.const import (
ImportError: cannot import name 'ATTR_CONNECTIONS' from 'homeassistant.const' (/usr/src/homeassistant/homeassistant/const.py)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 151, in async_init
    flow, result = await task
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 169, in _async_init
    flow = await self.async_create_flow(handler, context=context, data=data)
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 716, in async_create_flow
    raise data_entry_flow.UnknownHandler
homeassistant.data_entry_flow.UnknownHandler

Behavior 2:
After clicking “Add Integration” → Search for and click “Apple TV”, pop up screen shows “Config flow could not be loaded”. From the logs, one error which also was part of the first behavior:

2021-11-02 21:26:19 ERROR (MainThread) [homeassistant.config_entries] Error occurred loading configuration flow for integration apple_tv: cannot import name 'ATTR_CONNECTIONS' from 'homeassistant.const' (/usr/src/homeassistant/homeassistant/const.py)

Appreciate any thoughts on what might be happening. Thanks.

It’s the same root cause and issue has been reported before (see cannot import name 'ATTR_CONNECTIONS' from 'homeassistant.const' · Issue #1431 · postlund/pyatv · GitHub for details). Will be resolved once Home Assistant 2021.11.0 is released today.

1 Like

The integration has retained a connection to my Apple TV 4K second generation, but the connection to the first generation Apple TV gets dropped until HA is restarted. Both Apple TVs have reserved IP addresses. Let me know if I can provide anything to help troubleshoot.

@postlund

Hi just updated to latest Apple TV Beta and also to latest Home Assistant.

When trying to pair my apple tv 3 i get stuck at this:

Pairing is required for the DMAP service. Please enter PIN XXXX on your device to continue.

No screen is showing up on my apple tv and if i just press continue i get “Avbruten”

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 197, in async_init
    flow, result = await task
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 224, in _async_init
    result = await self._async_handle_step(flow, flow.init_step, data, init_done)
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 320, in _async_handle_step
    result: FlowResult = await getattr(flow, method)(user_input)
  File "/config/custom_components/apple_tv/config_flow.py", line 165, in async_step_zeroconf
    return await self.async_find_device_wrapper(self.async_found_zeroconf_device)
  File "/config/custom_components/apple_tv/config_flow.py", line 225, in async_find_device_wrapper
    return await next_func()
  File "/config/custom_components/apple_tv/config_flow.py", line 203, in async_found_zeroconf_device
    await self.async_set_unique_id(self.device_identifier)
  File "/config/custom_components/apple_tv/config_flow.py", line 105, in device_identifier
    if identifier in entry.data[CONF_IDENTIFIERS]:
KeyError: 'identifiers'
2021-11-03 19:46:49 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 197, in async_init
    flow, result = await task
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 224, in _async_init
    result = await self._async_handle_step(flow, flow.init_step, data, init_done)
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 320, in _async_handle_step
    result: FlowResult = await getattr(flow, method)(user_input)
  File "/config/custom_components/apple_tv/config_flow.py", line 165, in async_step_zeroconf
    return await self.async_find_device_wrapper(self.async_found_zeroconf_device)
  File "/config/custom_components/apple_tv/config_flow.py", line 225, in async_find_device_wrapper
    return await next_func()
  File "/config/custom_components/apple_tv/config_flow.py", line 203, in async_found_zeroconf_device
    await self.async_set_unique_id(self.device_identifier)
  File "/config/custom_components/apple_tv/config_flow.py", line 105, in device_identifier
    if identifier in entry.data[CONF_IDENTIFIERS]:
KeyError: 'identifiers'

Just noticed that my Apple TV 4 aborts right away after putting in the IP and click next after get prompter that I will need to fill in codes

Br Mathias

For the DMAP protocol leave it at that step in adding the integration, then you have to go on the AppleTV under settings > remotes (I don’t remember exactly the name) and find the entry called Home Assistant under the pair remotes section. That’s where you enter the code.

I just pushed version 1.9.0, please install that and try again. Follow what @squirtbrnr wrote regarding ATV 3.

I love this screenshot man! I can’t wait for this AppleTV integration to come out of testing so I can create something similar!

@postlund heres an interesting one… one of my Ecobee SmartThermostat with Voice Control (which is basically a Ecobee 4 plus voice control) shows up as an AppleTV. That’s the name I gave to the thermostat and the “EB-“ makes sense if it’s an Ecobee. Looking on their website they do list Siri compatibility for this model thermostat which must be new because it didn’t have it when they released it a few years ago. However, only one of my two thermostats shows up and no amount of restarting HA will make the other one show up. Maybe I need to restart the thermostat. Second thermostat just needs a firmware update that’s being slowly pushed out by Ecobee.

Anyway, thought it was interesting your beta integration picked this up.

EDIT: I’m about a month too slow… New Software update from Ecobee enables Siri on the Smart Thermostat with Voice Control https://www.ecobee.com/en-us/newsroom/press-releases/ecobee-smartthermostat-with-voice-control-is-now-enabled-with-siri/

Thanks. Excited to have an Apple TV integration that enables this.

Any plans to add a source_list like the Sonos and Roku integrations? Does Apple expose this?

hello, i see this message in my log, but everything seems to be working fine.

Logger: homeassistant
Source: custom_components/apple_tv/config_flow.py:153 
Integration: Apple TV 
First occurred: 14:04:46 (3 occurrences) 
Last logged: 14:54:02

Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/discovery_flow.py", line 74, in _async_process_pending_flows
    await gather_with_concurrency(
  File "/usr/src/homeassistant/homeassistant/util/async_.py", line 170, in gather_with_concurrency
    return await gather(
  File "/usr/src/homeassistant/homeassistant/util/async_.py", line 168, in sem_task
    return await task
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 197, in async_init
    flow, result = await task
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 224, in _async_init
    result = await self._async_handle_step(flow, flow.init_step, data, init_done)
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 320, in _async_handle_step
    result: FlowResult = await getattr(flow, method)(user_input)
  File "/config/custom_components/apple_tv/config_flow.py", line 153, in async_step_zeroconf
    service_type = discovery_info[zeroconf.ATTR_TYPE][:-1]  # Remove leading .
AttributeError: module 'homeassistant.components.zeroconf' has no attribute 'ATTR_TYPE'

Does this mean that in HA 2021.11.0, AppleTV with tvOS 15 will work again?

Indeed.

Running TVOS 15.1 beta:

Hi! after setting Airplay to allow everyone if was finally able to add both appletvs and they are now working again. Thank you!!

1 Like

I had no issues adding my 2 ATVs (4K), but now I try to use them in scenes.
I made one script to put them to sleep and one to wake them up.
Calling these scripts directly in HA works quite reliable.
But using these scripts in a scene does not.
Waking up does not work or sometimes only on the second try.


wz_atv_wakeup:
  alias: "WZ ATV Wakeup"
  sequence:
    - service: remote.send_command
      target:
        entity_id: remote.wohnzimmer_apple_tv
      data:
        delay_secs: 1
        command:
          - top_menu
    - service: media_player.turn_on
      target:
          entity_id: media_player.wohnzimmer_apple_tv
            
wz_atv_standby:
  alias: "WZ ATV Standby"
  sequence:
    - service: remote.send_command
      target:
        entity_id: remote.wohnzimmer_apple_tv
      data:
        delay_secs: 1
        command:
          - home_hold
          - select
    - service: media_player.turn_off
      target:
          entity_id: media_player.wohnzimmer_apple_tv

Has anyone experience in getting this to work more reliable?

Have you tried sending the wakeup command?

alias: Turn on Apple TV
sequence:
  - service: remote.send_command
    data:
      command: wakeup
    target:
      entity_id:
        - remote.living_room_apple_tv

After updating the Apple TV integration today to 1.9.0 and the result was not so good:

Logger: homeassistant.config_entries
Source: config_entries.py:511
First occurred: 2:58:26 PM (1 occurrences)
Last logged: 2:58:26 PM

Migration handler not found for entry Apple TV for apple_tv

Apple TV is now unavailable.
Then, after deleting the integration and reloading again, it autodiscovers my ATV3 and upon connection, when I type the 4-digit code that appears on the Apple TV screen, this is what I get:

image

Any help is much appreciated.

reboot HA and reboot the AppleTV. I had the same issue and if the integration aborts during setup, you have to reboot to get it to re-discover and also complete setup. Also make sure you don’t have any other devices/entities for that AppleTV already registered. You might have to reboot HA twice in that case and delete any leftover entities in between.

Thank you for stepping in.
I did reboot HA several times and finally got one step further.
It now accepts the on screen PIN code, and in the next step instructs me to type a PIN code back into the Apple TV device.
image
But there is no dialog box on the Apple TV screen requesting a pin code! And if I just click SUBMIT I get this:
image

So, still stuck.