home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
70.46k stars 29.4k forks source link

Apple TV 4th gen not getting connected #95413

Closed chini007 closed 4 months ago

chini007 commented 1 year ago

The problem

I am trying to add my apple TV. And when I provide the IP address of the apple TV, it complains Device not found.

What version of Home Assistant Core has the issue?

core-2023.6.3

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant Container

Integration causing the issue

apple_tv

Link to integration documentation on our website

No response

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

home-assistant[bot] commented 1 year ago

Hey there @postlund, mind taking a look at this issue as it has been labeled with an integration (apple_tv) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `apple_tv` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign apple_tv` Removes the current integration label and assignees on the issue, add the integration domain after the command.

(message by CodeOwnersMention)


apple_tv documentation apple_tv source (message by IssueLinks)

joostlek commented 1 year ago

Are you able to connect to other local devices? Since you're running home assistant in a container, the network setup can be different

chini007 commented 1 year ago

Oh yes I can connect other devices. I have already connected my smart home server (digitalStrom) via mqtt, my bose system, samsung tv, bosch controller etc.

postlund commented 1 year ago

Are they on different networks, e.g. VLANs?

chini007 commented 1 year ago

No they are all on same LAN. HA and other Integrations can see other devices using IP.

postlund commented 1 year ago

The important thing is that the IP packets reaching the Apple TV has an address belonging to the same network as the Apple TV, otherwise they will be dropped (MDNS/zeroconf works that way). Just IP connectivity is not enough. Since unicast look ups doesn't work (when you manually specify IP), I suspect this is not the case.

gbdavidx commented 1 year ago

i have a similar issue, im running home-assistant OS in truenas vm, i can't add via ip address, i was able to connect to my synology nas just fine for the record

postlund commented 1 year ago

How is the network configured in the VM?

gbdavidx commented 1 year ago

Simple..., att modem/wifi, http://192.168.1.106:8123/ home assistant, 192.168.1.74 (appletv), i can ping appletv from truenas scale

gbdavidx commented 1 year ago

I fixed my issue! I didnt have enable truest filters enabled.... Not sure why that did it!

postlund commented 1 year ago

It might have been that it dropped MDNS packets because of that. Something related to firewall or network rules would have been my best guess here.

chini007 commented 1 year ago

The important thing is that the IP packets reaching the Apple TV has an address belonging to the same network as the Apple TV, otherwise they will be dropped (MDNS/zeroconf works that way). Just IP connectivity is not enough. Since unicast look ups doesn't work (when you manually specify IP), I suspect this is not the case.

Am lost here, how could I check if the packets are coming from same network as Apple TV or not. And if not how could still add apple TV.

rwjack commented 1 year ago

@postlund Yeah I'm having the same issue here. Running HassOS, added a new adapter for the network in which the AppleTV resides. I can ping the AppleTV from HA, but when adding the device I just get the following:

image

pfsense is doing the routing, but nothing should be blocked on the VLAN level, meaning the HassOS adapter has full permissions to the apple TV.

Update: Suddenly I see AppleTV, HomeKit and Thread as Discovered Devices, though I only went through the initialization process for the AppleTV integration (entering the pin codes 3 times), though the adoption process still fails with only a warning in the logs:

Config entry 'Living Room' for apple_tv integration not ready yet: Not found at x.x.x.x (redacted), waiting for discovery; Retrying in background
postlund commented 1 year ago

@rwjack I know @bdraco has made improvements that hopefully improves this. The important thing is the the source IP address in Home Assistant matches the network in which the Apple TV resides, otherwise you must use an MDNS relayer (being reachable, e.g. ICMP, is not enough for this to work, the Apple TV will just do the packets).

rwjack commented 1 year ago

Yep, exactly why I added a new adapter in HassOS to match the Network AppleTV resides in, but not even this seems to have resolved the issue.

bdraco commented 1 year ago

New changes aren't in a published release yet. Should be next week or sooner depending on when some other issues get tied up

rwjack commented 1 year ago

Another update, it started working the next day, but failed again today with the same warning as before:

image

Something really wonky is going on. 🥴

bdraco commented 1 year ago

2023.8.2 was published with some more changes to work around flakey multicast

If thats the underlying problem, it should help.

If its not, you'll probably need to provide debug logs for pyatv

kneip68 commented 11 months ago

I can confirm the issue, sometimes it works perfectly to connect to ATV, sometimes it does not. I am running HA OS 2023.8.4 as a VM on Proxmox, only VirtIO Network Adapter is on the same subnet as ATV, a Homepod mini in the same room connected to the same router wirelessly works flawless. I can see the UDP packages of both Apple devices with wireshark on the NIC.

Now, when taking a look at the logs of pyatv (activated debug logs) I recognized that the integration tried to connect to the IP x.x.x.194 which was a dynamic non-actual registration on the FritzBox being my main router in that network with the same name of "MensCave" as the MDNS registration of the ATV. Since I deleted that record, the integration worked perfectly. No idea what the FritzBox does, maybe it's time to replace it by OPNsense ;-)

Anyway, maybe that helps someone, attached the log. home-assistant_apple_tv_2023-09-04T15-00-20.510Z.log

bfreire commented 9 months ago

With debugging enabled, I had this log the only time the integration recognized my Apple TV. HA never recognized the Apple TV again.

Logger: homeassistant.components.apple_tv.config_flow
Source: components/apple_tv/config_flow.py:421
Integration: Apple TV (documentation, issues)
First occurred: 16:23:39 (1 occurrences)
Last logged: 16:23:39

Unexpected exception
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/apple_tv/config_flow.py", line 421, in async_pair_next_protocol
    await self.pairing.begin()
  File "/usr/local/lib/python3.11/site-packages/pyatv/protocols/airplay/pairing.py", line 60, in begin
    self.http = await http_connect(self.address, self.service.port)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pyatv/support/http.py", line 653, in http_connect
    _, connection = await loop.create_connection(HttpConnection, address, port)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/asyncio/base_events.py", line 1085, in create_connection
    raise exceptions[0]
  File "/usr/local/lib/python3.11/asyncio/base_events.py", line 1069, in create_connection
    sock = await self._connect_sock(
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/asyncio/base_events.py", line 973, in _connect_sock
    await self.sock_connect(sock, address)
  File "/usr/local/lib/python3.11/asyncio/selector_events.py", line 628, in sock_connect
    return await fut
           ^^^^^^^^^
  File "/usr/local/lib/python3.11/asyncio/selector_events.py", line 668, in _sock_connect_cb
    raise OSError(err, f'Connect call failed {address}')
OSError: [Errno 113] Connect call failed ('192.168.1.80', 7000)
chini007 commented 9 months ago

This is what I see with debug 192.168.178.81: Multicast is broken or device offline, trying unicast PTR queries for ['_device-info._tcp.local.']

tommcmur commented 8 months ago

any new info on this? I am having the same issue with two apple tv's

dennybrah commented 7 months ago

I am also having an issue not able to connect my AppleTV to home assistant. I have in the past, but using proxmox ubuntu VM this time around, I am able to ping the AppleTV within ubuntu server fine, with no issues. But when I try to add the AppleTV ip to the AppleTV integration in HA, it says "No devices found on the network".

Edit:

I GOT IT WORKING

In my docker compose yaml, I originally set the network mode to "bridge"

I updated the network mode to "host" and this fixed it immediately after HA came back up. It also auto-found my appletv along with a bunch of other integrations.

chini007 commented 4 months ago

Yes, updating the pod to host mode "hostNetwork: true" resolves it.