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.