pyatv: HELP: Is your Apple TV not found? Read this

The problem A lot of people are having issues where their devices are not found. You either see a message like this:

ERROR: Could not find any Apple TV on current network

Or just empty results from atvremote scan. The issue can also come and go, so it works from time to time but very unreliably.

I do not know why this happens. I see it sometimes myself, but very seldom, so it’s hard to debug. So I am asking for help to solve this once and for all. If you have problems and want to help, continue reading.

Background Apple heavily uses Zero-configuration networking to publish and discover services on a network (they call it Bonjour). This simplifies user experience a lot, since no fiddling with IP-addresses or other network settings are required. Devices, like printers and media players, just “pop-up” when they are available.

The Apple TV works in the same way and pyatv tries to discover four distinct services:

  • _touch-able._tcp.local. - Legacy protocol (DMAP) used by Apple TV 3 and earlier. Was supported until tvOS 13 was released as well. Requires additional pairing when used.
  • _appletv-v2._tcp.local. - More or less the same as _touch-able._tcp.local. but is based on “Home Sharing”. If home sharing is enabled, the Apple TV can be controlled without pairing (simply put).
  • _mediaremotetv._tcp.local. - This is the new “Media Remote Protocol” used by tvOS. Used by Apple TV 4 and later.
  • _airplay._tcp.local. - AirPlay service used for instance when playing a video via AirPlay or performing screen mirroring. pyatv only use this for playing videos based on a URL.

Depending on which services pyatv finds, it will try to figure out the best protocol to use. If for instance both _touch-able._tcp.local. and _appletv-v2._tcp.local. are found, it will use the latter as no additional action is required by the user (i.e. no pairing).

If no service is found for some reason, then pyatv of course will conclude that no device exists. This is what happens for lots of users, including myself. pyatv uses a python library for zeroconf for service discovery and I suspect a bug in that library. By looking at open issues, other people report similar behavior as well.

What can I do? Troubleshooting this is tricky, especially since it’s not easily reproducible at all times. One thing I would like to conclude is if python-zeroconf is the culprit. We can do this with some confidence by scanning for Apple TVs with pyatv and also other tools on the same machine and network. If pyatv doesn’t find a device but avahi does, then we should suspect python-zeroconf.

So what you can do is:

  1. Scan for devices with atvremote: atvremote scan
  2. If the list is not empty, start over with 1) again a few times. If the device continues to be found, try again later to allow for caches to be flushed, etc.
  3. When no device is found, try scanning with other tools. On Linux you can use avahi-browse like this:
$ avahi-browse -d local _mediaremotetv._tcp
+    br0 IPv6 Vardagsrum                                    _mediaremotetv._tcp  local
+    br0 IPv4 Vardagsrum                                    _mediaremotetv._tcp  local

or on macOS, you can do this:

$ dns-sd -B _mediaremotetv._tcp
Browsing for _mediaremotetv._tcp
DATE: ---Mon 14 Oct 2019---
10:50:35.015  ...STARTING...
Timestamp     A/R    Flags  if Domain               Service Type         Instance Name
10:50:35.016  Add        2   4 local.               _mediaremotetv._tcp. Vardagsrum

For Windows I don’t know. There probably are tools, but you will have to look that up yourself. 4. At this stage, if atvremote scan and the other tool you used did not find any device (and you have an Apple TV on your network), then there probably is a legitimate problem. You can report this, it’s useful information. 5. If pyatv did not find a device, but the other tool did, then we can start suspecting python-zeroconf. It would be good if you re-run the commands a few times to get some more entropy.

You can report any combinations you have tried. If you have more than one Apple TV and only one is found, that can be useful as well.

Note: The commands above only looks for MRP, so if you have an ATV3 or earlier and want to help out, change _mediaremotetv._tcp to _touch-able._tcp instead.

What can I do more? Provide additional logging from python-zeroconf during scanning. A simple script like this will scan for devices with debug logging enabled (it is not sufficient to use --debug with atvremote as that doesn’t enable debug logging for python-zeroconf):

import logging
import asyncio
import pyatv
import zeroconf

LOOP = asyncio.get_event_loop()


async def scan(loop):
    print(await pyatv.scan_for_apple_tvs(loop, timeout=5))


if __name__ == '__main__':
    logging.basicConfig(level=logging.DEBUG)
    LOOP.run_until_complete(scan(LOOP))

Please do note that the debug printout may contain some sensitive information. No passwords or such should be there, but things like unique identifiers and MAC-addresses might be present. Either you mask sensitive data out (which might be hard) or you just email me the dump (pierre.staahl AT gmail.com). But remember, it is up to you if you want to share the log. I will only use it for debugging.

Great, so anything else? There is another (asyncio) zeroconf library for python that might be interesting to try out. It’s called aiozeroconf and is available here:

https://github.com/frawau/aiozeroconf

You could try installing that and scanning for services as well, maybe it works better? It’s still based on the same code base as python-zeroconf, so no guarantees.

Instructions:

aiozeroconf -s _mediaremotetv._tcp.local.

Browsing services, press Ctrl-C to exit...

Service Vardagsrum._mediaremotetv._tcp.local. of type _mediaremotetv._tcp.local. state changed: ServiceStateChange.Added
  IPv4 Address: XXX
  IPv6 Address: YYY
  Weight: 0, priority: 0
  Server: Vardagsrum-2.local.
  Properties are:
    ModelName: Apple TV
    AllowPairing: YES

