cristian5th / homebridge-appletv

Configuration of pyatv and cmd4 for reading the Apple TV status in Homebridge
GNU General Public License v3.0
25 stars 2 forks source link

homebridge-appletv

Configuration of pyatv and homebridge-cmd4 for reading the Apple TV status in Homebridge.

Installation

pyatv installation on Synology NAS

Upgrade

Homebridge-cmd4 plugin configuration

Note: replace /var/lib/homebridge/ with /volume1/homebridge when using a Synology NAS


{
"platform": "Cmd4",
"name": "Cmd4",
"interval": 5,
"timeout": 4000,
"debug": false,
"stateChangeResponseTime": 3,
"queueTypes": [
{
"queue": "A",
"queueType": "WoRm"
}
],
"accessories": [
{
"type": "Switch",
"displayName": "ATV Power",
"on": "FALSE",
"queue": "A",
"polling": [
{
"characteristic": "on"
}
],
"state_cmd": "bash /var/lib/homebridge/appletv_control.sh"
},
{
"type": "Switch",
"displayName": "ATV Play",
"on": "FALSE",
"queue": "A",
"polling": [
{
"characteristic": "on"
}
],
"state_cmd": "bash /var/lib/homebridge/appletv_control.sh"
},
{
"type": "Switch",
"displayName": "ATV Video Play",
"on": "FALSE",
"queue": "A",
"polling": [
{
"characteristic": "on",
"interval": 6,
"timeout": 5000
}
],
"state_cmd": "bash /var/lib/homebridge/appletv_control.sh"
}

}



## Shell script `appletv_control.sh`
>**Note:** replace `/var/lib/homebridge/` with `/volume1/homebridge` when using a Synology NAS

- Place the script file inside the folder `/var/lib/homebridge/`
- Set the script as executable with the command `chmod +x /var/lib/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

**Some explanations about the Shell script:**
The script offers three informational switches. Only two of them execute actions when activated.
- *'ATV Power' switch will display the power status of the Apple TV.* The switch is shown activated when the Apple TV is other than stand-by mode and activated when the Apple TV is in stand-by mode. This switch sends an action to power on/off the Apple TV.
- *'ATV Play' switch will display the playing state of the Apple TV.* The switch is shown activated when the Apple TV is playing and deactivated otherwise. This switch sends an action to play/pause the Apple TV.
- *'ATV Video Play' switch will display a particular playing state of the Apple TV.* This switch has been programmed following personal preferences and you should update it to your particular needs. As it is, it will show activated when the Apple TV is playing/paused a video from the Apple TV app or the Home Sharing app and it will show deactivated otherwise. You may add other apps like Netfix, Disney, HBO,... If you want it to consider the playing/pause state regardless of the app being used, it is suggested to remove the code used to read the active app, as this request is taking quite long to answer, risking for Homebridge timeouts. This switch sends no action to the Apple TV and is merely used for automation purposes (close/open blinds and turn off/on lights when the movie starts/ends)

## Known issues

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](https://github.com/postlund/pyatv/issues/1667)).

## Many thanks to
- [postlund/pyatv](https://github.com/postlund/pyatv)
- [ztalbot2000/homebridge-cmd4](https://github.com/ztalbot2000/homebridge-cmd4)
- [NorthernMan54/homebridge-cmd-television](https://github.com/NorthernMan54/homebridge-cmd-television)