Native support for Android TV / Android devices

I use this, the top service “input keyevent 224” is a wakeup command to turn off the screensaver, otherwise you can switch inputs but the screensaver stayed active

   - service: androidtv.adb_command
     data:
       entity_id: media_player.fire_tv
       command: "input keyevent 224"
   - service: androidtv.adb_command
     data:
       entity_id: media_player.fire_tv
       command: "HDMI3"

full list of commands here:

https://developer.android.com/reference/android/view/KeyEvent#KEYCODE_TV_INPUT_HDMI_2

1 Like

Thanks for the quick reply. I’m nearly positive that’s the service/command I tried, but it doesn’t work. I’ll double check shortly.

*Ok, so I think the issue is how the FireTV Stick is controlling inputs (Equipment Control?). Switching inputs via the controller/voice does use IR. But, the FireTV Stick definitely can switch inputs when I press the home button, for example. Just haven’t found a way to switch to an alternate input via the FireTV Stick CEC … so maybe it’s only a one-way function based on a CEC wake-up rather than direct input command? Any suggestions re: a setting I need to change on the FireTV Stick?

I have a Mibox S with an Ethernet to USB adapter connected to the USB port. As the device has no native UTP port am I correct to assume this addon will never work? Or would it work if I used Wifi?

It’ll work if you use wifi. Myself and a couple others have asked about the usb Ethernet adapter, but there don’t seem to be any answers.

Thanks! (searching unfortunately didn’t turn up any definitive answers)

Maybe it’s the same as with philips TVs. With the Philips TVs you first need to connect via Wifi to generate the necessary keys (I think an SSH key, but not sure). Afterwards it is possible to use Wifi or Ethernet, but for the first connection Wifi is mandatory.

Have you tried this? :slight_smile: I have no idea, but it’s worth a try, don’t you think? :slight_smile:

1 Like

Will give that a go, thanks

Hi all,
Are you aware of any plan to improve the ‘source selection’ for the Android TV media player ?
It would be really nice to choose what apps to be in the sources, instead of having them in the middle of all the background processes.

I have tried to do this, but since the mibox and mibox s only have a usb port to use an ethernet adapter with this won’t work. You have to turn on usb debugging to get the adb connection and even trying the rdnis option hasn’t worked.
So unless someone finds another way to send these commands over the network like the android tv remote app does we seem to be stuck on wifi with any miboxen.

I switched on my fire tv stick 4k from 2.4 ghz to 5ghz and suddenly it is not anymore available in HA.

My related config is:

  - platform: androidtv
    name: Fire TV Salotto
    host: 192.168.1.52
    device_class: firetv
    adb_server_ip: 127.0.0.1

And had NO problems since i switched wifi…
Is anyone having the same issue? Is there an incompatibility between HA and 5Ghz?

Same problem for me. I did a fritz router restart and my fire tv 4k is not more available in ha. I noticed that fire tv now is connecetd to 5ghz wifi.

I don’t have any amazon hardware to test with, but could it be that when you changed your wireless band that your router assigned a different IP address?
I still have issues with this and have to reboot my android TV boxes every now and then to see them again even though the still have the same IP. Not sure if this is an ADB thing or what, but they come back after a power cycle.

Is it possible to slow-down the screen shot generation period? I love the feature that the entity picture gets updated with current screen, but it updates every 5 seconds or so, which causes the media player icon to flash (I use mini-media player, but same behavior in default media control card).

I am using a FireTV stick with the built-in python adb

1 Like

I found as of a recent Fire TV update, that my Insignia Fire TV edition seems to be using Android’s Doze function. After I turn the tv “off” (which used to just put it in in a ‘soft’ standby mode with full network connectivity), the tv will disconnect from the network after about 5 minutes, won’t even respond to ping, and when I power it back on it turns on to the boot screen before waking rather than just waking like it used to. In my Unifi router controller I see that it is showing it’s in Powersave mode during this time. I’ve found that at regular intervals the Fire TV will wake for a period of time and then drop network again, likely checking in with Amazon servers.

As an attempt to fix this myself, I’ve tried to use adb commands to set the sleep time to 0. I’ve tried to sideload the wakelock app, however the Android Doze function is not effected by wakelock. Next I’m going to try to see if I can disable Doze via adb shell commands, and/or see if responding to ping will keep the Fire TV from sleep, then just keep a ping going at regular intervals.

Since yesterday i get suddenly these errors and my android box tv is in unavailable state:

2020-04-12 21:50:41 ERROR (MainThread) [homeassistant.components.media_player] Error while setting up androidtv platform for media_player
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 179, 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 213, in setup_platform
    state_detection_rules=config[CONF_STATE_DETECTION_RULES],
  File "/usr/local/lib/python3.7/site-packages/androidtv/__init__.py", line 44, in setup
    return AndroidTV(host, port, adbkey, adb_server_ip, adb_server_port, state_detection_rules, auth_timeout_s)
  File "/usr/local/lib/python3.7/site-packages/androidtv/androidtv.py", line 40, in __init__
    BaseTV.__init__(self, 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)
  File "/usr/local/lib/python3.7/site-packages/ppadb/command/transport/__init__.py", line 23, in shell
    conn.send(cmd)
  File "/usr/local/lib/python3.7/site-packages/ppadb/connection.py", line 77, in send
    return self._check_status()
  File "/usr/local/lib/python3.7/site-packages/ppadb/connection.py", line 83, in _check_status
    raise RuntimeError("ERROR: {} {}".format(repr(recv), error))
