Apple TV On HassOS

Fantastic it works. :star_struck:
Many thanks for this amazing integration. It solves a big problem for me : sleep my television through ATV and HDMI CEC.

1 Like

Hello @postlund,

Today HA discovered a new device as an Apple TV.

The point is that I don’t have a second one and I’m not sure what is the new device listed. I don’t remember that name, so It’s not a recently added one.

Do you have some ideas? Have i got to proceed or what?

Do you use forked-daapd or any other iTunes receiver? It might use DMAP and get picked up because of that. You can just ignore it.

Nop, I’m not using anything and I didn’t installed nothing new recently.

Anyway I’ll ignore it as suggested. Thanks!

If you you atvremote scan on a computer on the network, you might be able to get some hints regarding what it actually is for device.

SOLVED : My Airplay was not authorised “for all people on the same network”

Hello, hass-atv-beta should work with iOS 14 ? I can’t pair…
The app is in the remote app on my appletv but it failed when I type the code.

“Authentication error. You might have entered an invalid PIN code or not have permission to pair via this protocol. Please check access settings on your Apple TV.”

“pyatv==0.7.3”
iOS 14.2

Logger: custom_components.apple_tv.config_flow
Source: custom_components/apple_tv/config_flow.py:271
Integration: Apple TV (documentation)
First occurred: 20:50:12 (1 occurrences)
Last logged: 20:50:12

Authentication problem

Traceback (most recent call last): File “/usr/local/lib/python3.8/site-packages/pyatv/support/init.py”, line 29, in error_handler return await func(*args, **kwargs) File “/usr/local/lib/python3.8/site-packages/pyatv/airplay/auth.py”, line 33, in start_authentication raise AuthenticationError(“pair start failed”) pyatv.exceptions.AuthenticationError: pair start failed 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 271, in async_begin_pairing await self.pairing.begin() File “/usr/local/lib/python3.8/site-packages/pyatv/support/init.py”, line 37, in error_handler raise fallback(str(ex)) from ex pyatv.exceptions.PairingError: pair start failed

I didn’t find anything, but look at this log. Do I have to fix something?

Hi,

Great job on making this new integration. I had a lot of this working about a year ago via node-red/HA and found a lot has changed with TVOS and now have to design/build it again. Oh well (I was using Alexa as my trigger device, moving to HomeKit now as HomePod and many other apple devices with Siri).

Just found that the code syntax you had did not work for me in HA (developer -> services), it gave me an error (see screenshot)

I found that this works (noting that just holding home no longer puts the APV to sleep, you have to hit select as well, might be an TVOS 14 thing)

entity_id: remote.appletv
device: 32756745
command: 
  - home_hold
  - select
delay_secs: 0.75

Hi,

I’ve switched from homebridge to HASS and I’m glad to see pyATV on this platform.

Works well on a docker with hass.io but got an error with a chroot with Debian Buster 10.6 + Python 3.8.6 + HASS 0.118.4:

