Quickly send button commands to Android TVs using ADB. Works with CCwGTV too

Tags: #<Tag:0x00007fc40bde8628> #<Tag:0x00007fc40bde82e0>

Script: https://github.com/redphx/hassio-cookbook/tree/main/scripts/androidtv_press_buttons
Demo: https://youtu.be/mrJS9Q_toQw

Comparison:

Normal method, painfully slow. You could use “sendevent” commands instead, but the code is still long.

youtube_report_ads:
  alias: Report Youtube ads
  sequence:
    - service: androidtv.adb_command
      target:
        entity_id: media_player.android_tv
      data:
        command: PLAY_PAUSE
    - service: androidtv.adb_command
      target:
        entity_id: media_player.android_tv
      data:
        command: DOWN
    - service: androidtv.adb_command
      target:
        entity_id: media_player.android_tv
      data:
        command: UP
    ...

Faster method. Easy to write & understand.

youtube_report_ads:
  alias: Report Youtube ads
  sequence:
    - service: script.android_tv_press_buttons
      data:
        entity_id: media_player.android_tv_living_room
        method: sendevent
        buttons:
          - PLAY_PAUSE

          # Press 4 buttons with minimal delay
          - - DOWN
            - UP
            - UP
            - CENTER

          # Wait for 1 second
          - SLEEP 1

          - - DOWN
            - DOWN
            - DOWN
            - CENTER

          - SLEEP 0.5

          - - UP
            - CENTER

          - PLAY_PAUSE

Of cource this work on CCwGTV too. Just use method: default instead.

2 Likes

I saw your script on reddit. Unfortunately, it does not work for me. I use a packages folder that includes multiple yaml files, each housing multiple entities/automations/scripts.

How would you put your scripts in one single file? For example

automation:
  - alias "bla"
    # ...

binary_sensor:
  hi_mom:
    friendly_name: "Yeah yeah"
    # ...

script:
# your scripts

I tried putting the scripts in the way I assumed they should work, but somehow, nothing happens when I try running them. I adapted them to my media_player entity, of course.

Or see here for what I am trying to do :slight_smile:

Do you have scripts.yaml file? Just copy my scripts and put them into that file. No need to do anything special.

Im confused -

On your github you mention that sendevent (the fast method) doesnt work with the CCwGTV.

But here in your title youre saying it does.
it appears to me that only the default works with CCwGTV. If I am not interested in reporting Youtube ads, and want to just control the device, this does not seem any faster than the normal (slow) commands, is that correct?

If you want to use with CCwGTV just remove the line method: sendevent.
And no, my script is faster than the default method found in HA.

Its faster at button combos, sure.
It wont be faster when simply navigating normally because of the delay. Unless Im mistaking your code.

I will be using this for my shield though, thank you :slight_smile: