Home Assistant Community Add-on: ADB - Android Debug Bridge

OK so I took the service image example on github and under developer tools tested it out with my NVidia Shield.

Put in androidtv.adb_command for the service

Put in media_player.family_room_nvidia_shield for the entity

For Service Data put in the whole block: {“entity_id” :“media_player.shield”, “command”: “am start -a android.intent.action.VIEW -d -n com.google.android.youtube.tv/com.google.android.apps.youtube.tv.activity.ShellActivity”}

Sure enough my NVidia Shield Pro TV changed to YouTube.

Trying to duplicate that in my Lovelace code.

So when I do:

                tap_action:
                  action: call-service
                  service: androidtv.adb_command
                  service_data:
                    command: 'am start -a android.intent.action.VIEW -d -n com.google.android.youtube.tv/com.google.android.apps.youtube.tv.activity.ShellActivity'

OR even the full intent with the entity_id and all if that’s the right term it keeps telling me data missing.

Thoughts?

JR

You are missing the “entity_id:”

tap_action:
  action: call-service
  service: androidtv.adb_command
  service_data:
    entity_id: media_player.shield
    command: "am start -a android.intent.action.VIEW -d -n com.google.android.youtube.tv/com.google.android.apps.youtube.tv.activity.ShellActivity"

Cool thanks. I think I had it and failed to copy it right into the forum or this was my 50th attempt to format it to work but working now so thank you.

For intents like this:

{ “entity_id”: “media_player.android_mibox”, “intent”: “-n com.plexapp.android/com.plexapp.plex.activities.SplashActivity” }

How do you determine the com.plexapp.android part which I guess is the app bundle, but more specifically the com.plexapp.plex part? So right now I am looking at the ABC and NBC apps and don’t see those anywhere so going to try and figure them out but looking at things not always sure how the SplashActivity part gets figured out.

I can’t remember exactly what I did, but I can remember that I figured out how to find that out with help from info on this page

I think it involved downloading an adb tool on my PC and connecting to the shield to run the commands listed on the page above.

https://developer.android.com/studio/command-line/adb

So here’s an example I put together but not sure if it’s valid yet, making dinner so not in the mood to verify until after.

