Native support for Android TV / Android devices

So after digging through adb outputs, I found out that it is grepping of Window #1 instead of mCurrentFocus requires identfying currently running app


130|sabrina:/ $ CURRENT_APP=$(dumpsys window windows | grep 'Window #1') && CURRENT_APP=${CURRENT_APP#*{* * } && CURRENT_APP=${CURRENT_APP%%/*} && echo $CURRENT_APP
com.google.android.youtube.tv
indows | grep 'Window #1') && CURRENT_APP=${CURRENT_APP#*{* * } && CURRENT_APP=${CURRENT_APP%%/*} && echo $CURRENT_APP                                                          <
com.disney.disneyplus
indows | grep 'Window #1') && CURRENT_APP=${CURRENT_APP#*{* * } && CURRENT_APP=${CURRENT_APP%%/*} && echo $CURRENT_APP                                                          <
com.disney.disneyplus
indows | grep 'Window #1') && CURRENT_APP=${CURRENT_APP#*{* * } && CURRENT_APP=${CURRENT_APP%%/*} && echo $CURRENT_APP                                                          <
com.hbo.hbonow ```

 Now I need to find out how to get my python-androidtv package on my docker installation.

Got it working with above change. reporting it here someone else tried Google TV Chromecast on home assistant.

1 Like

Just got the CCGTV couple days ago - itā€™s my first Android TV device. Do you need to do the ADB enabling stuff and then enable it using the standard ā€˜androidtvā€™ integration? Thanks.

Once you restart homeassistant after adding androidtv integration to your config, you should see pop on your android tv to allow adb connection just accept it and you should be good along with above minor change.

Hi @sacdroid Could you please let me know exactly what you did to get Chromecast with Google TV reporting status correctly? How do I update the androidtv component to 0.51 to support the new chromecast? How do I make the necessary changes to have the new chromecast device report playback status correctly?

Thank you.

@beninsteon To make it work it requires changes to https://github.com/JeffLIrion/python-androidtv and then installing this custom python module on your home assistant with custom android tv integration. This steps may vary based on your HA install method. I am planning to work submitting pr upstream to fix it.
Change is required how python module identifies current app https://github.com/JeffLIrion/python-androidtv/blob/4ab4f57f889bab3f0e947b44e754bebc128a56b4/androidtv/constants.py#L32

The changes to support Google TV devices are merged into the androidtv package and will be included in the next Home Assistant release.

2 Likes

Thanks! worked for me :slight_smile:

Donā€™t know if it was already mentioned in this thread (donā€™t want to spend all the time browsing 500+ messages), but for Philips TVā€™s you can follow the following steps graphically shown to enable Debugging: https://blog.codetitans.pl/post/howto-enable-android-developer-options-on-philips-tv/

I can confirm that by following these steps on my Philips 55OLED903 I managed to get everything working in conjunction with the https://github.com/hassio-addons/addon-adb ADB pluging of @frenck

I can ask what you managed to set to control the TV. I have a Philips 65 OLED 804, but I donā€™t know what can be set. Thank you

You can set anything with intents. Just as an example: go to developer tools -> services and start playing with the newly created mediplayer. You could, for example, turn on or off the television or run more complex things like playing the latest episode of Desperate Housewives.

Can you share some examples?

I would also be interested in an example to see where and how to start.

Check back to the post from this past summer: Native support for Android TV / Android devices

It references this gist that contains a bunch of examples: https://gist.github.com/mcfrojd/9e6875e1db5c089b1e3ddeb7dba0f304

@pepe59 @maurizio53

3 Likes

Thank you very much for a lot of examples. I will definitely use something .

Hi there,
Iā€™m using my nvidia shield as a media player (native android component). If I start youtube it shows the cover art all fine. However prime video only gives me a black backgroundā€¦it seems like it is not fetching the imageā€¦

Is this a kown issue with the amazon prime video app?

If anybodyā€™s interested, if youā€™re not using HassOS (i.e. Container) and need an adb server container, I found a modified adb image based on the add-on, by peexl, source. Unfortunately, this is only for amd64. I modified it for armhf so it can be used on raspberry pi. Use tag armhf.
Source is here.
Image is here.

Hello, this is my first post, but Iā€™m reading this forum since christmas, as this is the day when I started my Raspberry Pi and Home Assistant adventure. My main goal is to automate my cave equipment for wife to handle :stuck_out_tongue:
I managed with Onkyo amplifier, Optoma projector, Tuya and sonoff light switches ā€¦ but stuck with Nvidia shield. I can use shield.kodi or shield.chromecast integrations, but they have limited possibilities. Iā€™m trying to use androidtv integration, but shield entity is not showing. No mater I use ADB server integration or Python ADB approach.

Here is my configuration.yaml, please advice. ADB in Shield enabled, message accepted, static IP set, device restarted multiple times.

media_player:
  - platform: androidtv
    host: 10.0.0.2
    port: 5555
    name: shield_kino
    device_class: androidtv
    get_sources: false
    adb_server_ip: 127.0.0.1
    adbkey: "/config/android/adbkey"
    apps:
      com.amazon.avod: "Amazon Video"
      com.google.android.tvlauncher: "Homescreen"
      com.google.android.apps.mediashell: "Google Cast"
      eu.hbogo.androidtv.production: "HBO GO"
      org.xbmc.kodi: "Kodi"
      com.netflix.ninja: "Netflix"
      com.plexapp.android: "Plex"
      com.google.android.youtube.tv: "YouTube"

ADB config

devices:
  - 10.0.0.2
reconnect_timeout: 90
log_level: debug
keys_path: /config/android/

ADB LOG

[s6-init] making user provided files available at /var/run/s6/etc...exited 0.
[s6-init] ensuring user provided files have correct perms...exited 0.
[fix-attrs.d] applying ownership & permissions fixes...
[fix-attrs.d] done.
[cont-init.d] executing container initialization scripts...
[cont-init.d] 00-banner.sh: executing... 
-----------------------------------------------------------
 Add-on: ADB - Android Debug Bridge
 The Android Debug Bridge server program
-----------------------------------------------------------
 Add-on version: 0.7.0
 You are running the latest version of this add-on.
 System: Home Assistant OS 5.10  (aarch64 / raspberrypi4-64)
 Home Assistant Core: 2021.1.5
 Home Assistant Supervisor: 2021.01.7
-----------------------------------------------------------
 Please, share the above information when looking for help
 or support in, e.g., GitHub, forums or the Discord chat.
-----------------------------------------------------------
[cont-init.d] 00-banner.sh: exited 0.
[cont-init.d] 01-log-level.sh: executing... 
Log level is set to DEBUG
[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.
[21:24:53] INFO: Starting the Android Debug Bridge server...
[21:24:54] INFO: Connecting to device: 10.0.0.2...
connected to 10.0.0.2:5555
[21:26:24] INFO: Connecting to device: 10.0.0.2...
already connected to 10.0.0.2:5555
[21:27:55] INFO: Connecting to device: 10.0.0.2...
already connected to 10.0.0.2:5555

I can only say that my code consists of:

media_player:

  • platform: androidtv
    name: nvidiashield
    host: mydeviceip ( so just fill in your ip without the stars)

Edit: the black dot should be a " - "

Thatā€™s all that is needed in my case and it is working.

Hi! Did you find any solution to Amazon Prime Video and Google play music only close, but not open? I have the same issue with an app called Viaplay (com.viaplay.android)

1 Like