Apple tvOS 15 Homebridge Control

If you use Homebridge and have an Apple TV you may know since tvOS 15 on/off control stopped working with the Homebridge Apple TV Remote plugin, the plug fails to find your AppleTV and is not yet fixed.

However I have come come up with a workaround and now have tvOS 15 on/off control.

I run Homebridge on a Raspberry Pi and the first step is to install the latest version ofย https://pyatv.dev

Once installed I then paired my Apple TV using the command
atvremote -s APPLETVIPADDRESS --protocol companion pair

atvremote -s 192.168.1.100 --protocol companion pair
Enter PIN on screen: 4337
Pairing seems to have succeeded, yey!
You may now use these credentials: ac1c0e52f256dc5f7b47f5f1f4f1e2a40b3c5676f7d598ac686de8b2afc23a54:cba29ca821e92d98ffa8e1eeab5b18a26b2b6a431f5056b452021ee057fa4a6b:43463041354438422d384242362<SNIP>

I copied the long string of numbers and created 3 shell scripts, adding my IP address of the ATV and the long string of numbers to each:

appletv_on.sh
atvremote -s 192.168.1.100 --airplay-credentials ac1c0e52f256dc5f7b47f5f1f4f1e2a40b3c5676f7d598ac686de8b2afc23a54:cba29ca821e92d98ffa8e1eeab5b18a26b2b6a431f5056b452021ee057fa4a6b:43463041354438422d384242362<SNIP> turn_on

appletv_off.sh
atvremote -s 192.168.1.100 --airplay-credentials ac1c0e52f256dc5f7b47f5f1f4f1e2a40b3c5676f7d598ac686de8b2afc23a54:cba29ca821e92d98ffa8e1eeab5b18a26b2b6a431f5056b452021ee057fa4a6b:43463041354438422d384242362<SNIP> turn_off

appletv_state.sh
atvremote -s 192.168.1.100 --airplay-credentials ac1c0e52f256dc5f7b47f5f1f4f1e2a40b3c5676f7d598ac686de8b2afc23a54:cba29ca821e92d98ffa8e1eeab5b18a26b2b6a431f5056b452021ee057fa4a6b:43463041354438422d384242362<SNIP> power_state

I copied those 3 scripts to my Raspberry Pi at /var/lib/homebridge

I then installed homebridge-script2-ventrilo Homebridge plugin which is a simple plugin that can run the scripts and added the following config:

{
    "accessory": "Script2",
    "name": "ATV",
    "on": "/var/lib/homebridge/appletv_on.sh",
    "off": "/var/lib/homebridge/appletv_off.sh",
    "state": "/var/lib/homebridge/appletv_state.sh",
    "fileState": "/var/lib/homebridge/script1.flag",
    "on_value": "true"
}

In Home app I can now turn on and off the ATV ๐Ÿ™‚

As I run the Alexa Homebridge plugin I told Alexa to discover devices, ATV was found and I added this to a routine “Watch Apple TV” which turns on the TV, AV Amp, switches HDMI input and now powers on the AppleTV ๐Ÿ™‚