adb shell pm dump com.google.android.youtube.tv > save.txt
Or whatever the bundle is and save to file
am start -a android.intent.action.VIEW -d -n com.google.android.youtube.tv / com.google.android.apps.youtube.tv.activity.ShellActivity```

Not sure if that will work but what I got so far.
1 Like

Ive been trying to get this to work.

I had to get a new SD card for my pi, and I figured I would do this from scratch- knowing that it is possible to throw on one of my snapshots. That said, I set up the ADB on HA, I included the IPs for the 2 Shields I wanted to use, on one ( the most pressing one) I accepted the connection on the Shield, and of course put them in my config.

Any help, or advice would be helpful. THANK YOU.

The configuration. yaml looks like:

Copy to clipboard

media_player:
  - platform: androidtv
    host: 192.168.86.57
    name: "Second NVidia Shield"
    adb_server_ip: 127.0.0.1
    adb_server_port: 5037
  - platform: androidtv
    host: 192.168.86.56
    name: "Livingroom NVidia Shield"
    adb_server_ip: 127.0.0.1
    adb_server_port: 5037

The Config in the add-on ADB looks like:

Copy to clipboard

devices:
  - 192.168.8x.5x
  - 192.168.8x.5x
reconnect_timeout: 90

The log for the ADB, insists that it is connected to the devices:

Copy to clipboard

[cont-init.d] 00-banner.sh: exited 0.
[cont-init.d] 01-log-level.sh: executing... 
[cont-init.d] 01-log-level.sh: exited 0.
[cont-init.d] adb.sh: executing... 
[cont-init.d] adb.sh: exited 0.
[cont-init.d] done.
[services.d] starting services
[services.d] done.
[22:41:13] INFO: Starting the Android Debug Bridge server...
[22:41:14] INFO: Connecting to device: 192.168.86.57...
connected to 192.168.86.57:5555
[22:41:14] INFO: Connecting to device: 192.168.86.56...
connected to 192.168.86.56:5555
[22:42:44] INFO: Connecting to device: 192.168.86.57...
already connected to 192.168.86.57:5555
[22:42:44] INFO: Connecting to device: 192.168.86.56...
already connected to 192.168.86.56:5555
[22:44:15] INFO: Connecting to device: 192.168.86.57...
already connected to 192.168.86.57:5555
[22:44:15] INFO: Connecting to device: 192.168.86.56...
already connected to 192.168.86.56:5555
[22:45:45] INFO: Connecting to device: 192.168.86.57...
already connected to 192.168.86.57:5555
[22:45:45] INFO: Connecting to device: 192.168.86.56...
already connected to 192.168.86.56:5555
[22:47:16] INFO: Connecting to device: 192.168.86.57...
already connected to 192.168.86.57:5555
[22:47:16] INFO: Connecting to device: 192.168.86.56...
already connected to 192.168.86.56:5555
[22:48:46] INFO: Connecting to device: 192.168.86.57...
already connected to 192.168.86.57:5555
[22:48:46] INFO: Connecting to device: 192.168.86.56...
already connected to 192.168.86.56:5555
[22:50:17] INFO: Connecting to device: 192.168.86.57...
already connected to 192.168.86.57:5555
[22:50:17] INFO: Connecting to device: 192.168.86.56...
already connected to 192.168.86.56:5555
[22:51:47] INFO: Connecting to device: 192.168.86.57...
already connected to 192.168.86.57:5555
[22:51:47] INFO: Connecting to device: 192.168.86.56...
already connected to 192.168.86.56:5555
[22:53:17] INFO: Connecting to device: 192.168.86.57...
already connected to 192.168.86.57:5555
[22:53:18] INFO: Connecting to device: 192.168.86.56...
already connected to 192.168.86.56:5555
[22:54:48] INFO: Connecting to device: 192.168.86.57...
already connected to 192.168.86.57:5555
[22:54:50] INFO: Connecting to device: 192.168.86.56...
already connected to 192.168.86.56:5555
[22:56:21] INFO: Connecting to device: 192.168.86.57...
already connected to 192.168.86.57:5555
[22:56:21] INFO: Connecting to device: 192.168.86.56...
already connected to 192.168.86.56:5555
[22:57:51] INFO: Connecting to device: 192.168.86.57...
already connected to 192.168.86.57:5555
[22:57:53] INFO: Connecting to device: 192.168.86.56...
already connected to 192.168.86.56:5555

And these are the errors I get:

Copy to clipboard

Log Details (WARNING)
Logger: homeassistant.components.media_player
Source: helpers/entity_platform.py:202
Integration: Media player (documentation, issues)
First occurred: 10:42:44 PM (6 occurrences)
Last logged: 10:52:50 PM

Platform androidtv not ready yet. Retrying in 60 seconds.
Platform androidtv not ready yet. Retrying in 90 seconds.
Platform androidtv not ready yet. Retrying in 120 seconds.
Platform androidtv not ready yet. Retrying in 150 seconds.
Platform androidtv not ready yet. Retrying in 180 seconds.

Copy to clipboard

Log Details (ERROR)
Logger: androidtv.adb_manager
Source: components/androidtv/media_player.py:218
First occurred: 10:42:13 PM (7 occurrences)
Last logged: 10:52:50 PM

ADB device is unavailable; encountered an error when searching for device.

Copy to clipboard

Log Details (ERROR)
Logger: homeassistant.components.media_player
Source: components/androidtv/media_player.py:215
Integration: Media player (documentation, issues)
First occurred: 10:42:13 PM (1 occurrences)
Last logged: 10:42:13 PM

Error while setting up androidtv platform for media_player
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 178, in _async_setup_platform
    await asyncio.wait_for(asyncio.shield(task), SLOW_SETUP_MAX_WAIT)
  File "/usr/local/lib/python3.7/asyncio/tasks.py", line 442, in wait_for
    return fut.result()
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/androidtv/media_player.py", line 215, in setup_platform
    state_detection_rules=config[CONF_STATE_DETECTION_RULES],
  File "/usr/local/lib/python3.7/site-packages/androidtv/__init__.py", line 52, in setup
    aftv = BaseTV(host, port, adbkey, adb_server_ip, adb_server_port, state_detection_rules, auth_timeout_s)
  File "/usr/local/lib/python3.7/site-packages/androidtv/basetv.py", line 100, in __init__
    self.device_properties = self.get_device_properties()
  File "/usr/local/lib/python3.7/site-packages/androidtv/basetv.py", line 206, in get_device_properties
    constants.CMD_MAC_ETH0)
  File "/usr/local/lib/python3.7/site-packages/androidtv/adb_manager.py", line 435, in shell
    return self._adb_device.shell(cmd)

I am having the same exact issue as lawsuitup. One day the shield and adb was all working, now there is the error setting the media player, yet the adb_server add-on says it is connected to the shield.

Unfortunately, I do not know when this broke, so I do not know if it was after an ADB add-on update, HA update or a shield firmware update.

I too am having the same issues as Lawsuitup… Saw his post here and a similar note on reddit. Similar config, same symptoms, same error. Tried multiple restarts and orders of setup/restarts.

I initially had this working (old version) but lost it with a SD card failure. After a fresh install, seeing the issues above.

Important Note: I can get this working when I only implement a single AndroidTV. But upon implementing a second AndroidTV I see the failures.

@lawsuitup - Can you try to update your config to only include a single AndroidTV? Does that fix it?

Similarly, you can see here (Late January), someone had a similar issue (on a supervised docker implementation).

@lawsuitup @asubpargamer @rzarobbie

Stop using the add-on, the Python ADB implementation should work just fine.

  1. Stop the add-on
  2. Remove adb_server_ip from your config
  3. Restart the device
  4. Restart HA
  5. Click the check box on the TV and approve connections from this device
1 Like

I had to reauthorize the second tv. Without the second tv, it would not set up either one.

Thank you for this answer. I finally got this to work… well kind of. I have 3 Fire TV 4K’s, 1 connected to a Sony and the other 2 are on LG TV’s. When I call the SLEEP service only the one (the Sony) executes the command but the other 2 do not. Do you have any idea why this is happening?

Do basic controls work for all 3? For example, turning the power on/off via the media player card in the UI (Lovelace). If that works then it’s probably an issue with your service call.

Basic controls don’t work either. For example when I watch something on the LG TV the media card will show the play button (instead of the pause button because it is already playing). When I use the Sony it shows a pause button which when I press, pauses it as one would expect.

Sounds to me like a problem with your TVs, not with the Android devices. Nevertheless, you should tell us, which devices are connected with what? Do you have six devices to control via ADB or just four? As far as I know, LGs mostly use WebOS and not Android.

The “sleep” issue sounds like a miscommunication between your LG TVs and the FireTVs. I’d suspect a setting regarding “HDMI-CEC”.

Please give us a little more information about your setup. Which TVs and FireTV sticks (I assume sticks, or are you really running an Amazon FireTV behind another TV?) are setup in which way in HA / ADB.

I have 3 TV’s which each have a Fire TV 4k stick. All 3 sticks are the same model and have the same software on them. One TV is a Sony and the other 2 are LG’s. The LG’s are connected to HA via WebOS and the Sony is connected via the Bravia integration. My only reason for this really is just so HA knows whether they are off/on. The over arching reason for getting the androidtv working is because I use the Fire TV Recast which only allows 2 live OTA TV streams simultaneously and the stream is not turned off just because you turn off a TV. So when I go to the 3rd TV(the other 2 had been previously streaming) it says I need to stop one of the other streams first. I’d like to make it so when a TV is turned off it puts the Fire TV to sleep which stops it from streaming. I have this automation currently working with the Sony TV as the androidtv is working on the Fire TV connected to that one.

So, you have four Android devices (1x SonyTV and 3x FireTV sticks) and two WebOS devices (LG TVs).

There are a few possibilities, to achieve what you want. But beforehand I have to ask, how do you send your commands? Especially to the WebOS devices? Or do you not send a command?

Nevertheless, I’d advice to check the settings in your WebOS TVs, as these are the ones that don’t work as expected, aren’t they? There is a setting that is called “HDMI-CEC”. With this setting, connected devices are able to talk to another. If one of them is going to power safe or sleep mode, it tells this to other connected devices and they shut off as well. There you need to send the signal only to one device (TV or stick doesn’t matter).

If you want to be safe, you need to make sure, all devices get there sleep signal. To make use of this, you can write an automation,

action:
  - data:
      entity_id: media_player.magentatv_stick
    service: media_player.turn_off
  - delay: 00:00:05
  - data:
      entity_id: media_player.sony_bravia_tv
    service: media_player.turn_off

or you use the Universal Media Player component, where you can put specific devices together in one card: https://www.home-assistant.io/integrations/universal/

Last but not least, are you sure, this is the correct thread? If I get it right, your four android devices work like they should, only the WebOS devices don’t… Then you should ask in the WebOS component thread, maybe someone there had this problem already. Don’t get me wrong, but till now, I haven’t seen anything, that would led to something wrong with the ADB bridge… :slight_smile:

Thank you for your assistant. The problem ended up being what you suspected - the HDMI-CEC setting was turned off. LG calls it SIMPLINK. FWIW the automation I’m using is:

- alias: Office Fire TV Sleep Mode When TV Shuts Off
  initial_state: true
  trigger:
    platform: state
    entity_id: media_player.office_tv
    to: 'off'
  action:
    service: androidtv.adb_command
    data:
      entity_id: media_player.office_fire_tv_2
      command: "SLEEP" 

This way the OTA stream will always be available unless all 3 TV’s are on at the same time which never happens in a household of 2. Thanks again.

I thought it could be useful for someone:

### Show local video with KODI 
{"entity_id" :"media_player.fire_tv_camera", "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.fire_tv_camera", "command": "am start -a android.intent.action.VIEW -d rtsp://user:[email protected]:XXX/Streaming/Channels/301 -n org.videolan.vlc/.gui.video.VideoPlayerActivity"}


4 Likes

Ok if i add these to my Shield_Intents gist?