Can I do EVEN more? If you are an experienced user, you can do some packet interception and look the broadcasted data. I have taken dumps with tcpdump (and also looked at zeroconf debug data) when no devices were found by pyatv and made the conclusion that no response was received at all (on network layer) when this happened. It basically means that no response was received by python-zeroconf, so it wasn’t just ignored for some unknown reason. It would be interesting to tap in on network traffic from another computer (with wireshark or so) and see if the expected data it received there or not. It would also be interesting to compare what python-zeroconf does, network-wise, and compare to other tools (like avahi and dns-sd, mentioned earlier). Maybe something is not configured correctly?

I leave this as an open bullet for experienced used to fiddle with.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 63 (34 by maintainers)

Most upvoted comments

@postlund can you please help me from going even more insane… Been working on this for over a week now. And for the life of me I can’t add my ATV…Running Raspbian lite. Ive tried to find my tv the old method… “apple_tv:” and I get nothing. Then I have tried the “Mrp” method and get nothing. So I thought I would get smart and use a port scanner. Found the port, and added the Name, IP and port under apple_tv_mrp… looks like this.

apple_tv_mrp:

- name: Living Room Apple TV

host: 192.168.1.9

port: 49152

This was the most exciting thing ever… I clicked scan and actually got the Apple TV to show up!

I confirmed the IP, and port. And then on to the next step… Authenticate. this is where I have been stuck now all day. I send the request to authenticate and I get nothing… I have tried rebooting Hass, the whole pi, whole home network, turning off home sharing, rebooting ATV, pulling the power on ATV and then turning back on home sharing, barking like a dog, cussing at it all with no luck. Help?

Support in Home Assistant is broken because only MRP is supported by tvOS 13, so pyatv is not compatible at the moment. So you can stop trying, you will not get it working 😄 I am working on fixing this but it’s gonna take some time as it is non-trivial.

For me the patched version works better:

$ pip install git+https://github.com/postlund/pyatv.git@aiozeroconf
$ atvremote scan
Scan Results
========================================
       Name: Balcony
    Address: 192.168.1.155
Identifiers:
 - 34:7E:5C:F2:85:18
Services:
 - Protocol: AirPlay, Port: 7000

       Name: Apple TV
    Address: 192.168.1.101
Identifiers:
 - D2A803C3-1555-406F-8E24-6FAA75D5D52E
 - AC:BC:32:6A:B7:E5
Services:
 - Protocol: MRP, Port: 49152, Credentials: None
 - Protocol: AirPlay, Port: 7000
$

“Balcony” is a Sonos speaker (well, IKEA Symfonisk, to be precise). But my Apple TV is now discovered, which is nice!

It is not discovered with the mainline version of atvremote.

I think I found the problem. I also couldn’t get Apple Remote app to work. Unpaired my phone from AppleTV and couldn’t add it back. It was acting exactly as atvremote. Using Remote App I could see Apple TV, but as soon as I was trying to pair ATV was disappearing from list. My living room Apple TV is hard wired, so I disconnected it from ethernet and connected to wifi network. After I was able to pair with my phone and atvremote. I switched back to ethernet and everything works as it should, so far. Have to say that this ATV was hardwired from day 1 (2 years now) and nothing has changed in my networking. I faced this issue when ATV was updated to TV OS. So I don’t know is it me or Apple. I’ll report back in 24 hours. PS. ubuntu server where I have atvremote installed also hardwired.

I just updated AppleTV to 13.2, obviously it restarted and so far everything works fine. I’ll report back tomorrow. Thank you.

Latest tvOS, ended up down this road scanning, trying to add to Home Assistant. Single Apple TV

My results:

MacOS

dns-sd -B _mediaremotetv._tcp Browsing for _mediaremotetv._tcp DATE: —Fri 25 Oct 2019— 21:45:15.354 …STARTING… Timestamp A/R Flags if Domain Service Type Instance Name 21:45:15.355 Add 3 15 local. _mediaremotetv._tcp. Justins Apple TV 21:45:15.355 Add 2 22 local. _mediaremotetv._tcp. Justins Apple TV

Ubuntu

avahi-browse -d local _mediaremotetv._tcp

  • enp0s25 IPv4 Justins Apple TV _mediaremotetv._tcp local
  • enp0s25 IPv6 Justins Apple TV _mediaremotetv._tcp local

Adding my two cents, since I’ve been trying to figure out what was up with this myself (until I ran across this issue):

  • avahi-browse -d local _mediaremotetv._tcp - ran on ubuntu 18.04, found both ATVs (IPv4 and IPv6 addresses)
  • atvremote scan - ran on MacOS (Catalina), didn’t find either of my two AppleTVs on the network
  • pyatv_debug_scan.py script from above - ran on MacOS, didn’t find anything
  • dns-sd -B _mediaremotetv._tcp - ran on MacOS, found both ATVs
  • python3 -m aiozeroconf -s _mediaremotetv._tcp.local. - ran on ubuntu 18.04 - found both ATVs, no problem

Anything I can do to help, I’m happy to jump in to help test. I have 2 ATVs, one an original ATV4 (HD) and an ATV 4k, if it matters. Thanks for looking into this for sure!