Alexa intent to control your Apple TV

Sometimes I lose my Apple TV remote and deviced to do something about it and decided I’d put Alexa to use since I haven’t misplaced my echo yet.

I created an intent that allows you to provide up to five commands (you can add more if you are interested) to control your Apple TV using the Remote control.

The Alexa Intent

  RemoteControl:
    action:
      - service_template: >
          {% macro run_script(button) %}{% if button=='up' %}script.apple_tv_up{% elif button=='down' %}script.apple_tv_down{% elif button=='left' %}script.apple_tv_left{% elif button=='right' %}script.apple_tv_right{% elif button=='menu' %}script.apple_tv_menu{% elif button=='play' %}script.play_tv{% elif button=='pause' %}script.pause_tv{% elif button=='tv' %}script.apple_tv_top_menu{% else %}script.apple_tv_select{% endif %}{% endmacro %}
          {{ run_script(B_ONE) }}
      - service_template: >
          {% macro run_script(button) %}{% if button=='up' %}script.apple_tv_up{% elif button=='down' %}script.apple_tv_down{% elif button=='left' %}script.apple_tv_left{% elif button=='right' %}script.apple_tv_right{% elif button=='menu' %}script.apple_tv_menu{% elif button=='play' %}script.play_tv{% elif button=='pause' %}script.pause_tv{% elif button=='tv' %}script.apple_tv_top_menu{% else %}script.apple_tv_select{% endif %}{% endmacro %}
          {% if B_TWO %}{{ run_script(B_TWO) }}{% else %}None{% endif %}
      - service_template: >
          {% macro run_script(button) %}{% if button=='up' %}script.apple_tv_up{% elif button=='down' %}script.apple_tv_down{% elif button=='left' %}script.apple_tv_left{% elif button=='right' %}script.apple_tv_right{% elif button=='menu' %}script.apple_tv_menu{% elif button=='play' %}script.play_tv{% elif button=='pause' %}script.pause_tv{% elif button=='tv' %}script.apple_tv_top_menu{% else %}script.apple_tv_select{% endif %}{% endmacro %}
          {% if B_THREE %}{{ run_script(B_THREE) }}{% else %}None{% endif %}
      - service_template: >
          {% macro run_script(button) %}{% if button=='up' %}script.apple_tv_up{% elif button=='down' %}script.apple_tv_down{% elif button=='left' %}script.apple_tv_left{% elif button=='right' %}script.apple_tv_right{% elif button=='menu' %}script.apple_tv_menu{% elif button=='play' %}script.play_tv{% elif button=='pause' %}script.pause_tv{% elif button=='tv' %}script.apple_tv_top_menu{% else %}script.apple_tv_select{% endif %}{% endmacro %}
          {% if B_FOUR %}{{ run_script(B_FOUR) }}{% else %}None{% endif %}
      - service_template: >
          {% macro run_script(button) %}{% if button=='up' %}script.apple_tv_up{% elif button=='down' %}script.apple_tv_down{% elif button=='left' %}script.apple_tv_left{% elif button=='right' %}script.apple_tv_right{% elif button=='menu' %}script.apple_tv_menu{% elif button=='play' %}script.play_tv{% elif button=='pause' %}script.pause_tv{% elif button=='tv' %}script.apple_tv_top_menu{% else %}script.apple_tv_select{% endif %}{% endmacro %}
          {% if B_FIVE %}{{ run_script(B_FIVE) }}{% else %}None{% endif %}
    speech:
      type: plain
      text: OK

The Alexa intent has Utterances using variations of five Intent Slots

{B_ONE} {B_TWO} {B_THREE} {B_FOUR} {B_FIVE}

So you can ask Alexa to

Menu Up Right Left Select

I’m sure there is a simpler way to accomplish this but I have used it a few times and thought I’d share the idea.

How did you get the script.apple_tv_up

@dumbstart

Utilizing the Apple TV platform gives you the ability to send remote control events and I created scripts to call the events as I use them all over the place.

apple_tv_up:
  sequence:
    - service: remote.send_command
      data:
        entity_id: remote.apple_tv
        command:
          - up
        device: ''

I’d be happy to share any other parts of my config and help where I can with any questions.

Please i would love to see how you did this in further detail. Do you have a repo i can visit?

@dumbstart

I hadn’t uploaded my config and you can check it out at my Github.

Home Assistant config

What you would be interested in would be found under home/living_room/apple_tv.yaml as well as apple_tv_automations.yaml.

I have my Apple TV to never sleep so it stays connected to my speakers to ensure I can always use it to send TTS.

Let me know if you have any questions.

2 Likes