Apple TV Sleep Support

Feature Description:
Many users (such as myself) have an Apple TV 4k (A1842 (32 GB)) running 12.1 tvOS and have it CEC enabled with a television & receiver. This makes for a simple 1 remote setup to turn on the Receiver, TV and Apple TV. It also makes for a simple 1 remote setup to turn off the TV, Receiver and sleep the Apple TV.

As a user, I would like to have Home Assistant support sleeping my Apple TV, which would thus turn off my TV & Receiver.

Currently the Apple TV component does not support this.

Operating environment (Hass.io/Docker/Windows/etc.):
Docker

Component/platform:

Only Workaround:
The only workaround presently is a convoluted sequence of left/down/select options in a script; which is not stable (often doesn’t work).

apple_tv_off:
  alias: Apple TV Off
  sequence:
  - data:
      entity_id: media_player.onkyo_receiver_zone2
    service: media_player.turn_off
  - data:
      command: top_menu
      entity_id: remote.living_room_apple_tv
    service: remote.send_command
  - delay: 0:00:02
  - data:
      command: top_menu
      entity_id: remote.living_room_apple_tv
    service: remote.send_command
  - delay: 0:00:02
  - data:
      command: left
      entity_id: remote.living_room_apple_tv
    service: remote.send_command
  - data:
      command: left
      entity_id: remote.living_room_apple_tv
    service: remote.send_command
  - data:
      command: left
      entity_id: remote.living_room_apple_tv
    service: remote.send_command
  - data:
      command: left
      entity_id: remote.living_room_apple_tv
    service: remote.send_command
  - data:
      command: down
      entity_id: remote.living_room_apple_tv
    service: remote.send_command
  - data:
      command: down
      entity_id: remote.living_room_apple_tv
    service: remote.send_command
  - data:
      command: down
      entity_id: remote.living_room_apple_tv
    service: remote.send_command
  - data:
      command: down
      entity_id: remote.living_room_apple_tv
    service: remote.send_command
  - data:
      command: select
      entity_id: remote.living_room_apple_tv
    service: remote.send_command
  - delay: 0:00:02
  - data:
      command: down
      entity_id: remote.living_room_apple_tv
    service: remote.send_command
  - data:
      command: down
      entity_id: remote.living_room_apple_tv
    service: remote.send_command
  - data:
      command: down
      entity_id: remote.living_room_apple_tv
    service: remote.send_command
  - data:
      command: down
      entity_id: remote.living_room_apple_tv
    service: remote.send_command
  - data:
      command: down
      entity_id: remote.living_room_apple_tv
    service: remote.send_command
  - data:
      command: down
      entity_id: remote.living_room_apple_tv
    service: remote.send_command
  - data:
      command: down
      entity_id: remote.living_room_apple_tv
    service: remote.send_command
  - data:
      command: down
      entity_id: remote.living_room_apple_tv
    service: remote.send_command
  - data:
      command: select
      entity_id: remote.living_room_apple_tv
    service: remote.send_command

Relevant configuration.yaml entry:

apple_tv:
  - host: 192.X.X.X
    login_id: !secret apple_tv
    name: Living Room Apple TV
    start_off: true

Additional information:
Is it possible to begin integrating some of the latest changes from here?

Related Issues:


This is one of the most requested features and I would add it directly if someone figured out a way to do it reliably (and working with CEC). But as of today it is not possible AFAIK.

on this part what do you put in the login ID please

apple_tv:
  - host: 192.X.X.X
    login_id: !secret apple_tv
    name: Living Room Apple TV
    start_off: true

is it the identifier? IE

       Name: Bedroom
    Address: 192.168.0.21
Identifiers:
 - EBC060DF-DD08-3572-B89C-6B58E0BDF8D3
 - SC:46:E7:3D:B1:22

These are not compatible versions. The latter one is based on pyatv 0.4.x while the first one is pyatv 0.3.x (which is the one bundled with home Assistant). I recommend that you try out the beta component:

thats awesome that just worked straight away!
I want to control the boxes now but I’ve added a few different remotes but don’t seem to give me a lot of control to be honest just like a play pause button!
do you have full menu control ?

ive seen something like this service: remote.send_command

entity_id: remote.apple_tv 
  command:
    - left
    - left
    - menu
    - select

but mine seems to be media_player.living_room so not so sure ?

and where would I put the code in my config?

For each device you add, you get one media_player and one remote, e.g. media_player.living_room and remote.living_room. The remote entity is only for sending button presses (you cannot do that with the media player).

You can look at the interface to get an up-to-date list of supported buttons:

You can send all buttons from RemoteControl except for the once named set_.... It works exactly like you wrote here.

1 Like

so do I have to add this code ?

Nah, you can just look at all lines with def, e.g. def up(self): means you can send up and so on.