Native support for Android TV / Android devices

I would like to know if it’s possible to define sources for the android TV component so that I can load an app directly from the source dropdown list ? (I don’t have the FireTV, for which it seems to be possible)
I haven’t seen any post/documentation about that, and since I don’t know how the media player sources really work, I don’t know if it’s possible.
Thank you!

Hello guys. I have a AndroidTV box with tuner for watching TV ( T2&S2 ). Everything goes OK but, have a little problem with the state of app ATV7 (com.pineone.sb), when i open it to watch the tv, in the state i have Live TV ‘paused’, and when i turn off the box, in the state have Live TV ‘playing’.
Can i inverted this role?
This is my basic conficuration:

media_player:
  # Use the Python ADB implementation
  - platform: androidtv
    host: 192.168.1.167
    name: "Android TV"
    device_class: androidtv
    apps:
      com.google.android.leanbacklauncher: "Android Home"
      com.pineone.sb: "Live TV"

and this is the adb response when i call GET_PROPERTIES

Output of command 'GET_PROPERTIES' from 'media_player.android_tv': {'screen_on': True, 'awake': True, 'audio_state': 'idle', 'wake_lock_size': 1, 'current_app': 'com.pineone.sb', 'media_session_state': None, 'device': 'hdmi', 'is_volume_muted': False, 'volume': 9}

TV OFF

TV ON

Greetings

Solved.
I also gave the GET_PROPERTIES command with the TV turned off and I saw that it signaled a wake_lock_size different from the one before, so I tried to configure it like this.

media_player:
  # Use the Python ADB implementation
  - platform: androidtv
    host: 192.168.1.167
    name: "Android TV"
    device_class: androidtv
    apps:
      com.google.android.leanbacklauncher: "Android Home"
      com.pineone.sb: "Live TV"
    state_detection_rules:
      'com.pineone.sb':
        - 'playing':
            'wake_lock_size': 1
        - 'standby':
            'wake_lock_size': 2

Can someone please point me to a more detailed tutorial on how to get the most out of this component? I’m looking for more detailed info on how to control specific apps and the general behaviour.

Thanks! :slight_smile:

You can make automations using template trigger like:

    
- alias: "Netflix automation"
  trigger:
  - platform: template
    value_template: "{% if is_state('media_player.android_tv', 'playing') and is_state_attr('media_player.android_tv', 'app_name', 'Netflix') %}true{% endif %}"

1 Like

I had to restore my Hassio and now I keep getting the " androidtv/adb_command. Service not found."

My button in lovelace is coded as follows:

              - type: custom:card-modder
                card:
                  type: entity-button
                  icon: mdi:arrow-left-bold
                  name: "LEFT"
                  entity: media_player.shield
                  hold_action: none
                  tap_action:
                    action: call-service
                    service: androidtv.adb_command
                    service_data:
                      entity_id: media_player.shield
                      command: LEFT
                style:

I got the androidtv from ha-androidtv-master folder in my custom_component

Not sure what is causing this, I had this issue before but don’t remember how I ended up fixing it.

Hello,
It looks like the androidTV component got updated recently. I now have a list of apps as sources in my media player entity. I really love this feature !


However, is there a way to customize the list of apps appearing here ? Most of them are running processes that I don’t need to see.

Edit:
If I may add another suggestion: the AndroidTV component should be able to expose the sources (app list) even if the player is in standby mode, just like the PS4 component, so that one could launch an app in just 1 click!

Thanks !

2 Likes

I added the ones I needed in the app: list but I am still seeing all the other sources as well. I thought if I turned off get_sources it would only show the ones I mapped but that was not the case, with get_sources: false I get nothing.

1 Like

The app option is only here to give a friendly name for the package / processes.
For instance replace com.plexapp.android by Plex.
But it is not used to generate the app/source list.

Is it possible to turn on android TV using media control component?

Yes :slight_smile:

Does anyone know how to control the Android TV (Xiaomi Mi Box S specifically) through ip/tcp and/or Bluetooth? I cannot use the ADB because of the restrictions in combination with the USB port (with an ethernet adapter)
I thought my google skills were on point, but I am having a hard time finding the network api, while there are some Android apps that do control it over the network.

nmap shows some open ports:

