Docker Configuration of pyatv and homebridge-cmd4 for reading the Apple TV status in Homebridge.
Add the following Environment variables:
- PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/homebridge/python/bin
- PYTHONPATH=/homebridge/python
version: '2'
services:
homebridge:
image: oznu/homebridge:ubuntu
restart: always
network_mode: host
environment:
- PGID=1000
- PUID=1000
- HOMEBRIDGE_CONFIG_UI=1
- HOMEBRIDGE_CONFIG_UI_PORT=8581
- TZ=Europe/Berlin
- PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/homebridge/python/bin
- PYTHONPATH=/homebridge/python
volumes:
- ./data:/homebridge
Enter console
docker exec -it $CONTAINERNAME /bin/bash
mkdir /homebridge/python
pip3 install --upgrade pip
pip3 install --target /homebridge/python cryptography
pip3 install --target /homebridge/python pyatv
atvremote scan
atvremote --id AA:BB:CC:DD:EE:FF --protocol airplay pair
atvremote --id AA:BB:CC:DD:EE:FF --protocol companion pair
- Place the script file inside the folder
/homebridge/
- Set the script as executable with the command
chmod +x /homebridge/appletv_control.sh
- Change ATV_id with the ID of your Apple TV
- Change airplay_credentials with the credentials given when pairing with the Apple TV
- Change companion_credentials with the credentials given when pairing with the Apple TV
- Install homebridge-cmd4 plugin.
{
"platform": "Cmd4",
"name": "Cmd4",
"interval": 5,
"timeout": 4000,
"debug": false,
"stateChangeResponseTime": 3,
"queueTypes": [
{
"queue": "A",
"queueType": "Sequential"
}
],
"accessories": [
{
"type": "Switch",
"displayName": "Apple TV Movie State",
"on": "FALSE",
"queue": "A",
"polling": [
{
"characteristic": "on"
}
],
"state_cmd": "bash /homebridge/appletv_control.sh"
}
]
}
There is a known issue for pyatv if you have configured a Homepod to be the default audio output. In this case, you will always get the power to be ON (postlund/pyatv#1667).
# Get Movie State
/homebridge/appletv_control.sh Get "Apple TV Movie State" "On"
# Get Play State
# A
/homebridge/appletv_control.sh Get "Apple TV Play State" "On"
# B
atvremote --id 90:DD:5D:AA:AA:AA --airplay-credentials `cat /homebridge/atv_airplay.cred` --companion-credentials `cat /homebridge/atv_companion.cred` playing
# Get Power State
# A
/homebridge/appletv_control.sh Get "Apple TV Power" "On"
# B
atvremote --id 90:DD:5D:AA:AA:AA --airplay-credentials `cat /homebridge/atv_airplay.cred` --companion-credentials `cat /homebridge/atv_companion.cred` power_state