Using the Apple TV as an alarm clock?

Okay, I’ve been trying to get this to work for a while now. I have an Apple TV in my bedroom, and I want it to play the news in the morning.
My best guess has been to script remote input into my Apple TV and open what I want. Here’s my last attempt at it, and it works about 30% of the time (no idea why it’s so sporadic)

################################################################################
wakeup_apple_tv:
  alias: 'Wakeup - Apple TV'
  sequence:
# Turn on the TV
    - service: remote.send_command
      data:
        entity_id: remote.master_bedroom_apple_tv
        command:
          - menu
    - delay:
        seconds: 15
# Go to the home menu
    - service: remote.send_command
      data:
        entity_id: remote.master_bedroom_apple_tv
        command:
          - top_menu
    - delay:
        seconds: 1
# Go to the first menu item (Plex)
    - service: remote.send_command
      data:
        entity_id: remote.master_bedroom_apple_tv
        command:
          - menu
# Open Plex
    - service: remote.send_command
      data:
        entity_id: remote.master_bedroom_apple_tv
        command:
          - select
    - delay:
        seconds: 15
# Select Apocrathia user account
    - service: remote.send_command
      data:
        entity_id: remote.master_bedroom_apple_tv
        command:
          - select
    - delay:
        seconds: 5
# Go to news
    - service: remote.send_command
      data:
        entity_id: remote.master_bedroom_apple_tv
        command:
          - down
          - right
          - right
          - right
          - right
          - right
          - right
          - select
    - delay:
        seconds: 15
# Fullscreen
    - service: remote.send_command
      data:
        entity_id: remote.master_bedroom_apple_tv
        command:
          - select
################################################################################

I’m out of ideas. As you can see, I’m trying to open Plex, and go to the news section. I’ve also got Haystack.tv on my Apple TV, but that seems to be even less reliable. Does anybody have any ideas? I’ve even tried using the media_player.play_media call to send something over (just an NPR stream, even) and that won’t work either.

1 Like

Does play media work at all? I do something similar where it starts playing C-Span Washington Journal, no judgment please, when I’m getting ready.

I have a shell script that gets the episode links each morning and then feeds them to Home Assistant using the api. It works great as it even plays it in higher quality than if I AirPlay it from my phone.

If you’d like I can send you the script. It’s hobbled together out of ASCII and love and may not work for you but I can share it. It’s very simple and just uses curl and grep to suss out the links then it sends it to Hassio.

Here’s the bash function from the script.

function play_segment() {
  curl -s -X POST -H "Content-Type: application/json" -H "x-ha-access: $hass_pass" -d '{"entity_id": "media_player.living_room","media_content_id": "'"$selected_url"'","media_content_type": "video"}' "$hass_url/api/services/media_extractor/play_media" > /dev/null
}

selected_url is the url of the segment and hass_url is my Hassio site. So when I need to wake up it runs a shell_command which sorts everything out and sends the video over.

Recently I’ve switched to a Bluetooth speaker setup, quality is near meaningless to me, so I can continue to send notifications out when the projector is off which would work out in your case as the audio would begin as the tv starts up.

Can you try to use play_media from a youtube video to see if that works?

Navigating like this should work “ok”, assuming that nothing moves around and you always start in the same place and your delays are long enough to handle all kind of buffering delays in the app and menus and nothing fails to load (you see that there are a lot of ifs here). Using play_media should work a lot better. For that to work you must first authenticate:

…and then pass the live stream URL. Remember that Apple is quite picky with formats and you can not just send anything to it. Some guide lines regarding what is supported can be found here:

https://developer.apple.com/library/content/documentation/AudioVideo/Conceptual/AirPlayGuide/PreparingYourMediaforAirPlay/PreparingYourMediaforAirPlay.html

If it’s not possible to get a static link to the news stream (=it’s same every day), adding support to youtube-dl would be the optimum solution. That way you could use the media_extractor component to get the video stream URL. It does not support Haystack.tv now however.

It can be frustrating having the remote navigate long paths when it doesn’t start where you are expecting. The issue I ran into was not being able to know if it is on the screen saver or on the menu. The first command sent will either leave the screen saver and return to the menu or leave the menu and start the screen saver.