Nmap scan report for xxx.xxx.xxx.xxx
Host is up (0.0011s latency).
Not shown: 994 closed ports
PORT     STATE SERVICE
8008/tcp open  http
8009/tcp open  ajp13
8080/tcp open  http-proxy
8443/tcp open  https-alt
9000/tcp open  cslistener
9090/tcp open  zeus-admin

Where 8008 and 8009 seem to be for the build-in Chromecast (according to google)

1 Like

How? I am only able to turn off. But after that the entity becomes unavailable. So i am not able to turn on

Hi, api was finnaly able to get this working whit both the adb python and adb server options. The component works just but there is a huge delay at any interaction (pause, launch apps, recovery states…) like a good 5 to 7 seconds

I have other media players added from the same tv and the actions are instant. Is this a specific adb problem? Any way to fix it ?

Is this delay present with both the Python ADB and ADB server configurations? Is one approach faster than the other?

Now I see where you’re getting… :wink:

AndroidTV has problems on some devices, that aren’t able to handle wake-on-lan. In my case the tv component (Sony Bravia with PSK) takes this into account.

My only idea would be to set up a wakelock. Not ideal, but better than nothing. :slight_smile:

Yes. I did more testing and the delay (5-9 seconds) is present on everything related whit the media player (update device status, play/pause, switch sources, volumen up/down/mute).
The delay is there interacting whit the media players cards or calling one of the media player functions whit services

I can confirm that sending anything whit the adb_command is instant. Also i cant see a diference of speed whit python adb or server adb because the delay is not always consistent ( goes from sometimes 3 seconds to 9 seconds).

How the ‘“select source” service launch the apps? If i try to open netflix from the sources takes like 3 to 5 seconds, whit adb command -> am start -n com.netflix.ninja/.MainActivity is instant

Also, i have just tried this beta version https://github.com/JeffLIrion/ha-androidtv whit unfortunately the same results :confused:

@Sxkre, How would I go about sending commands via adb instead of the regular way, which are awfully slow? Also, anyway to merge this with Google Cast integration card, and pull the metadata?

Thanks

Go to services —> androidtv.adb _command. For netflix the example is am start -n com.netflix.ninja/.MainActivity

I find the package name to launch whit this ( u need to adb shell on your tv first)—> dumpsys package | grep hbo | grep Activity (change hbo for the app name and a couple of process will show up. Just try one of them whit am start -n and the app will launch

Hi, I’m using below code in a glance card configured to open app with tap_action and close the app with hold_action

type: glance
entities:
  - entity: script.start_netflix
    icon: 'mdi:netflix'
    tap_action:
      action: call-service
      service: script.start_netflix
    hold_action:
      action: call-service
      service: script.stop_netflix
  - entity: script.start_primevideo
    icon: 'mdi:amazon'
    tap_action:
      action: call-service
      service: script.start_primevideo
    hold_action:
      action: call-service
      service: script.stop_primevideo
  - entity: script.start_playmusic
    icon: 'mdi:play-circle-outline'
    tap_action:
      action: call-service
      service: script.start_playmusic
    hold_action:
      action: call-service
      service: script.stop_playmusic
show_name: false
show_state: false
columns: 3

my script

start_netflix:
  sequence:
  - data:
      entity_id: media_player.android_tv
      source: com.netflix.ninja
    service: media_player.select_source
  alias: Start Netflix
stop_netflix:
  sequence:
  - data:
      entity_id: media_player.android_tv
      source: '!com.netflix.ninja'
    service: media_player.select_source
  alias: Stop Netflix
start_primevideo:
  sequence:
  - data:
      entity_id: media_player.android_tv
      source: com.amazon.amazonvideo.livingroom
    service: media_player.select_source
  alias: Start Prime Video
stop_primevideo:
  sequence:
  - data:
      entity_id: media_player.android_tv
      source: '!com.amazon.amazonvideo.livingroom'
    service: media_player.select_source
  alias: Stop Prime Video
start_playmusic:
  sequence:
  - data:
      entity_id: media_player.android_tv
      source: com.google.android.music
    service: media_player.select_source
  alias: Start Play Music
stop_playmusic:
  sequence:
  - data:
      entity_id: media_player.android_tv
      source: '!com.google.android.music'
    service: media_player.select_source
  alias: Stop Play Music

Netflix is working fine, but Amazon Prime Video and Google play music is just closing, but not opening.

One more thing, how can I use the hold action in original remote to get more options like context menu when I press the middle enter button?

1 Like