Apple TV Automation - Stopping Playback at 01:00 Everyday

Long time reader, first time post …

At night, we fall asleep watching TV on Apple TV with the Channels App (using a SiliconDust HD Homerun Prime). Since Apple TV does not have a sleep timer, or Channels, it will continue to play content on Channels, or other Apps (i.e. Netflix). There is a CURL command that I can schedule and will stop channels playback, but will not apply if watching another App.

I would like to use HomeAssistant to schedule a MENU command to be sent to Apple TV at 01:00. This will stop playback, eventually Apple TV and TV (via HDMI CEC) will enter power save and turn off. I know the concept works because I am currently using a BroadLink IR Control Hub to do this, sending the Menu command at 01:00, but I just want to reduce clutter.

I’ve successfully added the Apple TV to my configuration.yaml

# Apple_TV
apple_tv:
  - host: 10.0.1.27
    login_id: XXXX
    name: ATV_MasterBedroom
    start_off: true
    credentials: XXXX

I’m trying to call the following in automations.yaml, it triggers correctly, but the command is not taking place on Apple TV. What am I doing wrong?

- id: ATV_Master_Bedroom_Automation
  alias: "Turn Off Master Bedroom TV @ 01:00AM"
  trigger:
  - platform: time
    at: '01:00:00'
  action:
  - service: remote.send_command
    data:
      entity_id: media_player.master_bedroom
      command:
        - top_menu

Difficult to tell because you have ignored the instructions at the top of the page to format your code properly, but I think you need a couple of extra spaces in the final line, before

- top_menu

Sorry, I hit the Code Blocks button and thought I could simply paste my code in. I actually needed to highlight it. I’ve edited my post.

Unfortunately, a few extra spaces in the final line did not work for me. Is there any way to see the service call in logs and if a error is generated from it?

OK. Sorted my problem!

I was using the entity_id for the Apple TV in my service call and not the entity_id created for the Remote Interface itself.

Therefore, after scanning for Apple TVs on network, you will see the entity_id. In this case, it was:

media_player.master_bedroom

When calling the service below, you need to reference a new entity_id:

remote.master_bedroom

- id: ATV_Master_Bedroom_Automation
  alias: "Turn Off Master Bedroom TV @ 01:00AM"
  trigger:
  - platform: time
    at: '01:00:00'
  action:
  - service: remote.send_command
    data:
      entity_id: remote.master_bedroom
      command:
        - top_menu

All works!