Skip to content

Instantly share code, notes, and snippets.

@mcfrojd
Last active March 30, 2024 16:53
Show Gist options
  • Save mcfrojd/9e6875e1db5c089b1e3ddeb7dba0f304 to your computer and use it in GitHub Desktop.
Save mcfrojd/9e6875e1db5c089b1e3ddeb7dba0f304 to your computer and use it in GitHub Desktop.
Working INTENTS to use with Community Hass.io Add-ons: Android Debug Bridge for your Nvidia Shield TV

Latest Update 2021-03-06 : New image showing the new "Services" in Home Assistant and got some tips from the comments below.

Credits and thanks: Home Assistant Forum users & Github users: @ocso, @wiphye, @teachingbirds, @tboyce1, @simbesh, @JeffLIrion @ff12 @rebmemer @siaox @DiederikvandenB @Thebuz @clapbr @Finsterclown


Start apps on your android device (in the examples below, my Nvidia Shield TV) from Home Assistant

alt text

Starts Youtube App

entity_id: media_player.shield
command: >-
  am start -a android.intent.action.VIEW -n
  com.google.android.youtube.tv/com.google.android.apps.youtube.tv.activity.ShellActivity

Starts Kodi

entity_id: media_player.shield
command: >-
  am start -a android.intent.action.VIEW -n
  org.xbmc.kodi/.Splash

Starts Twitch

entity_id: media_player.shield
command: >-
  am start -a android.intent.action.VIEW -n
  tv.twitch.android.app/tv.twitch.android.apps.TwitchActivity

Starts Netflix (Shows profiles if its the first start.)


entity_id: media_player.shield
command: >-
  am start -a android.intent.action.VIEW -n
  android.intent.action.VIEW -d -n com.netflix.ninja/.MainActivity

Starts TV4 Play (swedish streaming)

entity_id: media_player.shield
command: >-
  am start -a android.intent.action.VIEW -n
  se.tv4.tv4playtab/se.tv4.tv4play.startup.SplashActivity

Starts SVT Play (swedish streaming)

entity_id: media_player.shield
command: >-
  am start -a android.intent.action.VIEW -n
  se.svt.android.svtplay/se.svt.svtplay.tv.ui.StartupActivity

Starts C More (swedish streaming)

entity_id: media_player.shield
command: >-
  am start -a android.intent.action.VIEW -n
  se.cmore.bonnier/.androidtv.splash.TvConfigurationActivity

Starts ViaPlay (swedish streaming)

entity_id: media_player.shield
command: >-
  am start -a android.intent.action.VIEW -n
  com.viaplay.android/.features.home.HomeActivity

Starts specific Twitch stream (If stream is live)

entity_id: media_player.shield
command: >-
  am start -a android.intent.action.VIEW -d
  twitch://stream/frenck
entity_id: media_player.shield
command: >-
  am start -a android.intent.action.VIEW -d
  twitch://stream/drzzs

KILL apps on your Shield from Home Assistant

Kills YOUTUBE App

entity_id: media_player.shield
command: >-
  am force-stop
  com.google.android.youtube.tv

Kills KODI App

entity_id: media_player.shield
command: >-
  am force-stop
  org.xbmc.kodi

Kills TWITCH App

entity_id: media_player.shield
command: >-
  am force-stop
  tv.twitch.android.app

Kills NETFLIX App

entity_id: media_player.shield
command: >-
  am force-stop
  com.netflix.ninja

Kills SVT PLAY App

entity_id: media_player.shield
command: >-
  am force-stop
  se.svt.android.svtplay

Kills TV4 PLAY App

entity_id: media_player.shield
command: >-
  am force-stop
  se.tv4.tv4playtab

Kills C MORE App

entity_id: media_player.shield
command: >-
  am force-stop
  se.cmore.bonnier

Install apps on your Android Device from Home Assistant

Not tested my self, but tips from https://gist.github.com/JeffLIrion

entity_id: media_player.fire_tv_living_room
command: >-
  pm install -r /sdcard/Download/something.apk

Shield navigation and controlling

RIGHT   {"entity_id" :"media_player.shield", "command": "RIGHT"}
LEFT    {"entity_id" :"media_player.shield", "command": "LEFT"}
UP      {"entity_id" :"media_player.shield", "command": "UP"}
DOWN    {"entity_id" :"media_player.shield", "command": "DOWN"}
WAKE    {"entity_id" :"media_player.shield", "command": "MENU"} # use to be the "WAKEUP" command
SLEEP   {"entity_id" :"media_player.shield", "command": "SLEEP"}
ENTER   {"entity_id" :"media_player.shield", "command": "ENTER"}
BACK    {"entity_id" :"media_player.shield", "command": "BACK"}
HOME    {"entity_id" :"media_player.shield", "command": "HOME"}
PLAY    {"entity_id" :"media_player.shield", "command": "input keyevent 126"}
PAUSE   {"entity_id" :"media_player.shield", "command": "input keyevent 127"}
STOP    {"entity_id" :"media_player.shield", "command": "input keyevent 86"}

Intents i'm not using, but someone could have interest in.

(Not tested by me, but tested by people in the Home Assistant Forum.)

Starts Hulu App

entity_id: media_player.shield
command: >-
  am start -a android.intent.action.VIEW -n
  com.hulu.livingroomplus/.MainActivity

Starts Live Channels App

entity_id: media_player.shield
command: >-
  am start -a android.intent.action.VIEW -n
  com.google.android.tv/com.android.tv.MainActivity

Starts Amazon App

