Apple TV - Open Apps via Home Assistant

Hey,

I hope someone who already uses Apple TV and Home Assistant can help me out. I have some pre-sale questions for an Apple TV:

Is it possible to open Apps (like Netflix, Youtube, etc.) via Home Assistant?

What I want to achieve:
Use a switch to turn on my AVR, turn on Apple TV, switch to Spotify App and play media.
Or create a Netflix-Switch. I hit this switch, my TV turns on, my AVR turns on, Apple TV turns on and opens Netflix app.

There is no info regarding my question on the Home Assistant component site: https://www.home-assistant.io/components/apple_tv/

FYI: I have own a Logitech Harmony Hub.

You can send the same commands as with the Siri Remote. Take a look here:

You should be able to send the necessary sequence of commands to navigate to e.g. the netflix app.

Thanks for your reply.

Not exactly what I was thinking about, but I guess it will work. There is nothing like: input_select.source: Netflix, right?

Yes, thatā€™s right. As @Tribune suggested and I had done that, you may create scripts that send the right sequence of remote commands to open the desired app. You can even put some delays to wait for the app to load and then go thru the login/select things.

p.s. no spotify on apple tv :frowning:

Unfortunately no, there is no API to open apps natively.

Thanks for your replies.

Sending commands on my Harmony remote might be the solution.
But I totally missed that there is no Spotify (Connect) support, which is really disappointing.

I have to think about how to integrate Airplay into my systemā€¦

Use a Chromecast with the Airplay addon?

Good idea or buy a new AVR which has Airplay/Spotify Connect included.
Chromecast is way cheaper of courseā€¦

Iā€™ve just tried to do this, it seems to work. But how do you make sure it always works?

Is it possible to see if Apple TV is asleep? So we can wake it up, wait for it to be active and start our sequence?

And how do we know where the cursor is? I guess menu / top-menu (not sure what the difference is) will bring us to the beginning. But then what?

Could you share your config?

You are right, you dont know for sureā€¦ But you can get pretty close :-). Try something like this:

start_zwift:
  sequence:
    - service: remote.send_command
      data:
        entity_id: remote.apple_tv_livingroom
        command:
          - menu
    - delay: 00:00:02
    - service: remote.send_command
      data:
        entity_id: remote.apple_tv_livingroom
        command:
          - top_menu
    - delay: 00:00:02            
    - service: remote.send_command
      data:
        entity_id: remote.apple_tv_livingroom
        command:
          - right
          - right
          - down
    - delay: 00:00:02
    - service: remote.send_command
      data:
        entity_id: remote.apple_tv_livingroom
        command:
          - select

The first ā€œmenuā€ command is just to ā€œwake upā€ the atv. ā€œtop-menuā€ brings the ATV to the ā€œhome screenā€ so you kind know where the cursor is. Then you have to adapt to your case where your app is. As long you dont keep changing the positions of the apps, it should work. Maybe the ā€œdelayā€ isnt needed but since it worked I left them there.

3 Likes

Thanks for sharing! This is very close to what I have so far.

Iā€™m going to add the delays and see if that helps. I have the feeling that sometimes Iā€™m too fast for the ATV to register each step. Adding more delays would solve this perhaps.

I have added commands to scripts.yaml file to start netflix. Test execute the script and it works. How can I setup HA to tell Alexa to run the command? I have emulated hue installed.

You can expose the script domain to emulated_hue and call it that way.

1 Like

I have figure it out. We need to create an input boolean as a trigger to run the script and expose the input boolean for Alexa to turn it on via voice command.

input_boolean.yaml
(Note: Need to install Simpleicon via HACS since some brand logos have been ā€˜movedā€™.)

  appletv_netflix:
    name: AppleTV Netflix
    icon: si:netflix
    initial: off

scripts.yaml

# Turn on Netflix via AppleTV
  appletv_netflix:
      alias: Appletv Netflix
      sequence:
        - service: remote.send_command
          data:
            entity_id: remote.living_room
            command:
              - menu
        - delay: 00:00:08
        - service: remote.send_command
          data:
            entity_id: remote.living_room
            command:
              - menu
        - delay: 00:00:02
        - service: remote.send_command
          data:
            entity_id: remote.living_room
            command:
              - down
        - delay: 00:00:02
        - service: remote.send_command
          data:
            entity_id: remote.living_room
            command:
              - select

automations.yaml

# Turn on Appletv Netflix
- alias: 'turn on appletv netflix'
  trigger:
    platform: state
    entity_id: input_boolean.appletv_netflix
    from: 'off'
    to: 'on'
  action:
  - service: script.turn_on
    entity_id: script.appletv_netflix
  - service: input_boolean.toggle
    entity_id: input_boolean.appletv_netflix

emulated_hue.yaml

#emulated_hue:
  host_ip: !secret emulated_hue_ip
  listen_port: 80
  off_maps_to_on_domains:
    - automation
  expose_by_default: false
  exposed_domains:
    - input_boolean
  entities:
    input_boolean.appletv_netflix:
      name: 'Appletv Netflix'
      hidden: false

It is now possible to launch apps directly (vs using several programmed button presses). Iā€™m not sure if itā€™s new to v15 or specific to newer devices, but the sources show in a drop down on the info tab of my Apple TV device menu, and I have successfully launched Disney+ with a script using the media_player.select_source service (ā€œMedia player: select sourceā€ in UI). When configuring my test script, I typed the source name exactly as it is shown in that dropdown.

1 Like