Anyone have an example of ADB commands for Chromecast with Google TV(To Turn on pandora and start playing music-- to bypass sending by "cast")

Hello all,

Could anyone help me out with the subject? Or does anyone possibly have an example of doing this with the subject device? (I have heard ADB commands can be specific to the device)

I have verified that I can send the ADB commands to the TV (using Android TV Integration) but to be honest, I have no clue if it is even possible to get it to play music consistently. I really almost don’t even care what station as long as I can get it to play one of the recent ones.

The reason, I am wanting to do it by ADB commands is because when you do it through a routine on google assistant, it sends the audio to the television through a “cast” and almost all music services only allow 30 min- 1 hour until it stops playing (free tier).

By starting the app and music directly throught the TV interface, I have learned it goes for a few hours before stopping.

Question: Can you achieve what you want by using the voice command on the remote?

If so there is ADB code that you can send to mimic the voice search / command function if that helps?

@rossk

Thank you so much for this idea. I didn’t even realize adb commands could “attach to” voice commands from the remote.

I will give this a try when I get home this evening and report back hear more of your thoughts.

Hopefully, voice commands (for music apps) from the remote don’t automatically deviate to “cast” usage.

I will run 2 test:

  1. Running voice command “Play 2000s rock on pandora” from the main menu of Google TV.
  2. Open pandora with ADB command, see if I can find a consistent way to navigate to the pandora search bar by adb navigation commands, and then run voice search of “Play 2000s rock on pandora” from the search bar.

Thank you again @rossk, hopefully we can get this one going. The hour or so of music and then just turning off is maddening and I’m so cheap. haha.

This is what I use to replicate the CCWGTV search / command via HA if it helps any!

service: androidtv.adb_command
data:
  command: >-
    input keyevent MENU &&  am start -a  
    "android.search.action.GLOBAL_SEARCH" --es query "play suits on netflix" 
    -e source 30 && input keyevent 23 && input keyevent 23 && input keyevent 23
target:
  entity_id: media_player.android_tv_office_ccwgtv

They shouldn’t do as long as you are loading an actual app.

Thank you for this.

I think like you said, this is the key.

Before I left the house this morning, I did a quick check with the remote from the main menu screen and it resorted to cast usage.

I’m sure you’re “spot on” and as long as I open the app first with the “com…” start app language in HA automation actions, that with the app running and the voice command in usage, it moves forward without cast.

How do you get ahold of the adb language for the events? I couldn’t figure out how to get ahold of the event language last night trying to run the event catcher from the developer service menu (for some reason, the “call service” button would never let the grey go away from over the button)

If you have an example of this or get time to be able to paste an example of this part of the process, I would be very grateful.

Thank you again for showing your talent with this stuff. I’ll get there eventually. lol

Only on my iPhone at the moment so will take a look at what I have when I am in front of a computer.

However most of the time, I simply select the source (app) via home assistant, small delay and then send the above adb command to tell the app what I want to watch from within the now opened app.

Open the app in question and check the source in developer tools (as they are not all listed unless active) then try a quick script to select that source and then send adb to command.

Not a problem. Thank you for this. (See below response)

I will give this a try when I get home in just a bit.

I will report back either way but I think I am following you. Crossing my fingers!!

So the code post below still sent it as a “cast”. I think the “GLOBAL_SEARCH” is what is causing it. It’s essentially searching the whole google tv through its general search feature. If you happen to have any other ideas, I definitely won’t turn them down.

Consistency is what I’m hoping to be able to maintain. And the only ideas I have are to 1.) Find a consistent/ repeatable way to navigate the Google TV GUI to get what I want (which sounds like a disaster- but may be the only way) or 2.) find a way to voice search within the app but the problem with that is, it looks like you still have to navigate to the search bar within the individual app or the search is a “GLOBAL SEARCH” as you are showing me.

1.) How did you learn/ where did you find the command you needed to make the voice search work properly?

2.) And hopefully the last one is. Do you know how to turn the google tv on and off within home assistant?-- → EDIT: I now see there are “POWER” and “SLEEP” commands in the documentation for AndroidTV ADB commands. (no need to respond on this one)

service: media_player.select_source
data:
  source: '"com.pandora.android.atv"'
target:
  entity_id: media_player.android_tv_192_168_1_43

service: androidtv.adb_command
data:
  command: >-
    input keyevent MENU &&  am start -a  
    "android.search.action.GLOBAL_SEARCH" --es query "play 2000s rock on pandora" 
    -e source 30 && input keyevent 23 && input keyevent 23 && input keyevent 23
target:
  entity_id: media_player.android_tv_192_168_1_43

@rossk thank you for always being willing to help with things even when they do get a little “sticky”

So I got the event recorder working. For instance, the adb command for down is:

Android TV

Output from service ‘learn_sendevent’ from media_player.android_tv_192_168_1_43:

'sendevent /dev/input/event5 4 4 786499 && sendevent /dev/input/event5 1 108 1 && sendevent /dev/input/event5 0 0 0 && sendevent /dev/input/event5 4 4 786499 && sendevent /dev/input/event5 1 108 0 && sendevent /dev/input/event5 0 0 0'

EDIT: The above doesn’t work for the voice search button though. haha

Also, for others, force close an app is as below:

service: androidtv.adb_command
data:
  command: am force-stop "com.pandora.android.atv"
target:
  entity_id: media_player.android_tv_192_168_1_137
enabled: true

Most of the stuff I have discovered over time and just keep notes in one note.

This is a pretty good resource for commands:

Ahh, Thank you for these. These will be helpful.

1 Like

Message me if I can help any more, still playing with some of this myself to be honest.

I appreciate that.

After messing with it some more, it looks like this is how Pandora has decided to treat voice search involving their app (everything handled by cast).

I tried a few other music apps and it looks like they work more like we would expect and function properly with your great idea.

For Pandora, the best I can come up with is to find a somewhat repeatable set of navigation commands.

Is there a quick way to send text to a search field within an app that you know of, or is the best you can think of is send individual letters through key press commands to build the words being searched for??—> I see how your global search works, I was wandering if there was a way to apply that to a search bar within an app.

Thank you for your thoughts, maybe this will also help someone in the future

Not that I have found as yet, the problem is the delay is sending multiple key values appears to be a bit of a bottle neck

1 Like

Hello from the future! This may help someone… I made a script that enables the current app’s search and tied it to an input_text entity for queries and an input_button entity to run the script:

alias: Android TV Search
sequence:
  - service: androidtv.adb_command
    data:
      command: input keyevent SEARCH
    target:
      entity_id: media_player.android_tv
  - service: androidtv.adb_command
    data:
      command: >-
        input keyevent DEL && input text {{
        '"'+states('input_text.text_field')+'"' }} && input keyevent ENTER
    target:
      entity_id: media_player.android_tv
mode: single
icon: mdi:card-search-outline

This is the reason why two consecutive commands need to be used.