entity_id: media_player.shield
command: >-
  am start -a android.intent.action.VIEW -n
  com.amazon.amazonvideo.livingroom/com.amazon.ignition.IgnitionActivity

Starts SPMC App

entity_id: media_player.shield
command: >-
  am start -a android.intent.action.VIEW -n
  com.semperpax.spmc17/.Splash

Starts Haystack App

entity_id: media_player.shield
command: >-
  am start -a android.intent.action.VIEW -n
  com.haystack.android/.tv.ui.LoadingActivity

Starts PBS App

entity_id: media_player.shield
command: >-
  am start -a android.intent.action.VIEW -n
  com.pbs.video/.ui.main.activities.StartupActivity

Starts Pluto TV App

entity_id: media_player.shield
command: >-
  am start -a android.intent.action.VIEW -n
  tv.pluto.android/.leanback.controller.LeanbackSplashOnboardActivity

Starts Spotify App

entity_id: media_player.shield
command: >-
  am start -a android.intent.action.VIEW -n
  com.spotify.tv.android/.SpotifyTVActivity

Starts HBO Go App

entity_id: media_player.shield
command: >-
  am start -a android.intent.action.VIEW -n
  eu.hbogo.androidtv.production/eu.hbogo.androidtv.MainActivity

Starts Plex App

entity_id: media_player.shield
command: >-
  am start -a android.intent.action.VIEW -n
  com.plexapp.android/com.plexapp.plex.activities.SplashActivity

Starts Perfect Player App

entity_id: media_player.shield
command: >-
  am start -a android.intent.action.VIEW -n
  com.niklabs.pp/com.niklabs.perfectplayer.MainActivity

Starts S0undTV (twtich) App

entity_id: media_player.shield
command: >-
  am start -a android.intent.action.VIEW -n
  com.s0und.s0undtv/com.s0und.s0undtv.activities.MainActivity

Starts SmartYoutubeTV App

entity_id: media_player.shield
command: >-
  am start -a android.intent.action.VIEW -n
  com.liskovsoft.videomanager/com.liskovsoft.smartyoutubetv.bootstrap.BootstrapActivity

Starts Steam Link App

entity_id: media_player.shield
command: >-
  am start -a android.intent.action.VIEW -n
  com.valvesoftware.steamlink/com.valvesoftware.steamlink.SteamShellActivity

Starts Ziggo TV App

entity_id: media_player.shield
command: >-
  am start -a android.intent.action.VIEW -n
  com.ziggo.tv/com.lgi.horizongo.core.activity.splash.SplashActivity

Starts Tivimate/ImPlayer App

entity_id: media_player.shield
command: >-
  am start -a android.intent.action.VIEW -n
  ar.tvplayer.tv/.ui.MainActivity

Show local video with KODI

entity_id: media_player.shield
command: >-
  am start -a android.intent.action.VIEW -d
  file:///storage/emulated/0/Android/data/files/sunrise.mp4 -n
  org.xbmc.kodi/.Splash

RTSP stream with VLC

entity_id: media_player.shield
command: >-
  am start -a android.intent.action.VIEW -d
  rtsp://user:password@192.168.1.X:XXX/Streaming/Channels/301 -n
  org.videolan.vlc/.gui.video.VideoPlayerActivity

Intents to change the HDMI input on TVs with Android TV built in (@Thebuz)

HW1-9 Represent various inputs, 1-4 maybe for composite etc. depending on the model of TV

HDMI 1

adb shell am start -a android.intent.action.VIEW -d content://android.media.tv/passthrough/com.mediatek.tvinput%2F.hdmi.HDMIInputService%2FHW5 -n org.droidtv.playtv/.PlayTvActivity -f 0x10000000

HDMI 2

adb shell am start -a android.intent.action.VIEW -d content://android.media.tv/passthrough/com.mediatek.tvinput%2F.hdmi.HDMIInputService%2FHW6 -n org.droidtv.playtv/.PlayTvActivity -f 0x10000000

HDMI 3

adb shell am start -a android.intent.action.VIEW -d content://android.media.tv/passthrough/com.mediatek.tvinput%2F.hdmi.HDMIInputService%2FHW7 -n org.droidtv.playtv/.PlayTvActivity -f 0x10000000

HDMI 4

adb shell am start -a android.intent.action.VIEW -d content://android.media.tv/passthrough/com.mediatek.tvinput%2F.hdmi.HDMIInputService%2FHW8 -n org.droidtv.playtv/.PlayTvActivity -f 0x10000000

ADB commands to find out the intent from diffrent apps:

(what is the command to use to start the app?)

I got a lot of help from people in this thread: https://community.home-assistant.io/t/android-tv-hdmi/234411/28

Use SSH & Web Terminal add-on in Home Assistant with "protection mode" off

alt text

First access the adb container:

docker exec -it addon_a0d7b954_adb /bin/bash

And the run the command:

adb shell pm dump $package | grep -A 1 "MAIN" | grep $package | awk '{print $2}' | grep $package

(Replace $package with the app ID.)

Some pre filled commands for some popular apps

adb shell pm dump org.xbmc.kodi | grep -A 1 "MAIN" | grep org.xbmc.kodi | awk '{print $2}' | grep org.xbmc.kodi

adb shell pm dump tv.twitch.android.app | grep -A 1 "MAIN" | grep tv.twitch.android.app | awk '{print $2}' | grep tv.twitch.android.app

adb shell pm dump se.tv4.tv4playtab | grep -A 1 "MAIN" | grep se.tv4.tv4playtab | awk '{print $2}' | grep se.tv4.tv4playtab

