Generic Android Box/Stick/TV Component - Need Testers & Help With Fixing Current Issues

I started working on improvements and changes to this component, which development has stalled on.

My goal is to make this component work for ALL Android Boxes/Sticks/TV, both “official” (shield & tv’s running the android os) and “generic” (sticks & boxes running a modified android phone os) devices.

Thus far, @JeffLIrion has been a HUGE help in helping this project suceed to the point that it’s currently at. They graciously took it upon themself to modify their fire-tv module to create the androidtv module, which I’ve further modified to get to the point we’re at.

Now I’ve gotten to the point where I need help.

First, the device I’ve been testing on:
(Generic Android Box, running a modified android phone os like most chinese android boxes & sticks)
Device: T95V Pro Android Box
Specs: Android 6.0 Amlogic S912 Octa Core Processor, 2GB RAM, 16GB Storage

So far here’s what I’ve accomplished with the files I’ll link to at the bottom of the post.

  • State detection seems to be pretty accurate
    • When on homescreen or in settings state is listed as “On” on the UI media card
    • When in an app, but nothing has been selected, state is listed as “Idle” and if it’s one of the recognized apps that will also be stated on the UI media card
    • When inside the app & playing, state is listed as “Playing”, and if it’s one of the recognized apps that will also be stated on the UI media card
    • When inside the app & playback is paused, state is listed as “Paused”, and if it’s one of the recognized apps that will also be stated on the UI media card
  • Half of the Buttons in the UI work (for me on the generic android box)
    • I can Pause from the UI media card
    • I can use the Power button from the UI media card
    • I can use the Mute/Unmute from the UI media card
  • :warning: Current Issues :warning:
    • The Play button does not make playback continue when it’s been paused (regardless if it was paused from the UI or by the remote)
    • The Fast Forward button does not work
    • The Rewind button does not work
    • There are a bunch of warnings in the logs pertaining to the adb commands stating “data_length xxx does not match actual number of bytes read: xxx”
    • :warning: Component will out of nowhere switch to state UNKNOWN
      • Happens after trying to press one of the above mentioned buttons that don’t function correctly twice in a row
      • Happens randomly after some time for some unknown reason

All buttons seem to work for people using Shields or “official” Android TVs running the android tv os, but the eventual component going unresponsive and state switching to a permanent UNKNOWN appears to be universal.

