For a while my hass instance would loose track of the Apple TV if it went into a sleeping state. This was a bit of a problem for me, as I mainly relied on the state of my ATV to turn my (old and power hungry amp) on and off.
This was a known bug and had been fixed
but the problems persisted for me, and it turned out that i had a config
issue (probably as well as being affected by the bug). Saw the
and got clued in to what was going on, the hass integration is relying on
the "Companion Protocol".
I had added it by hostname/ip, and it turns out that it relies heavily on the mdns advertisements from the ATV and its "identifiers" instead. Adding it as the "name" of the ATV (mine is creatively named "Apple TV") and now hass doesnt loose track of it when it goes to sleep and is immediately aware of the state of the ATV as soon as it wakes up.
This reliance on mdns and discovery requires you to run hass on the same network, which is an annoying constraint (though I do run it on the same network).
The hass integration uses
pyatv, which comes
with the (rather neat)
atvproxy tool, which can proxy the companion
(and all the others too). Idea: can we use that as a bridge between
home assistant and ATV?
First, we have to find the Apple TV and the identifiers:
amine ~ $ atvremote scan Scan Results ======================================== Name: Apple TV Model/SW: Apple TV 4K, tvOS 16.6 Address: 10.1.1.14 MAC: 8C:42:99:82:4C:CB Deep Sleep: False Identifiers: - 8B2E0556-6BFF-46AB-B977-3D8E678D38A4 - 8C:42:99:82:4C:CB - 8C4299824CCB
Then we pair
atvremote with the ATV for the companion protocol (note
how we direct it to the ATV with the UUID, and not ip/hostname):
amine ~ $ atvremote --id 8B2E0556-6BFF-46AB-B977-3D8E678D38A4 --protocol companion pair Enter PIN on screen:
After that it spits out an authentiction token, which i saved as
~/.config/atv.credentials. Then we can start
atvproxy for the
amine ~ $ atvproxy companion `cat ~/.config/atv.credentials` 10.1.1.14 2023-08-18 00:50:30 DEBUG [pyatv.scripts]: Running with pyatv 0.13.4 2023-08-18 00:50:30 DEBUG [pyatv.scripts.atvproxy]: Binding to local address 10.1.1.13 2023-08-18 00:50:30 INFO [pyatv.scripts.atvproxy]: Started Companion server at port 46507 2023-08-18 00:50:30 DEBUG [pyatv.core.mdns]: Publishing zeroconf service: ServiceInfo(type='_companion-link._tcp.local.', name='Proxy._companion-link._tcp.local.', [....])
And now the proxy appears as an Apple TV named
Proxy on the network, which the
hass integratoin can connect to.
|2023-08-18||initial notes on pairing and starting |