Apple TV Integration - tvOS 15 Beta

You can use a power meter behind the TV, let that control the switch or make conditions based on the power consumption itself. No more manual switching needed for the girls (and you):wink:

The issue is back again :unamused:

The problem is that the device is not connected, it probably fails to re-connect. I look at the other error you sent.

Which protocol is it? The companion protocol doesn’t work when the device is on another VLAN.

Apologies for the ignorance, but how do I determine that sorry?

It’s says what protocol you are pairing when adding a new device.

I removed all my Apple devices and readded them. Now it seem to work fine again. -fine-

I can add my Apple TVs and HomePods, but not the AirPort Express (2nd generation)
My stereo pair of HomePods show up as 2 separate speakers.

Is it somehow possible to group and ungroup Homepods using automations? So not using Siri?
May that get possible for Sonos and HomePods together?

E.g. play the same music as currently in the livingroom also in the bathroom, when the bathroomlights are turned on?

Do you get any error with the airport or isn’t it found? It’s hard for me to help without any context in the matter. It should be discovered, otherwise you can try adding it manually.

Grouping or ungrouping is not supported and probably will not be for a long time. If/when it is added it would likely be for AirPlay 2 receivers, so you can group multiple AirPlay 2 receivers together. That would include Sonos.

Sorry, I was not precise enough. The AirPort Express gets detected, but ever when I try to add it, it requests the pairing, but that does not work:
“Pairing is required for RA0P but is disabled on the device.”

Then you need to go into the Home app and change so that anyone on the same network can connect to your speakers.

Thank you, but I already did that. It does work for the HomePods and Homepod minis, but it does not for the AirPort Express.
Any try leads to „failed to add device“

Is the AirPort added to your home or is it running standalone? Mine is added to my home and switched between “disabled” and “not needed” for pairing when I toggle between “everyone sharing this home” and “everyone on the same network” at least.

Deleting the device and readding fixed the issue. Now all apple devices work fine.

1 Like

I have a suggestion for devices that get turned off: truncate the log message with something like “Device not available on the network” or something. In my case, the Apple TV in my theater is completely turned off when the theater is not in use (why use energy if you aren’t using it). As a result, every time I reboot I get a number of long errors in the log that I assume are connected to the Apple TV not being available but being mapped in the integration:

2021-12-27 16:36:20 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/pyatv/support/knock.py", line 28, in _async_knock
    _, writer = await asyncio.wait_for(
  File "/usr/local/lib/python3.9/asyncio/tasks.py", line 481, in wait_for
    return fut.result()
  File "/usr/local/lib/python3.9/asyncio/streams.py", line 52, in open_connection
    transport, _ = await loop.create_connection(
  File "/usr/local/lib/python3.9/asyncio/base_events.py", line 1056, in create_connection
    raise exceptions[0]
  File "/usr/local/lib/python3.9/asyncio/base_events.py", line 1041, in create_connection
    sock = await self._connect_sock(
  File "/usr/local/lib/python3.9/asyncio/base_events.py", line 955, in _connect_sock
    await self.sock_connect(sock, address)
  File "/usr/local/lib/python3.9/asyncio/selector_events.py", line 502, in sock_connect
    return await fut
  File "/usr/local/lib/python3.9/asyncio/selector_events.py", line 537, in _sock_connect_cb
    raise OSError(err, f'Connect call failed {address}')
OSError: [Errno 113] Connect call failed ('10.1.200.120', 32498)

Which then leads to this a few seconds later:

2021-12-27 16:36:31 ERROR (MainThread) [custom_components.apple_tv] Failed to connect
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/asyncio/locks.py", line 413, in acquire
    await fut
asyncio.exceptions.CancelledError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/asyncio/tasks.py", line 492, in wait_for
    fut.result()
asyncio.exceptions.CancelledError
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
  File "/config/custom_components/apple_tv/__init__.py", line 227, in _connect_loop
    await self._connect(conf)
  File "/config/custom_components/apple_tv/__init__.py", line 304, in _connect
    self.atv = await connect(conf, self.hass.loop, session=session)
  File "/usr/local/lib/python3.9/site-packages/pyatv/__init__.py", line 110, in connect
    await atv.connect()
  File "/usr/local/lib/python3.9/site-packages/pyatv/core/facade.py", line 565, in connect
    if await setup_data.connect():
  File "/usr/local/lib/python3.9/site-packages/pyatv/protocols/airplay/__init__.py", line 278, in _connect_rc
    await mrp_connect()
  File "/usr/local/lib/python3.9/site-packages/pyatv/protocols/mrp/__init__.py", line 927, in _connect
    await protocol.start()
  File "/usr/local/lib/python3.9/site-packages/pyatv/protocols/mrp/protocol.py", line 156, in start
    await self.send_and_receive(messages.client_updates_config())
  File "/usr/local/lib/python3.9/site-packages/pyatv/protocols/mrp/protocol.py", line 255, in send_and_receive
    return await self._receive(identifier, timeout)
  File "/usr/local/lib/python3.9/site-packages/pyatv/protocols/mrp/protocol.py", line 267, in _receive
    await asyncio.wait_for(semaphore.acquire(), timeout)
  File "/usr/local/lib/python3.9/asyncio/tasks.py", line 494, in wait_for
    raise exceptions.TimeoutError() from exc
asyncio.exceptions.TimeoutError

The beta integration didn’t work for me at first. It let me set up, paired 4 codes and was successful but then HA didn’t show any data or let me control the device. No errors either, just couldn’t do anything.

I checked the ATV and it was v14, upgraded to v15 and deleted and readded in HA - everything works perfectly. Thanks for your efforts @postlund !

Hi there, on the beta Is it possible to customize the source_list? or at least make it alphabetical?

I tried searching around but can’t seem to find any clue that it’s possible as an HA function.

thanks

Couple of noob-ish questions:

HomePods:

  • Is there a way to “turn off” a HomePod? I ask because they appear to be paused forever showing the song/cover they were playing sometimes days ago.

AppleTV:

  • In the previous integration, I could send a media_player.turn_off command and it would show the ATV as “off” in the HA GUI. I had automations set up to do this when I turned my TVs off. Also turn_on when I turned them on. This was purely aesthetic as I know it doesn’t actually do anything on the ATV. Is there a way to do this now? This no longer appears to be working.

I don’t think there are. Sorting them alphabetically would be a minor improvement, I’ll try to keep that in mind when I do some other fixes.

1 Like

I have not found any way to turn the HomePods off and I don’t think it’s possible. Would have been a nice feature to just “stop” everything so it would not show anything playing. But I have not found any way to do that either.

Personally I would have preferred to keep the old power management behavior, but a lot of users have requested ways to actually turn the device off (at least in the sense that it mimics turning off the device via the menus so that CEC turns off other devices) so here we are. It should work pretty ok to turn on and off a device, but it’s not always the case that the correct state is shown. If you have a HomePod connected to it, there’s no way for me to deduce a “power state” as turning the device off is not indicated via protocol in any way. It will keep showing as turned on (e.g idle) in this case. Whenever it is sleeping the state will be standby. Maintaining both behaviors would require a lot of error prone and ugly code, so I’m not keen on supporting that (even if I would still like to have the old behavior myself).

Wait… so the turn_off is supposed to now turn off the connected device(s) via HDMI-CEC?? Is it supposed to be the same as home_hold and then select?