postlund / pyatv

A client library for Apple TV and AirPlay devices
https://pyatv.dev
MIT License
891 stars 100 forks source link

Using Apple TV Remote from Home Assistant running in Docker #890

Closed shiftux closed 3 years ago

shiftux commented 3 years ago

Not sure if I should post this here or on a HA forum... Hope this is OK.

I'm trying to control my apple TV 4K from Home Assistant running in a Docker container.

From my laptop I can run a scan and find the Apple TV

Scan Results
========================================
       Name: Living Room
   Model/SW: 4K tvOS 14.2 build 18K57
    Address: 192.168.XXX.XXX
        MAC: XX:XX:XX:XX:XX:XX
 Deep Sleep: False
Identifiers:
 - XX:XX:XX:XX:XX:XX
 - YYYYYYY-YYYY-YYYY-YYYY-YYYYYYYYYYY
Services:
 - Protocol: AirPlay, Port: 7000, Credentials: None
 - Protocol: MRP, Port: 49153, Credentials: None

Using this I was able to set up the Apple TV on HA and also to pair it and get "credentials". However after setting those and restarting HA I get an error in my logs A <class 'aiohttp.client_exceptions.ClientConnectorError'> error occurred: Cannot connect to host 192.168.XXX.XXX:3689 ssl:None [Connect call failed ('192.168.XXX.XXX, 3689)]. And the state of the media player in HA is stuck in "Establishing a connection to apple_tv". Also I don't see a remote on the ATV (in the "remote app and devices" setting).

Investigating this further I went into the HA container and tried using atvremote from there. Without any additional arguments the discovery fails (this had worked from the laptop)

atvremote --debug scan
DEBUG: Discovering devices for 3 seconds
Found Apple TVs:

Note: You must use 'pair' with devices that have home sharing disabled

using pair, I get:

bash-5.0# atvremote --address 192.168.XXX.XXX --debug --login_id YYYYYYY-YYYY-YYYY-YYYY-YYYYYYYYYYY -p none pair
Use any pin to pair with "pyatv" (press ENTER to stop)
Using pairing guid: 0xD0F271E6E051C691
Note: If remote does not show up, try rebooting your Apple TV
DEBUG: Started pairing web server at port 38141
DEBUG: Published zeroconf service: ServiceInfo(type='_touch-remote._tcp.local.', name='0000000000000000000000000000002886860805._touch-remote._tcp.local.', addresses=[b'\xac\x12\x00\x05'], port=38141, weight=0, priority=0, server='0000000000000000000000000000002886860805._touch-remote._tcp.local.', properties={b'DvNm': 'pyatv', b'RemV': b'10000', b'DvTy': b'iPod', b'RemN': b'Remote', b'txtvers': b'1', b'Pair': 'D0F271E6E051C691'})

DEBUG: Shutting down pairing server
No response from Apple TV!

All the while observing the "remotes and devices" - "remote app and devices" page on the ATV, I'm not getting a remote showing up (and rebooting the ATV does not help).

The line No response from Apple TV! makes me think that this is related to a port on the Docker container not being exposed. However I can't specify a port for atvremote and have noticed that the allocated port changes every time I run a pair...

HA version 0.110.4 OpenSSL 1.1.1g 21 Apr 2020

shiftux commented 3 years ago

Took an entirely different approach and installed HACS and then installed the hass-atv-beta version. This works, sorry for the confusion...

postlund commented 3 years ago

What's in the hass-atv-beta repo will be included in Home Assistant 1.0 once released. Some minor differences so far, but almost the same. So HACS will soon not be needed for this, although I will likely continue to update it with new features for eager testers.

shiftux commented 3 years ago

thanks for all your work!! 👏