adb shell pm dump se.svt.android.svtplay | grep -A 1 "MAIN" | grep se.svt.android.svtplay | awk '{print $2}' | grep se.svt.android.svtplay

adb shell pm dump com.google.android.youtube.tv | grep -A 1 "MAIN" | grep com.google.android.youtube.tv | awk '{print $2}' | grep com.google.android.youtube.tv

adb shell pm dump com.netflix.ninja | grep -A 1 "MAIN" | grep com.netflix.ninja | awk '{print $2}' | grep com.netflix.ninja

adb shell pm dump se.cmore.bonnier | grep -A 1 "MAIN" | grep se.cmore.bonnier | awk '{print $2}' | grep se.cmore.bonnier

adb shell pm dump com.viaplay.android | grep -A 1 "MAIN" | grep com.viaplay.android | awk '{print $2}' | grep com.viaplay.android


Tested @tboyce1 command on my Shield and this is what i came up with:

(command to list some of the intents thats running on your device)

Source: https://community.home-assistant.io/t/community-hass-io-add-on-adb-android-debug-bridge/96375/23

Use SSH & Web Terminal add-on in Home Assistant with "protection mode" off

alt text

First access the adb container:

docker exec -it addon_a0d7b954_adb /bin/bash

And the run the command:

adb shell
pm list packages | sed -e "s/package://" | while read x; do cmd package resolve-activity --brief $x | tail -n 1 | grep -v "No activity found"; done

And got this:

  • de.blinkt.openvpn/.activities.MainActivity
  • com.plexapp.android/com.plexapp.plex.activities.SplashActivity
  • com.nvidia.tegrazone3/.LaunchActivity
  • com.android.documentsui/.LauncherActivity
  • com.plexapp.mediaserver.smb/com.plexapp.mediaserver.ui.main.MainActivity
  • com.spotify.tv.android/.SpotifyTVActivity
  • com.android.vending/com.google.android.finsky.tvmainactivity.TvMainActivity
  • se.viafree.android/com.viafree.android.SplashActivity
  • com.nvidia.inputviewer/.MainActivity
  • tv.emby.embyatv/.startup.StartupActivity
  • se.tv4.tv4playtab/se.tv4.tv4play.startup.SplashActivity
  • com.android.gallery3d/.app.GalleryActivity
  • tv.twitch.android.app/tv.twitch.android.apps.TVLandingActivity
  • com.nvidia.ota/.ui.LauncherActivity
  • org.xbmc.kodi/.Splash
  • pl.solidexplorer2/pl.solidexplorer.SolidExplorer
  • com.google.android.youtube.tv/com.google.android.apps.youtube.tv.activity.ShellActivity
  • com.joaomgcd.join/.activity.ActivityMain
  • com.google.android.tv.remote.service/.settings.SettingsActivity
  • com.netflix.ninja/.MainActivity

My LoveLace Remote Card

alt text

You find all info and code here https://github.com/mcfrojd/hassio_lovelace_multiremote


Credit to @clapbr

Sharing the method I've been using to use the search function on Shield directly from HA/Lovelace. Works well for a bunch of stuff, including Netflix (search example: "Vikings on Netflix")

configuration.yaml

input_text:
  androidtv_search_input:
    name: Android Search

scripts.yaml

'atvsearchscript':
  alias: Android TV Search
  sequence:
  - data_template:
      command: am start -a "android.search.action.GLOBAL_SEARCH" --es query "{{ states('input_text.androidtv_search_input')}}"
      entity_id: media_player.shield
    service: androidtv.adb_command

Lovelace raw

      - entities:
          - entity: input_text.androidtv_search_input
            type: 'custom:text-input-row'
          - action_name: Search Android TV
            icon: 'mdi:television-classic'
            name: ' '
            service: script.atvsearchscript
            type: call-service

Credit to @JeffLIrion

How to start a Wyze cam RTSP stream in VLC:

"dumpsys power | grep mWakefulness | grep -qv Awake && input keyevent 4; CURRENT_APP=$(dumpsys window windows | grep mCurrentFocus) && CURRENT_APP=${CURRENT_APP#*{* * } && CURRENT_APP=${CURRENT_APP%%/*} && if [ $CURRENT_APP != 'org.videolan.vlc' ]; then monkey -p org.videolan.vlc -c android.intent.category.LAUNCHER 1 && sleep 3; fi; am start -a android.intent.action.VIEW  -d  rtsp://USER:PASSWORD@192.168.0.42/live"

Change the user, password, and IP address in the last part of that command.


@zimmra
Copy link

zimmra commented Jan 17, 2023

Hi! Thanks for this list.. Do you know a adb command for match the framerate?

I’d be interested in this and adb to toggle or enable/disable ‘Night Listening Mode’

@doudigit
Copy link

Hi! Thanks for this list.. Do you know a adb command for match the framerate?

I’d be interested in this and adb to toggle or enable/disable ‘Night Listening Mode’

Try running logcat and while running logcat in the background run match the framerate/ night listening mode action on your tv. Check logcat for logs and search for the activity that happened once you activated the desired action.

@WolfDon757
Copy link

Has anyone found the intents for Disney Plus, Paramount Plus, HBO Max, and Youtube TV

@doudigit
Copy link

Has anyone found the intents for Disney Plus, Paramount Plus, HBO Max, and Youtube TV

As written above

adb shell
pm list packages | sed -e "s/package://" | while read x; do cmd package resolve-activity --brief $x | tail -n 1 | grep -v "No activity found"; done

it will list all the activities needed of all the apps you got

@ronyn77
Copy link

ronyn77 commented Jan 22, 2023

Hello,