2020-12-01 08:57:00 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.8/site-packages/aiohttp/web_protocol.py", line 422, in _handle_request
    resp = await self._request_handler(request)
  File "/srv/homeassistant/lib/python3.8/site-packages/aiohttp/web_app.py", line 499, in _handle
    resp = await handler(request)
  File "/srv/homeassistant/lib/python3.8/site-packages/aiohttp/web_middlewares.py", line 118, in impl
    return await handler(request)
  File "/srv/homeassistant/lib/python3.8/site-packages/homeassistant/components/http/request_context.py", line 18, in request_context_middleware
    return await handler(request)
  File "/srv/homeassistant/lib/python3.8/site-packages/homeassistant/components/http/ban.py", line 72, in ban_middleware
    return await handler(request)
  File "/srv/homeassistant/lib/python3.8/site-packages/homeassistant/components/http/auth.py", line 127, in auth_middleware
    return await handler(request)
  File "/srv/homeassistant/lib/python3.8/site-packages/homeassistant/components/http/view.py", line 129, in handle
    result = await result
  File "/srv/homeassistant/lib/python3.8/site-packages/homeassistant/components/config/config_entries.py", line 136, in post
    return await super().post(request)
  File "/srv/homeassistant/lib/python3.8/site-packages/homeassistant/components/http/data_validator.py", line 60, in wrapper
    result = await method(view, request, *args, **kwargs)
  File "/srv/homeassistant/lib/python3.8/site-packages/homeassistant/helpers/data_entry_flow.py", line 69, in post
    result = await self._flow_mgr.async_init(
  File "/srv/homeassistant/lib/python3.8/site-packages/homeassistant/data_entry_flow.py", line 130, in async_init
    result = await self._async_handle_step(
  File "/srv/homeassistant/lib/python3.8/site-packages/homeassistant/data_entry_flow.py", line 213, in _async_handle_step
    result: Dict = await getattr(flow, method)(user_input)
  File "/home/homeassistant/.homeassistant/custom_components/apple_tv/config_flow.py", line 137, in async_step_user
    self.scan_result, _ = await device_scan(None, self.hass.loop)
  File "/home/homeassistant/.homeassistant/custom_components/apple_tv/config_flow.py", line 76, in device_scan
    scan_result = await scan(loop, hosts=hosts, timeout=timeout)
  File "/srv/homeassistant/lib/python3.8/site-packages/pyatv/__init__.py", line 49, in scan
    devices = (await scanner.discover(timeout)).values()
  File "/srv/homeassistant/lib/python3.8/site-packages/pyatv/support/scan.py", line 205, in discover
    responses = await mdns.multicast(
  File "/srv/homeassistant/lib/python3.8/site-packages/pyatv/support/mdns.py", line 585, in multicast
    await protocol.add_socket(net.mcast_socket(None, 5353))
  File "/srv/homeassistant/lib/python3.8/site-packages/pyatv/support/net.py", line 67, in mcast_socket
    sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
OSError: [Errno 92] Protocol not available

Needed to patch net.py like this to get it work:

    if hasattr(socket, "SO_REUSEPORT"):
        sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)

Strange.

By the way, Pierre, did you see the new AppleTV remote controller implementation on Hap-nodejs?
I’ve played with Siri commands and patched it to send recorded sentences: magic to launch an App or select TV channel!

Hey @postlund - First of all, thanks a lot for your excellent work in this. Much appreciated.

Not sure if this thread is the best place to ask, but it was one of the top results in Google.

I added my 2x Apple TV 4K to HA after this integration became official in the HA 2012.12 version.
I have noticed that when the Apple TVs are not in use, the media_player state is constantly switching between “idle” and “unknown” (and at the same time the remote state is switching between “on” and “off”). This happens approximately every 20 seconds, so often that it totally floods the state history and my browser actually freezes when I try to view the history of either the media_player or the remote.

So I was wondering if this is normal, or if there is anything I can do to fix this?
I can always work around this by excluding the entities from the recorder, but it would be nice to have the history available.

apple-tv-state-history

That does not sound normal. Please check the log first and foremost, you should hopefully find something there.

Hei Pål, Jeg tar for gitt at du har sett denne tråden:

Did you resolve that issue? I have the same.

Hi

I have been busy so I did not spend any time on it. I just did a workaround where I excluded the appletv entities from the recorder to avoid filling up the database with these messages. However I noticed some memory leak issues as well due to this, so I just disabled the integration as I don’t depend on it currently.

I have a suspicion it might be related to the appletv devices being connected via wifi, so I will test with cable for one of my devices which will be easy to connect, to see if it helps.

Meanwhile i found a workaround - I switched from Ethernet to Wifi - since then it is working as expected.
I suppose that the issue is realted to an Multicast incompatible Powerline Device which causes Multicast flooding.
The same is possible with a wifi repeater which is not multicast (IGMPv3) capable. Which applies for most cheap models.

Thanks for sharing, that’s quite interesting. I was running the appletv devices and the Home Assistant NUC on the same wifi (TP-Link Deco X60 mesh with 3 nodes), so I will check if there is something I can adjust in there. But typically these home usage mesh systems have limited configuration options.

Have a look at “IGMP Proxy and Snooping”

Has any progress been made on the integration that will allow for the select_source yet? I’m trying to integrate my AppleTV (running tvOS 14.x). I can see the status information when something is playing, but I can’t control anything other than the play/pause. I’ve tried creating scripts that use the up/down/left/right command from the remote, but they only work if the AppleTV is on the main screen, with nothing already playing. Being able to select the source using just the app name would be really useful.

That will come quite soon, but use the media browser as that seems to be what others do.

I have updated apple tv to version 15 beta and I can no longer integrate it into the home assistant? do you know how to do it?
the network sometimes sees it, other times it doesn’t and sometimes it asks only for the first pin while the second doesn’t ask for it, Thanks