Native support for Android TV / Android devices

Hi,

Could someone help me what is wrong with my configuration, particularly, with state_detection_rules that I actually copied from docs example:

media_player:
  - platform: androidtv
    host: 192.168.1.100
    name: Android TV
    adb_server_ip: 127.0.0.1
    adb_server_port: 5037
    apps:
      org.droidtv.playtv: "TV"
      com.google.android.youtube.tv: "YouTube"
      com.netflix.ninja: "Netflix"
      org.droidtv.tvsystemui: "Screensaver"
      com.plexapp.android: "Plex"
      com.google.android.tvlauncher: "Menu"
      com.opera.sdk.example: "Browser"
      org.xbmc.kodi: "Kodi"
    state_detection_rules:
      'com.plexapp.android':
        - 'paused':
            'media_session_state': 3  # this indentation is important!
            'wake_lock_size': 1       # this indentation is important!
        - 'playing':
            'media_session_state': 3  # this indentation is important!
        - 'standby'

Unfortunately, validator doesn’t accept it:

Configuration invalid

Invalid config for [media_player.androidtv]: [state_detection_rules] is an invalid option for [media_player.androidtv]. Check: media_player.androidtv->state_detection_rules. (See ?, line ?). Please check the docs at https://home-assistant.io/integrations/media_player.androidtv/

Why i am getting this inside HACS?

I reinstalled three times the component and always got it.
Running 0.100.3

Configuration is:

  - platform: androidtv
    name: Fire TV
    host: 192.168.1.33
    device_class: firetv
    get_sources: false
    apps:
      com.netflix.ninja: "Netflix"
      com.amazon.avod: "Amazon Prime Video"
      com.dazn: "DAZN"
      com.amazon.firetv.youtube: "Youtube"
      it.rainet.androidtv: "RAI Play"
      com.amazon.tv.launcher: "Home"
      com.spotify.tv.android/.SpotifyTVActivity: "Spotify"
      com.esaba.downloader: "Downloader"
      tv.arte.plus7: "Arte"

adb is correctly connected:

pi@hassbian:~$ adb connect 192.168.1.33

connected to 192.168.1.33:5555

But i cannot see the media_player.fire_tv inside my entities…

You’re probably using an old version of HA or an old custom component. Use the latest HA and the built-in component and it should work just fine.

https://www.home-assistant.io/integrations/androidtv#adb-troubleshooting

  1. You are already connected to the Android TV / Fire TV via ADB from another device. Only one device can be connected, so disconnect the other device, restart the Android TV / Fire TV (for good measure), and then restart Home Assistant.

I am using 0.100.3 as i am having BIG problems installing and running 0.101.3.
Is there a release that will work with 0.100.3 as custom component?
I was always connected only with my fire tv… i discovered it changed ip address also if i set it as static IP
Must i restart FireTV again and connect with adb again?

How disconnect the device?

I disconnected (deleting the adb keys) and restarted my fire tv.
Got the request for adb, the two adb keys were created again, clicked ok, restarted HA but still got the same advice !!!
So i need (in the meantime i solve the problem with the 0.101.3 release) of the previous release of the component that was working great…

Why did you delete the keys? You should NOT be running adb connect <IP address>. Read the documentation thoroughly and follow it exactly.

If the device does not get setup in HA, check the log.

The log says nothing… i only get that advice in HACS.
I was thinking that disconnect was to delete keys…

Without the Home Assistant log, it’s impossible to know what’s going on.

Actually i have no log regarding androitv component… what do i use in logger: to check this component?

logger:
  androidtv: info
  custom_components.androidtv: info

Ok, let you know…

Hmmm maybe wrong indentation.
If i set:

logger:
  default: error
  logs:
    homeassistant.components.sensor.mitemp_bt: critical
    homeassistant.components: critical
    homeassistant.components.media_player: critical
    androidtv: info
    custom_components.androidtv: info

I still get no errors…

I forgot to mention that I am using the latest available version 0.101.3 and I am not using the customer component, therefore, I am puzzled with this error.
Can you confirm that full example in the current documentation successfully passing config validation?

Change it to homeassistant.components.media_player: info.

I migrated from the server to client method in 0.101.3 by commenting out the adb_server_ip and using the key generated by the adb command in the adbkey config parameter. It works fine.

- platform: androidtv
  host: 10.1.2.3
  name: Shield
  #  adb_server_ip: 127.0.0.1
  adbkey: /home/homeassistant/.android/adbkey

Check your indentation. This exact config consisting of the documentation config and your config is valid:

media_player:
  - platform: androidtv
    name: Android TV
    device_class: androidtv
    host: 192.168.0.222
    apps:
      com.amazon.tv.launcher: "Fire TV"
    turn_on_command: "input keyevent 3"
    turn_off_command: "input keyevent 223"
    state_detection_rules:
      'com.amazon.tv.launcher':
        - 'standby'
      'com.netflix.ninja':
        - 'media_session_state'
      'com.ellation.vrv':
        - 'audio_state'
      'com.plexapp.android':
        - 'paused':
            'media_session_state': 3  # this indentation is important!
            'wake_lock_size': 1       # this indentation is important!
        - 'playing':
            'media_session_state': 3  # this indentation is important!
        - 'standby'
      'com.amazon.avod':
        - 'playing':
            'wake_lock_size': 4  # this indentation is important!
        - 'playing':
            'wake_lock_size': 3  # this indentation is important!
        - 'paused':
            'wake_lock_size': 2  # this indentation is important!
        - 'paused':
            'wake_lock_size': 1  # this indentation is important!
        - 'standby'
  - platform: androidtv
    host: 192.168.1.100
    name: Android TV
    adb_server_ip: 127.0.0.1
    adb_server_port: 5037
    apps:
      org.droidtv.playtv: "TV"
      com.google.android.youtube.tv: "YouTube"
      com.netflix.ninja: "Netflix"
      org.droidtv.tvsystemui: "Screensaver"
      com.plexapp.android: "Plex"
      com.google.android.tvlauncher: "Menu"
      com.opera.sdk.example: "Browser"
      org.xbmc.kodi: "Kodi"
    state_detection_rules:
      'com.plexapp.android':
        - 'paused':
            'media_session_state': 3  # this indentation is important!
            'wake_lock_size': 1       # this indentation is important!
        - 'playing':
            'media_session_state': 3  # this indentation is important!
        - 'standby'

Ok i did it and this is what i get:

2019-11-13 19:44:48 INFO (MainThread) [homeassistant.components.media_player] Setting up media_player.androidtv

But no entity with that name is present and i still get that advice in HACS.

Just curious:
Having this configuration:

  - platform: androidtv
    name: Fire TV
    host: 192.168.1.33
    device_class: firetv

The media player entity created should be media_player.fire_tv and not media_player androidtv or not?
But i get none of them…

SOLVED: I deleted from the core.entity_registry all the entries regarding firetv. Restarted and… voilà… all is working again. Only one question: why i get two media_players about firetv? One is called media_player.fire_tv (as the name inside the configuration), the second media_player.fire_tv_stick which is always in standby.

Does anyone here know how to get ADB working over Ethernet on a USB adapter?
I have a Xiaomi Mi Box, and attached to it a USB adapter with an Ethernet port. If I enable USB debugging, the Ethernet won’t work, which obviously isn’t an acceptable side effect.