I am trying to start the application rayplay using the command "am start -a android.intent.action.VIEW -n it.rainet.androidtv".
But It does not work. It returns an exception.

Exception occurred while executing 'start':
java.lang.IllegalArgumentException: Bad component name: it.rainet.androidtv
	at android.content.Intent.parseCommandArgs(Intent.java:7599)
	at com.android.server.am.ActivityManagerShellCommand.makeIntent(ActivityManagerShellCommand.java:337)
	at com.android.server.am.ActivityManagerShellCommand.runStartActivity(ActivityManagerShellCommand.java:434)
	at com.android.server.am.ActivityManagerShellCommand.onCommand(ActivityManagerShellCommand.java:185)
	at android.os.BasicShellCommandHandler.exec(BasicShellCommandHandler.java:98)
	at android.os.ShellCommand.exec(ShellCommand.java:44)
	at com.android.server.am.ActivityManagerService.onShellCommand(ActivityManagerService.java:10611)
	at android.os.Binder.shellCommand(Binder.java:929)
	at android.os.Binder.onTransact(Binder.java:813)
	at android.app.IActivityManager$Stub.onTransact(IActivityManager.java:5073)
	at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2899)
	at android.os.Binder.execTransactInternal(Binder.java:1159)
	at android.os.Binder.execTransact(Binder.java:1123)

The name of the application is correct because if I start a getproperties command while the app is running it returns the following :