To help me test and/or fix things you can install the component using the following steps:

  1. Download my latest version of the Custom Component (save in the path: config/custom_components/media_player/

  2. Add the config values to your configuration.yaml

  - platform: androidtv
    host: localipofyourdevice
    name: GiveItAName
    #adbkey is only needed for newer android OSes (after kitkat I believe)
    adbkey: "Path to your public & private adbkey"
  1. (If Needed) If your device’s OS is newer than kitkat (so 5.0 & on) you will likely need to first connect to the device outside of HA via command line using adb in order to generate the adbkey file.
    Instructions are mostly similar to those found here. Of course, you’ll need to pip install adb (and maybe pip install python-adb) if your os doesn’t by default include the adb module.

  2. Once all that is out of the way and the config is saved, restart Home Assistant

  3. Lastly, and this is important, you need to locate your deps folder (location varies depending on os) and find the newly installed androidtv folder. In that folder is an file. Replace that file with the one from the following link.

    Modified Module (replace the in the path: /deps/androidtv/

  4. Finally, restart Home Assistant once more and the component should work as I’ve described.

I’m hoping that someone will be willing to help fix the issues I’ve been dealing with. And it would also be a great help if people could test this component on their “generic” devices and report their findings. To do so, please add your comments on this issue following the template laid out in the Issue body. For those that would like to help me in fixing the current issues, please feel free to fork the branches I’ve linked & submit PRs back to them.

On my Shield, everything works fine for 5 minutes after restarting HA and then it goes to unknown and stays there. In the logs, I see

Failed to execute an ADB command; will attempt to re-establish the ADB connection in the next update

It looks like it is not recovering from that adb connection issue.

Ah, nice to see that the component hasn’t been abandoned.

I’m still using the a1ex4 component and I’m quite happy with it now that I have my ‘adb connect’ automation that starts the connection. It works most of the time, I had a couple of failures that could be explained by a network charge.
I don’t have an heavy use of this, I just deal with volume most of the time.

I’m of course willing to test your dev.

I’d just like to understand what is the point 5 needed for ? What happens if I just replace the (working) custom component with yours ? Is that because the adb connection doesn’t initiate by itself ?

A lot has been changing with the project recently. I’ve been very busy working on improvements and additions. I would suggest if you don’t want to ruin any of your setup right now that you test it on a dev install on a different device (like if you have a spare pi laying around). The difference between my and a1ex4’s versions is large as it stands now. A few things to note:

  • Component (and module) are being built to completely leverage async, meaning faster platform loading for one thing.
  • I’ve added the ability to Play Media, essentially allowing the device to imitate a chromecast. Example: You could create an automation that would “cast” your security camera’s feed to your android box (connected to your bedroom tv) if motion is detected in the middle of the night. That way you can immediately see what’s going on.
  • General efficiency improvements and better coding practices.

If you do in fact have a separate device that you’d like to test on I could add you to a group chat on discord where we go over changes and report issues.

I don’t have a spare device, I run HA in a VM, Ubuntu OS. Along with network services (zoneminder, cups, caldav…)
But anyway, I’ll try it and let you know. It’s easy to revert if needed.

I could make it work, placed the file in custom_component/media_player in place of the previous one.
Using Ubuntu and a venv, I struggled to find the “deps” folder. I have one in the homeassistant user home directory, but it’s empty.
Should look in : /usr/homeassistant/lib/python3.6/site-packages/androidtv
Still don’t know what’s the purpose of this ? The underlaying library has incompatibilities ? Likely to be erased on next update ?

At first try, I found out why I needed to make the scripted ‘adb connect’ with previous component. It failed silently trying to find adbkey files. Though they were in $home/.android, it didn’t use them.
Your version shows the error in the log, I added the adbkey section pointing to that default directory. Don’t understand why it doesn’t find those as it runs as homeassistant user ?

There’s one major difference now, that if the box ain’t available when HA starts, you won’t try to connect regularly, so when I turn on the box, it won’t show. I think you should retry every X minutes.

When I restarted HA, Netflix was playing, it lead me to the home screen when the box was detected. Other than that, I saw no difference until now.

I use a Nexbox a95x, 2GB/8GB running stock Android 6.

  • The underlying library is completely different & relies on different dependencies itself.
  • Providing the adbkey path in the configuration.yaml can take a few tries. I found it easiest to place the adbkey files within the homeassistant folder alongside the configuration.yaml file or (if you plan on having multiple entities using the platform) creating a folder within that directory and naming it something like android and adding an inner folder (one for each device) for easier management of all your keys. You may also need to add single or double quotes around the path.
  • About being taken to the Homescreen on start-up, that’s a temporary behavior in the testing version. When released this will only happen the first time after installing the component. The reason: This dynamically gathers the settings & launcher package name. This way, if a user doesn’t have the official android tv launcher (which is hard-coded in a1ex4’s version) the component will still be able to accurately detect the states (as ON if you’re sitting on the homescreen or in settings, IDLE while in an app, etc).
  • If the component cannot connect to the device, it will continue to try reconnecting each update (just as chromecast or any other media component). Also, you may not be using the right version as there are a few branches in both the component and dependency, so it’s best to join the discord group to know which versions should be used for testing currently as it’s constantly changing as I aggressively continue developing. I’ve been at it pretty heavily over the last week.

Honestly, at this point in development you’re best not comparing the two versions as a1ex4’s version will soon be obsolete when this version is complete & a PR will be submitted to the HA repo. Partial credit will obviously be given to them for starting the project/providing some framework.

Oh, and once “officially” released you won’t need to do all the replacing of the deps (if that wasn’t obvious).

Great work! When done, will this be able to be used on hassio as well?

Thanks! Umm, good question. The real answer is I’m not sure as I chose not to run hassio (I went hassbian for my first install). However, I don’t see why it wouldn’t be install-able on hassio. The only caveat will be the initial needing to connect to the android device from a different device to obtain the adbkey files, then transferring them to your hassio server. It’s not hard, but some may see it as a hassle. Hopefully the write-up I provide on the component’s page will be easy enough for everyone :slight_smile:

Are you interested in helping test? If so, you can find me on discord with the same user name and I’ll add you to the small group I have now. Still working out a few small kinks before cleaning things up and starting to run the format tests (pip8, TravisCI, etc) that are needed in order to get a PR accepted.

1 Like

Sure, but the fun is before official release :wink:

I’ll try to come to discord soon…

EDIT : either I didn’t understand, or I miss an information to add you in discord : your tag number ? I have the same user name, #4409.

Couldn’t find you. I’m CaffeinatedMike#6374

Could really use some help figuring out an issue that seems exclusive to high-end devices (nvidia shield, which I don’t have to test on). I have the latest version working (branch async-hell-fix) perfectly for me on my chinese Android box.