RuntimeError: ERROR: 'FAIL' 0006closed

While my two fire tv sticks are regularly online and working as expected…
Any hints?

Hello!

After getting back to HA after a longer break I configured my Sony Android TV using this integration. My configuration is simple, like this:

  - platform: androidtv
    name: Sony TV
    host: X.X.X.X
    adb_server_ip: 127.0.0.1
    adb_server_port: 5037
    get_sources: true
    apps:
      com.sony.dtv.tvx: "TV"
      com.google.android.leanbacklauncher: "Home"
    turn_on_command: "input keyevent 3"
    turn_off_command: "input keyevent 223"

It works, there are few issues though. First is that I don’t see any sources but
STREAM_NOTIFICATION:
Strange :thinking:
Another thing is that when I play Spotify on the TV I do not get “artist - title” of currently played song, I don’t know if it’s by design or it’s a bug. Also in the preview I don’t see cover art also but sort of like a small screenshot of current view seen on the TV.
Last thing is that the Media Player card flickers every few seconds, I don’t know if it’s because refreshing data on the cover and it’s to be expected.
I am also having issues with unavailable state after longer period but I did find some posts about wakelocks and sideloading an app to prevent this from happening and I will investigate further.

Anyway, all help is welcome, thanks!

Hello,
I am having an issue with the exclude_unnamed_apps parameter. I thought this would display the apps defined in both the backend library and the ones I have defined in the apps parameter.

Here is my config:

- platform: androidtv
    host: 192.168.0.14
    name: Nvidia Shield
    adb_server_ip: 127.0.0.1
    adb_server_port: 5037
    exclude_unnamed_apps: True
    apps:
      "tv.molotov.app" : "Molotov"
      "com.synology.dsphoto" : "DS Photo"
      "com.synology.dsvideo" : "DS Video"
      "com.google.android.music" : "Google Music"
      "com.google.android.tvlauncher" : "Accueil"
      "com.mobisystems.fileman" : "File commander"
      "com.joaomgcd.join" : "Join"
      "net.dinglisch.android.taskerm" : "Tasker"
      "com.google.android.katniss.search.SearchActivityService" : "Google Assistant"
      "com.google.android.apps.mediashell" : "Chromecast"
      "com.android.tv.settings" : "Paramètres"

And here is a screenshot of the sources proposed by my androidTV media player
Sans titre
As one can see, I does not show some of the apps from the backend library (Youtube, VLC for instance). Some of my user-defined apps (DS video, DS photos from Synology) are not present in the list, until I open them manually.

Other problem, the “Home” source (accueil in the screenshot) does not work. It has also been reported by another user here.

Any idea ?

Thanks !

The sources list only displays the running apps, so it is behaving as intended. This could be documented better on the Android TV documentation page… The problem is that the page has become a bit cluttered, due to both the plethora of configuration options as well as all the ADB troubleshooting info. And with the decision to move towards config flows and away from YAML configuration, the configuration will stay the way it is until someone adds config flow support. And that’s not something I want to do!

You can always launch an app using the media_player.select_source service call and putting, for example, source: YouTube or source: "DS Photo", regardless of whether that source is currently in the drop-down sources list.

The command used by the backend library to launch apps doesn’t work for every app, as you found with “Accueil.” In those cases, you need to figure out the right intent to use with the androidtv.adb_command service; this gist contains a lot of info about that.

1 Like

Thank you for your complete answer

Hey all!

I am working on revamping my lovelace UI to mimic an actual touch panel, and I have successfully created a ‘Netflix button’ that will open the Netflix App on my Fire Stick 4K.

I want to add a ‘HULU button’ as well, so I added the same code except I changed the app id to ‘com.hulu.livingroomplus’ and no dice! I also saw that there is another app id for HULU, ‘com.hulu.plus’, I tried this as well and it doesn’t work either.

I am unsure what I am missing here - below is my config entry, and my lovelaceui entry. For clarity - my lovelaceui is done by using picture-elements with images & tap-actions.

Any thoughts and or ideas??

Copy to clipboard

- platform: androidtv
    name: "Fire TV"
    device_class: firetv
    host: 10.20.18.14
    port: 5555
    adb_server_ip: 127.0.0.1
    adb_server_port: 5037
    apps:
      com.netflix.ninja: "Netflix"
      com.hulu.livingroomplus: "HULU"
      com.amazon.avod: "Amazon Video"

Copy to clipboard

#HULU Button
          - entity: media_player.fire_tv
            image: /local/hulu_logo.png
            style:
              left: 20%
              top: 60%
              width: 20%
            tap_action:
              action: call-service
              service: androidtv.adb_command
              service_data:
                command: am start -a android.intent.action.VIEW -d -n com.hulu.livingroomplus/.MainActivity
                entity_id: media_player.fire_tv
            type: image