app_name: it.rainet.androidtv
source: it.rainet.androidtv
adb_response: {'screen_on': True, 'awake': True, 'audio_state': 'playing', 'wake_lock_size': 4, 'current_app': 'it.rainet.androidtv', 'media_session_state': 3, 'audio_output_device': 'hdmi', 'is_volume_muted': False, 'volume': 15, 'running_apps':

Any ideas?

@doudigit
Copy link

But It does not work.

Check my reply just above your question. You need to find the activity from that app to be able to run it

@ronyn77
Copy link

ronyn77 commented Jan 22, 2023

Check my reply just above your question. You need to find the activity from that app to be able to run it

Do you mean this : "pm list packages | sed -e "s/package://" | while read x; do cmd package resolve-activity --brief $x | tail -n 1 | grep -v "No activity found"; done" ?

This is the result :

source_list: com.android.systemui, com.google.android.ext.services, com.android.providers.media.module, com.nvidia.blakepairing, com.dolby.android.audio.service, com.nvidia.shieldtech.accessoryui, com.nvidia.shield.remote.server, com.nvidia.osc, com.nvidia.app.messaging, flar2.homebutton, com.anydesk.anydeskandroid, com.nvidia.tegrazone3:PersonalGridService, com.nvidia.tegrazone3:telemetry, com.nvidia.shield.ask, com.google.process.gservices, com.google.android.inputmethod.latin, com.google.android.tv.remote.service, com.google.android.gms.persistent, com.android.providers.tv, com.google.android.gms, Live Channels, ar.tvplayer.tv, Android TV Launcher, it.rainet.androidtv, Google Cast, com.gaditek.purevpnics, com.gaditek.purevpnics:openvpn, com.google.android.permissioncontroller, Play Store, com.nvidia.ota, com.google.android.tvrecommendations, com.google.android.katniss:interactor
volume_level: 1
is_volume_muted: false
app_id: ar.tvplayer.tv
app_name: ar.tvplayer.tv
source: ar.tvplayer.tv
adb_response: com.apkmirror.helper.prod/com.apkmirror.presentation.start.StartActivity
com.plexapp.android/com.plexapp.plex.activities.SplashActivity
android/com.android.internal.app.ResolverActivity
com.nvidia.tegrazone3/com.nvidia.tegrazone.MainActivity
com.android.documentsui/.LauncherActivity
com.lonelycatgames.Xplore/.Browser
com.gaditek.purevpnics/com.purevpn.SplashActivity
com.plexapp.mediaserver.smb/com.plexapp.mediaserver.ui.main.MainActivity
com.android.vending/com.google.android.finsky.tvmainactivity.TvMainActivity
com.tcl.browser/.portal.home.activity.HomePageActivity
ar.tvplayer.tv/.ui.MainActivity
com.nst.iptvsmarterstvbox/.view.activity.SplashActivity
com.google.android.apps.tachyon/.MainActivity
com.nvidia.inputviewer/.AccessorySelectionActivity
com.mytv.stb.emu.tu/com.mvas.stbemu.activities.MainActivity
com.iptvstreamplayer.IPTVStreamPlayer/crc645bc3e740440b3816.MainActivity
com.google.android.youtube.tvmusic/com.google.android.apps.youtube.tvmusic.activity.MainActivity
com.android.gallery3d/.app.GalleryActivity
com.nvidia.ota/.ui.LauncherActivity
com.iqiyi.i18n.tv/.launch.LaunchActivity
flar2.homebutton/a.a
com.anydesk.anydeskandroid/.gui.activity.MainActivity
com.limelight/.PcView
com.google.android.youtube.tv/com.google.android.apps.youtube.tv.activity.ShellActivity
com.google.android.tv.remote.service/.settings.SettingsActivity
com.tvwebbrowser.v22/.MainActivity
com.netflix.ninja/.MainActivity
hdmi_input: null
device_class: tv
entity_picture: /api/media_player_proxy/media_player.nvidia?token=830388f9a03296bc464c1f533f0bc030b2b9b4cfc1cc7609da264b8c8c0dfcf3&cache=1674400958.010054
friendly_name: Nvidia Shield
supported_features: 23997
,,,

For "it.rainet.androidtv", it does not show any activity...

@doudigit
Copy link

For "it.rainet.androidtv", it does not show any activity...

That’s a bit weird. Either way I’ve downloaded the apk of rainet and then uploaded it to decompiler.com where I’ve accessed resources/ android manifest xml where there were a lot of activities you could use ( from launching to directly to music videos movies, but that you’ll need to test on your own)

the activity that seems to launch the app should be
it.rainet.playrai.activity.SplashActivity
If you wish to test out other activities just follow my steps I wrote in this post.

@ronyn77
Copy link

ronyn77 commented Jan 22, 2023

the activity that seems to launch the app should be
it.rainet.playrai.activity.SplashActivity
If you wish to test out other activities just follow my steps I wrote in this post.

Very interesting your suggestion, but I do not know how to "understand" the content of the manifest file...I see a lot of rows, but I cannot interpret them, and I will need to perform a lot of blind tests.

Anyway, awaiting your answer, I found an app called Activity launcher. I installed it on the android device where the apps are running and I found all the activities that I need. I do not know if it is a better solution, but for sure easier. In my case it was "am start -a android.intent.action.VIEW -n it.rainet.androidtv/.ui.MainLeanbackActivity".
Do you know that app?

@doudigit
Copy link

Do you know that app?

I know the app. Easier or not, you managed to solve your problem. The only difference is by reading the manifest file you can see all the possible activities that the app has to offer.

@zimmra
Copy link

zimmra commented Jan 23, 2023

Try running logcat and while running logcat in the background run match the framerate/ night listening mode action on your tv. Check logcat for logs and search for the activity that happened once you activated the desired action.

No specific activity gets listed, just reports back what changes to the settings have happened. appears to maybe be just a script they’re running to enable and disable?

The main/first thing I see is HDMI DRC gets changed to 1 or 0. I assume this is dynamic range compression. 1 being night mode enabled and 0 being disabled.

Following that is a slew of settings that get changed pertaining to sample rate, # of output channels, and available audio formats.

Night mode it (tries) to go to 8000Hz sample rate which throws an error saying the audio output device is not compatible, as well as listing 2 output channels, and stereo as the only enabled format

Regular mode shows 128 channels enabled, and lists all the usual surround formats

What I’m not sure of, is whether simply setting DRC to 1 or 0 causes all of those settings to change on their own, or if their script is changing a plethora of settings

@jdekoven
Copy link

Not sure if this is the right place to post this but I'm looking for people who are doing this stuff with Firestick. I have found that for most apps I don't have to do the adb commands and I can just use the media player source and put in the source that the Firestick displays in Home Assistant when playing. For instance Netflix is simply Netflix.

However, I'm having problems with ITV (now ITVx). Even though it shows the source as air.ITVxMediaPlayer, that does not work. I also got the command line and tried an adb command of:
am start -a android.intent.action.VIEW -n com.candyspace.itvplayer.ui.main.MainActivity , but that doesn't work either. I'm also wondering if like with Netflix how using ADB I can go direct to a certain video, if with BBCiPlayer if I can get to a certain channel.

If anyone is familiar with these issues with Firestick or could direct me to where I could research this more I would appreciate it.

@briodan
Copy link

briodan commented Mar 16, 2023

It would have to be something telling the UI to switch profile... Will keep looking, thanks anyway.

Try running logcat and do the switch profiles. Then check what logcat for clues on what happens in background when you press switch profile. If there’s an activity for it you should be able to find it like that

Did as suggested by @doudigit and identified something that seemed related: ActivityTaskManager: START u0 {cmp=com.google.android.apps.tv.launcherx/.profile.chooser.ProfileChooserActivity (has extras)} from uid 10043

Knowing which profile(s) is/are running with: pm list users

With this, I managed to open the profile chooser: am start -n com.google.android.apps.tv.launcherx/.profile.chooser.ProfileChooserActivity

and then based on which profile is currently running I can use DPAD_LEFT or DPAD_RIGHT and choose the profile I want to switch to.

All of this without "waking up" the TV, as it seems!

Thanks again @doudigit for the precious help and direction

can you explain in a bit more detail or post the code you use that checks the profile and used dpad to select the profile to switch to?

@pplucky
Copy link

pplucky commented Apr 3, 2023

It would have to be something telling the UI to switch profile... Will keep looking, thanks anyway.

Try running logcat and do the switch profiles. Then check what logcat for clues on what happens in background when you press switch profile. If there’s an activity for it you should be able to find it like that

Did as suggested by @doudigit and identified something that seemed related: ActivityTaskManager: START u0 {cmp=com.google.android.apps.tv.launcherx/.profile.chooser.ProfileChooserActivity (has extras)} from uid 10043
Knowing which profile(s) is/are running with: pm list users
With this, I managed to open the profile chooser: am start -n com.google.android.apps.tv.launcherx/.profile.chooser.ProfileChooserActivity
and then based on which profile is currently running I can use DPAD_LEFT or DPAD_RIGHT and choose the profile I want to switch to.
All of this without "waking up" the TV, as it seems!
Thanks again @doudigit for the precious help and direction

can you explain in a bit more detail or post the code you use that checks the profile and used dpad to select the profile to switch to?

Sorry, I completely missed the notification for your question. Better late than never.

I decided to have an Input Select where I store the current profile and can also use it to trigger the profile change (which is actually done via script call). Bare in mind that I have only 2 profiles (Main/Kids) and that my main profile picture is on the leftmost position. Based on that, you may need to adapt below logic to your case.

Possibly not the most optimized solution, but definitely working. Here it is below, let me know if you need any further help.

input_select:
### Input select to allow checking current Profile ###
### and also changing it ###
  chromecast_4k_profile:
    name: CC 4K Profile
    icon: mdi:google
    options:
      - "Main"
      - "Kids"

script:
  chromecast_4k_update_profile:
    alias: "Update Chromecast 4K Profile"
    icon: mdi:google
    sequence:
### String example:
### UserInfo{0:Proprietário:c13} running
### UserInfo{10:configured_user:1010} running
### UserInfo{11:new_user:1010}
      - service: androidtv.adb_command
        target:
          entity_id: media_player.chromecast_4k
        data:
          command: "pm list users | grep UserInfo"
      - delay: 5
      - choose:
          - alias: "Result from ADB command returns the active user to store it in input_select"
            conditions:
              - or:
                  - "{{ state_attr('media_player.chromecast_4k','adb_response')|regex_search('UserInfo{10:configured_user:1010} running', ignorecase=False) == True }}"
                  - "{{ state_attr('media_player.chromecast_4k','adb_response')|regex_search('UserInfo{0:Proprietário:c13} running', ignorecase=False) == True }}"
            sequence:
              - service: input_select.select_option
                target:
                  entity_id: input_select.chromecast_4k_profile
                data:
                  option: >-
                    {% if state_attr('media_player.chromecast_4k','adb_response')|regex_search('UserInfo{10:configured_user:1010} running', ignorecase=False) == True -%}
                      Kids
                    {% elif state_attr('media_player.chromecast_4k','adb_response')|regex_search('UserInfo{0:Proprietário:c13} running', ignorecase=False) == True %}
                      Main
                    {% endif %}

  chromecast_4k_switch_main_to_kids_profile:
    alias: "Switch from Main to Kids Profile"
    icon: mdi:google
    sequence:
      - alias: "Google TV Laucher is the current app"
        condition: state
        entity_id: media_player.chromecast_4k
        attribute: app_id
        state: "com.google.android.apps.tv.launcherx"
      - alias: "Open profile chooser and choose kids' account"
        service: androidtv.adb_command
        target:
          entity_id: media_player.chromecast_4k
        data:
          command: "am start -n com.google.android.apps.tv.launcherx/.profile.chooser.ProfileChooserActivity && sleep 2 && input keyevent DPAD_RIGHT && input keyevent ENTER"
      - delay: 00:00:05
      - alias: "Update Chromecast 4K Profile"
        service: script.chromecast_4k_update_profile

  chromecast_4k_switch_kids_to_main_profile:
    alias: "Switch from Kids to Main Profile"
    icon: mdi:google
    sequence:
      - alias: "Google TV Laucher is the current app"
        condition: state
        entity_id: media_player.chromecast_4k
        attribute: app_id
        state: "com.google.android.apps.tv.launcherx"
      - alias: "Open profile chooser and choose main account"
        service: androidtv.adb_command
        target:
          entity_id: media_player.chromecast_4k
        data:
          command: "am start -n com.google.android.apps.tv.launcherx/.profile.chooser.ProfileChooserActivity && sleep 2 && input keyevent DPAD_LEFT && input keyevent ENTER"
      - delay: 00:00:05
      - alias: "Update Chromecast 4K Profile"
        service: script.chromecast_4k_update_profile

automation:
### Change Chromecast 4K Profile based on input_select option
  - alias: "Chromecast 4K Profile"
    id: chromecast_4k_profile
    trigger:
      - platform: state
        entity_id: input_select.chromecast_4k_profile
        from:
          - "Main"
          - "Kids"
        to:
          - "Main"
          - "Kids"
    condition:
      - alias: "Input select changed by some user"
        condition: template
        value_template: "{{ trigger.to_state.context['user_id'] != none }}"
    action:
      - service: >-
          {% if trigger.to_state.state == "Main"  %}
              script.chromecast_4k_switch_kids_to_main_profile
          {% elif trigger.to_state.state == "Kids"  %}
              script.chromecast_4k_switch_main_to_kids_profile
          {% endif %}

@briodan
Copy link

briodan commented Apr 4, 2023

thanks trying it out however i found that for some reason the enter function does not work to switch to the selected profile.
i dont think this is an issue with script or anything because the TV is doing the same thing when using the remote.

  • if i launch the profile switches from the remote profile button the OK command has no effect and returns to the previous profile
  • if i laucnh the profile switcher by navigating to the top of the screen and selecting the profile swicher the OK command works

not sure if my TV just updated or if there is another issue with it,

@pplucky
Copy link

pplucky commented Apr 4, 2023

input keyevent DPAD_RIGHT && input keyevent ENTER"
- delay: 00:00:05

Insteaf of input keyevent ENTER, try input keyevent DPAD_CENTER, maybe it works better.

Otherwise just do as suggested by @doudigit above and try to see what appears when you are able to switch the profile.

@GRClark
Copy link

GRClark commented Apr 26, 2023

-a android.intent.action.VIEW -d THE-LINK-OF-A-SHOW -f 0x10808000
After any main activity of an app that supports opening a link to watch something, will launch the show or a movie. This same logic can be used for YouTube, AmazonPrime, Hulu, Disney+, HBO etc

Do you have an example how to search and play a YouTube video? Tried this and didn’t work.

am start -n com.google.android.youtube.tv/.MainActivity -a android.intent.action.VIEW -d https://youtu.be/i9HokGpj-kE -f 0x10808000

Also curious if there’s a way to add a delay between key events?

@evnvc
Copy link

evnvc commented May 4, 2023

I've went to the trouble of searching the activity on decompiler.com and this is what I found for HBO Max
com.hbo.hbonow/com.hbo.max.HboMaxActivity

@GinAndBacon
Copy link

Not sure if this is the right place to post but after the may core update the ADB add on connects to my Sony TV running Android TV but all ADB commands have stopped working. ADB add on logs show it connects fine but nothing works and under devices it shows as not connected even though the ADB add on say's it is. I know the add on is deprecated but it was working fine up until the last core update. After the update it rediscovered my Sony TV as an Android TV device using the native integration but ADB commands don't work. I'm assuming it's trying to use the built in python implementation but for some reason it doesn't work.

I'm just wondering if anyone else is having this issue if they have done the latest monthly core update for May or not. Probably need to hook my Nvidia Shield up to see if it's an issue there but I have a feeling it will just be rediscovered as a new android TV device similar to my Sony TV. Considering the ADB add on has been deprecated for over a year it's probably update related but wanted to try and verify. Surprised the add on lasted this long anyways but I was under the assumption the Python ADB server had been added to Home Assistant and the add on was no longer needed but since it worked I never tried to change anything. Odd thing is iHA won't restore to a full backup done before the core update

@evnvc
Copy link

evnvc commented May 4, 2023

I have a Samsung TV with a Chromecast w Gtv attached to it, and it still works for me. I did however have to reauthorize USB debugging after the core update. Commands work fine, bar the Netflix app launch

@GinAndBacon
Copy link

GinAndBacon commented May 6, 2023

Well, I have tried removing and adding the device by de authorizing devices on my Sony TV and deleting the keys from the HA directory they are stored it allows me to add the integration but then fails to actually run. Kind of odd. One question, are you using the python implementation or are you running the ADB server add on still as that is what I was using? Regardless after reading up more on the Android TV remote integration added in the latest update I'm probably going to just move to do that as it appears to allow you to do most of what ADB does although based on their examples I'm unsure about some more obscure apps because it uses URL's instead of ADB commands but need to mess around with it first. Just odd that the ADB server connects but get the error below everytime I add the AndroidTV device. Especially since it adds the keys back once I authorize it.

File "/usr/src/homeassistant/homeassistant/config_entries.py", line 387, in async_setup
result = await component.async_setup_entry(hass, self)
File "/config/custom_components/androidtv/init.py", line 162, in async_setup_entry
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
AttributeError: 'ConfigEntries' object has no attribute 'async_setup_platforms'

EDIT: confirmed and works just as fast as ADB. Just posting this in case anyone else runs into this issue because of the ADB server add on being deprecated and it works in essentially the same way using the below script.

alias: Sony YouTube
sequence:
service: remote.turn_on
data:
activity: https://www.youtube.com
target:
entity_id: remote.bedroom_tv
mode: single

LAST EDIT: So, at some point I think I had manually tried to setup the python implementation. I noticed that folder referenced above under custom_components had a date of January 2022 which I believe is right around the time ADB Server was deprecated and removed from add ons. That folder was messing everything up. I honestly think that is the only reason it was there because I can't think of any other reason it should exist as I noticed it was not being deleted when I deleted the AndroidTV instance from devices. Removed that folder, rebooted and everything works now so huge user error on my end but leaving this up in case anyone else runs into something stupid like this. There is no folder created under custom_components when adding the AndroidTV device when using the deprecated ADB Server add on so that was messing everything up. Not sure why this core update broke everything but it shouldn't exist anyways and all is working as it was which is good because the remote integration isn't nearly as powerful as ADB granted it was just introduced.

@kaijk
Copy link

kaijk commented May 26, 2023

Is there a new Intent now for MAX to replace hbonow? My HBO intent has stopped working. I see the com.hbo.hbonow intent is still there, and which has been working, but it now returns:

$ cmd package resolve-activity  com.hbo.hbonow
No activity found

even when I have the new MAX app running and am logged into it

@GinAndBacon
Copy link

Is there a new Intent now for MAX to replace hbonow? My HBO intent has stopped working. I see the com.hbo.hbonow intent is still there, and which has been working, but it now returns:

$ cmd package resolve-activity  com.hbo.hbonow
No activity found

even when I have the new MAX app running and am logged into it

Have you tried using the Android Debug Bridge: Learn sendevent service under development tools? Super useful for finding the commands for more obscure apps. Go to dev tools then services and choose the service above and Android device in UI mode. Call the service and hit the button to launch the app. If there isn't a dedicated hardware button download button mapper as it allows you to reassign apps to hardware keys on any Android remote. After that you will get a notification with the ADB command used to launch the app. You may have to side load the button mapper APK. I don't remember if it's in the Android TV store or not.

@kaijk
Copy link

kaijk commented May 26, 2023

I connected directly to my firestick with adb tools and listed all the packages, not even just 3rd party ones. The only one that looks even close is com.hbo.hbonow, the one I've been using prior to the HBO-MAX > MAX changeover this week. This intent no longer works, but the intent is still there in the firestick
"am start -a android.intent.action.VIEW -n com.hbo.hbonow/com.hbo.max.HboMaxActivity"

@GinAndBacon
Copy link

Do you see anything close to the name "com.wbd.stream" in the list, I just installed it as I never had it installed and when looking in the Android>Data folder in Solid Explorer that's the name of the folder it was installed in, it's the part after that I can't figure out as it always starts with that name. For example Plex is named com.plexapp.android in that folder and Kodi is org.xmbc.kodi. it's always the part after the / that's different and I just tried and the learnsendevent service and it still outputs a notification but it no longer works as documented so I guess that got broken somewhere along the way and those commands were always much longer anyways.

Hopefully there is something close to that name in the list If you pulled from your FireTV because the part after the / is usually the tricky part, especially now that the learnsendevent service notification doesn't work anymore. I'm also wondering how they did the switchover and if they created a new folder or installed it under the same one. Might be worth looking in the Android> Data folder with a file browser to see if there is a com.wbd.stream" folder now. At least that's what it's named on my Sony Android TV and those folder names are typically universal between devices.

@GinAndBacon
Copy link

GinAndBacon commented May 26, 2023

I connected directly to my firestick with adb tools and listed all the packages, not even just 3rd party ones. The only one that looks even close is com.hbo.hbonow, the one I've been using prior to the HBO-MAX > MAX changeover this week. This intent no longer works, but the intent is still there in the firestick am start -a android.intent.action.VIEW -n com.hbo.hbonow/com.hbo.max.HboMaxActivity

Figured it out. Came across an older thread on the HA forums. I knew there was an easier way of doing this, just had been a while. If you are running Windows install the WSL or if you are running Linux then you are obviously good to go. Install ADB sudo apt install adb then connect to the device via IP adb connect 192.168.0.xx:5555 after that run the below, replacing the package name with the one in the android/data folder. You will get a prompt on the Android device so you have to confirm to connect if you haven't already done so from your PC. Sorry if I am repeating some stuff you have already done, just wanted to be document all steps taken. ADB in Windows won't work because it can't do grep (at least that I am aware of) so Windows Subsystem for Linux is needed in order to run the below commands to get the intent.

Kodi (obviously documented already but was a copy/paste from the link above
me@R2D2:/usr$ adb shell pm dump org.xbmc.kodi | grep -A 1 "MAIN" | grep org.xbmc.kodi | awk '{print $2}' | grep org.xbmc.kodi

org.xbmc.kodi/.Splash

After that I simply changed the name to com.wbd.stream which is the name in the Android/data folder and it immediately launched
me@R2D2:/usr$ adb shell pm dump com.wbd.stream | grep -A 1 "MAIN" | grep com.wbd.stream | awk '{print $2}' | grep com.wbd.stream

com.wbd.stream/com.wbd.beam.BeamActivity

So created a script with the above as the intent command and it launched instantly. Thought I would post the details in case it comes in handy for future use if other apps change names or just need to find a particular one that isn't documented already. Just replace the name with whatever is in the Android/data folder to whatever app it is you want to find the intent to.

am start -a android.intent.action.VIEW -n com.wbd.stream/com.wbd.beam.BeamActivity

@kaijk
Copy link

kaijk commented May 27, 2023

Thank you! I'll check out "wbd" when I get a bit of alone time with the firestick.

I don't recall seeing wbd in any listings I've produced, though. Thanks for the thought to install adb on my linux box.

I have android studio installed on windows for just this purpose so I have adb tools there. I run adb connect <ip of firestick> from a windows command prompt after disconnecting HA from the firestick. Then, running adb shell gets a command prompt on the firestick. pm and other commands are now available in the firestick shell. Just have to remember to do an adb disconnect or HA can't reconnect to the device.

@kaijk
Copy link

kaijk commented May 28, 2023

I've got the new MAX intent working -

After disconnecting HA, connecting to the FIreStick with adb connect <IP address> and getting a Shell in the device adb shell, I ran the following:

pm dump com.hbo.hbonow | grep wbd

Among a bunch of other stuff was this:

intent={act=android.intent.action.MAIN cat=[android.intent.category.LEANBACK_LAUNCHER] flg=0x10000000 pkg=com.hbo.hbonow cmp=com.hbo.hbonow/com.wbd.beam.BeamActivity}

Now, this opens MAX for me in HA:

"am start -a android.intent.action.VIEW -n com.hbo.hbonow/com.wbd.beam.BeamActivity"

Interesting how WBD mixed the two bits together to create the new intent.

Note, run adb disconnect before trying to reconnect HA to the device.

@GinAndBacon
Copy link

I'm speculating it was because you more than likely did an update and I did a new install as that the folder in Android/data was named com.wbd.stream when I did a new install. If you already had it installed it may have not changed the folder name in that directory and just updated the files in that folder but that's just speculation by me as the first part always matches up with the folder name in that directory (at least for me it does on my Sony Android TV). You could check with a file explorer and see if the folder is still named com.hbo.hbonow but if it's working it's working and that's all that matters. Might be worth remembering if you ever do a new install on another Android device and the above doesn't work for the new install (if that even ever happens).

@AfonsoFGarcia
Copy link

Working intents for switching HDMI inputs on 2023 Philips TVs (tested on OLED818):

HDMI1:

adb shell am start -a android.intent.action.VIEW -d content://android.media.tv/passthrough/com.mediatek.tis%2F.HdmiInputService%2FHW2 -n org.droidtv.playtv/.PlayTvActivity -f 0x10000000

HDMI2:

adb shell am start -a android.intent.action.VIEW -d content://android.media.tv/passthrough/com.mediatek.tis%2F.HdmiInputService%2FHW3 -n org.droidtv.playtv/.PlayTvActivity -f 0x10000000

HDMI3:

adb shell am start -a android.intent.action.VIEW -d content://android.media.tv/passthrough/com.mediatek.tis%2F.HdmiInputService%2FHW4 -n org.droidtv.playtv/.PlayTvActivity -f 0x10000000

HDMI4:

adb shell am start -a android.intent.action.VIEW -d content://android.media.tv/passthrough/com.mediatek.tis%2F.HdmiInputService%2FHW5 -n org.droidtv.playtv/.PlayTvActivity -f 0x10000000

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment