Carlos Santos

iOS Dev

Apple TV Homeassistant Integration

2019-02-02 2 mintech unsplash-logoAsh Edmonds

Recently I had tried to integrate my Apple TV 4K with following the guide available on Homeassistant’s docs.

You need to scan your device, but I couldn’t get that working for nothing in this world that it was required for the setup.

It’s supposed to work via apple_tv domain and apple_tv_scan service .

Maybe I couldn’t due to some missing dependencies, as I have Hass installed via docker. 🤷‍♂️

You’ll need login_id.

So I run into this /r/homeassistant post that helped me a lot.

Running the following python script would allow me to find my Apple TV and get the tokens I needed to set it up on Homeassistant


Save this snippet as (you may need to either install pyatv and asyncio):

import pyatv
import asyncio

def discover(loop):
    atvs = yield from pyatv.scan_for_apple_tvs(loop, timeout=5)

# Devices are now in atvs

loop = asyncio.get_event_loop()

And then run:

$ python3

This willl print something like this:

[AppleTVDevice(name='Living room', address=IPv4Address(''), login_id='00000000-0ea5-1c43-c57b-58bb37bd5726', port=3689, airplay_port=7000)]

And voilá, here’s what you need 🎊 to set it up on Homeassistant.

After that, you just need to use this to call apple_tv_authenticate service and it should all work.

With this setup you’ll have access to the AppleTV component and a remote component that you can use for example to turn on and play stuff when you arrive home…

Or maybe broadcast a voice message to your family, it’s up to your imagination… it’s also creepy 😁.