Native support for Android TV / Android devices

@MomoB @blakadder Thank you both for your feedback! :+1:

If anyone knows how to make a Hass.io addon that can install the ADB binaries and start the ADB server, that would be very helpful!

2 Likes

I am using hassio latest version installed through docker on my raspberrypi3b+.
i am using Mini m8s2 android tv box.
i am getting adb connections by adb connect xxx.xxx.xxx.xxx

this is the error which i am receiving
2019-01-03 13:39:40 ERROR (MainThread) [homeassistant.components.media_player] Error while setting up platform androidtv
Traceback (most recent call last):
File “/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity_platform.py”, line 128, in _async_setup_platform
SLOW_SETUP_MAX_WAIT, loop=hass.loop)
File “/usr/local/lib/python3.6/asyncio/tasks.py”, line 358, in wait_for
return fut.result()
File “/usr/local/lib/python3.6/concurrent/futures/thread.py”, line 56, in run
result = self.fn(*self.args, **self.kwargs)
File “/config/custom_components/media_player/androidtv.py”, line 181, in setup_platform
atv = AndroidTV(host, adbkey)
File “/config/deps/lib/python3.6/site-packages/androidtv/init.py”, line 230, in init
self.properties = self.device_info()
File “/config/deps/lib/python3.6/site-packages/androidtv/init.py”, line 327, in device_info
btmac = re.findall(BTMAC_REGEX_PATTERN, properties)[0]
IndexError: list index out of range

Please guide me to solve my problem.

Can someone,who got Android TV working,make a video of working and how feature works with Android TV/box.
Please someone,
So that all features can be fully used by all.

Hi a1ex4,

Thanks for developing a component for androidtv.
Unfortunately I cant get my Philips (android) TV to trust my Raspberry pi (running my HA instance). (see below)

pi@rhea:~$ adb devices
List of devices attached
192.168.1.114:5555      unauthorized

I enabled USB debugging but as far I understand I would be supposed to connect the TV to my raspi by USB to enable wireless ADB afterwards. Unfortunately I seems very cumbersome to move my TV or my raspi - do you have an idea how to enable ADB over Wifi without connecting by usb?

Thanks for any pointers.

Best regards
noheton

pi@rhea:~$ adb shell getprop
error: device unauthorized.
This adb server's $ADB_VENDOR_KEYS is not set
Try 'adb kill-server' if that seems wrong.
Otherwise check for a confirmation dialog on your device.

When u allow ADB connections in Android TV and after connecting it with rasp using ADB, u have to look at TV for a popup which asks to allow ADB connections,
U have to select always and allow.
After that is done it wont show unauthorised.
Try and let us know ur story.

Hmm unfortunately I don’t seem to get any notification at all when I enable USB Debugging or when I try to connect with the raspi.
The TV is running Android Nougat (7?) by the way.
I will try again later and let you know.

Update: A reboot of the TV seems to have fixed it. Sorry my bad. I will now play with the component a bit :slight_smile:

What features are available through this component,
Please make a video,
As I am getting it working, but can’t see any options to open an app using this component.

Wait how did you install the ADB binaries on Hassio ? I thought that was impossible, but I don’t know much bout Hassio. I’m going to assume you meant Home-assistant installed with docker on a RPi to help you solve your issue. We’re going to updtate the library used by this component:
cd /config/deps/lib/python3.6/site-packages/androidtv/
mv __init__.py __init__.py.bak
wget https://raw.githubusercontent.com/JeffLIrion/python-androidtv/master/androidtv/__init__.py
Then restart HA and report back! :wink:

@noheton Glad you got it to work, ADB connection can be inconsistent sometime.

The available features are explained in the original post, under the service section. The “Open app” service has not yet been implemented as I don’t have access to an Android TV for the hollidays.

Now the adb connection seems to work but unfortunately the androidtv package cant make sense of my device properties.

Init of the component fails with:

File “/config/deps/lib/python3.6/site-packages/androidtv/ **init** .py”, line 327, in device_info
btmac = re.findall(BTMAC_REGEX_PATTERN, properties)[0]
IndexError: list index out of range

My pi@rhea:~$ adb shell getprop

[dalvik.vm.appimageformat]: [lz4]
[dalvik.vm.dex2oat-Xms]: [64m]
[dalvik.vm.dex2oat-Xmx]: [512m]
[dalvik.vm.heapgrowthlimit]: [192m]
[dalvik.vm.heapmaxfree]: [8m]
[dalvik.vm.heapminfree]: [512k]
[dalvik.vm.heapsize]: [512m]
[dalvik.vm.heapstartsize]: [16m]
[dalvik.vm.heaptargetutilization]: [0.75]
[dalvik.vm.image-dex2oat-Xms]: [64m]
[dalvik.vm.image-dex2oat-Xmx]: [64m]
[dalvik.vm.isa.arm.features]: [default]
[dalvik.vm.isa.arm.variant]: [cortex-a9]
[dalvik.vm.stack-trace-file]: [/data/anr/traces.txt]
[dalvik.vm.usejit]: [true]
[dalvik.vm.usejitprofiles]: [true]
[debug.atrace.tags.enableflags]: [0]
[debug.force_rtl]: [0]
[debug.hwui.use_buffer_age]: [0]
[dev.bootcomplete]: [1]
[drm.service.enabled]: [true]
[hwc.rm]: [0]
[init.svc.adbd]: [running]
[init.svc.audioserver]: [running]
[init.svc.bindersvr_tv]: [running]
[init.svc.blackBox]: [stopped]
[init.svc.bootanim]: [stopped]
[init.svc.cameraserver]: [running]
[init.svc.clearCounter]: [stopped]
[init.svc.console]: [running]
[init.svc.ddg]: [running]
[init.svc.debuggerd]: [running]
[init.svc.drm]: [running]
[init.svc.dtv-svc]: [stopped]
[init.svc.gatekeeperd]: [running]
[init.svc.healthd]: [running]
[init.svc.insmod]: [stopped]
[init.svc.installd]: [running]
[init.svc.k2logcat]: [running]
[init.svc.keystore]: [running]
[init.svc.lmkd]: [running]
[init.svc.logd]: [running]
[init.svc.logd-reinit]: [stopped]
[init.svc.mdnsd]: [running]
[init.svc.media]: [running]
[init.svc.mediacodec]: [running]
[init.svc.mediadrm]: [running]
[init.svc.mediaextractor]: [running]
[init.svc.mount_cache]: [stopped]
[init.svc.mtk_rm]: [stopped]
[init.svc.netd]: [running]
[init.svc.p2p_supplicant]: [running]
[init.svc.servicemanager]: [running]
[init.svc.surfaceflinger]: [running]
[init.svc.tvnativeserver]: [running]
[init.svc.ueventd]: [running]
[init.svc.updatedns]: [stopped]
[init.svc.vold]: [running]
[init.svc.wakelock_proxy]: [running]
[init.svc.zram-svc]: [stopped]
[init.svc.zygote]: [running]
[media.hls.default.max-height]: [1080]
[media.hls.default.max-width]: [1920]
[media.stagefright.codecremote]: [0]
[mtk.disable_sync_from_ts]: [1]
[mtk.inside]: [1]
[mtk.omx.vdp]: [1]
[mtk.tma.enable]: [0]
[mtk.wopacket.force_default_on]: [1]
[net.bt.name]: [Android]
[net.change]: [net.dns1]
[net.dns1]: [192.168.1.1]
[net.dns2]: [8.8.4.4]
[net.hostname]: [android-a87b1772108d6866]
[net.qtaguid_enabled]: [1]
[net.tcp.default_init_rwnd]: [60]
[persist.bt.avrcp.ct]: [0]
[persist.service.bdroid.bdaddr]: [22:22:bd:17:6e:7e]
[persist.sys.BTRemotePairingDone]: [0]
[persist.sys.CEC_wakeup_en]: [1]
[persist.sys.CICAMSTATUS]: [NOTUPGRADING]
[persist.sys.ColdBootReason]: [CrashBoot]
[persist.sys.Greenmutestatus]: [false]
[persist.sys.ICPsignon]: [0]
[persist.sys.OFFRS_UI_IS_OPENED]: [false]
[persist.sys.OLED]: [0]
[persist.sys.PHLRC]: [0]
[persist.sys.PinCodeResult]: [-1]
[persist.sys.PinStatus]: [NONE]
[persist.sys.WOWCAST]: [0]
[persist.sys.bluetooth.dialogs]: [true]
[persist.sys.dalvik.vm.lib.2]: [libart.so]
[persist.sys.deviceprovisioned]: [true]
[persist.sys.dumpId]: [00000227_00000003_00033816.508622_1794]
[persist.sys.inputid]: [com.mediatek.tvinput/.dtv.TunerInputService/HW9]
[persist.sys.isfav]: [0]
[persist.sys.locale]: [de-DE]
[persist.sys.loungmode.booting]: [false]
[persist.sys.media.avsync]: [true]
[persist.sys.mediaindex]: [3]
[persist.sys.power_appswitch]: [org.droidtv.playtv]
[persist.sys.power_currentstate]: [FULL]
[persist.sys.power_lastapp]: [none]
[persist.sys.power_previousstate]: [BOOTING]
[persist.sys.power_silentreboot]: [03.01.2019 4:38:07 vorm.(PERFORMED)]
[persist.sys.profiler_ms]: [0]
[persist.sys.screen_status]: [OFF]
[persist.sys.set_type]: [55PUS6482/12]
[persist.sys.source_ui_running]: [0]
[persist.sys.timezone]: [Etc/GMT-1]
[persist.sys.upgrade_filename]: []
[persist.sys.upgrade_source]: []
[persist.sys.usb.config]: [adb]
[persist.sys.virginbit]: [0]
[persist.sys.webview.vmsize]: [104857600]
[pm.dexopt.ab-ota]: [speed-profile]
[pm.dexopt.bg-dexopt]: [speed-profile]
[pm.dexopt.boot]: [verify-profile]
[pm.dexopt.core-app]: [speed]
[pm.dexopt.first-boot]: [interpret-only]
[pm.dexopt.forced-dexopt]: [speed]
[pm.dexopt.install]: [interpret-only]
[pm.dexopt.nsys-library]: [speed]
[pm.dexopt.shared-apk]: [speed]
[ro.adb.secure]: [1]
[ro.allow.mock.location]: [0]
[ro.baseband]: [unknown]
[ro.board.platform]: [mt5891]
[ro.boot.flash.locked]: [1]
[ro.boot.hardware]: [mt5891]
[ro.boot.serialno]: [000070af2412bd2f]
[ro.bootimage.build.date]: [Fri Aug 31 15:31:47 CST 2018]
[ro.bootimage.build.date.utc]: [1535700707]
[ro.bootimage.build.fingerprint]: [Philips/PH7M_EU_5596/PH7M_EU_5596:7.0/NTG46/276:user/release-keys]
[ro.bootloader]: [unknown]
[ro.bootmode]: [unknown]
[ro.build.characteristics]: [nosdcard,tv]
[ro.build.date]: [Fri Aug 31 15:31:47 CST 2018]
[ro.build.date.utc]: [1535700707]
[ro.build.description]: [PH7M_EU_5596-user 7.0 NTG46 276 release-keys]
[ro.build.display.id]: [NTG46 release-keys]
[ro.build.fingerprint]: [Philips/PH7M_EU_5596/PH7M_EU_5596:7.0/NTG46/276:user/release-keys]
[ro.build.flavor]: [PH7M_EU_5596-user]
[ro.build.host]: [TWCLS075]
[ro.build.id]: [NTG46]
[ro.build.product]: [PH7M_EU_5596]
[ro.build.tags]: [release-keys]
[ro.build.type]: [user]
[ro.build.user]: [jenkins]
[ro.build.version.all_codenames]: [REL]
[ro.build.version.base_os]: []
[ro.build.version.codename]: [REL]
[ro.build.version.incremental]: [276]
[ro.build.version.preview_sdk]: [0]
[ro.build.version.release]: [7.0]
[ro.build.version.sdk]: [24]
[ro.build.version.security_patch]: [2018-07-05]
[ro.camera.hal32.support]: [1]
[ro.camera.support]: [1]
[ro.com.google.clientidbase]: [android-philips-tv]
[ro.com.google.gmsversion]: [N_Q3_2017]
[ro.config.debugdump.customized]: [true]
[ro.config.media_vol_steps]: [60]
[ro.config.ts.date.time]: [true]
[ro.crypto.fuse_sdcard]: [true]
[ro.crypto.state]: [unsupported]
[ro.dalvik.vm.native.bridge]: [0]
[ro.debuggable]: [0]
[ro.expect.recovery_id]: [0x37a09ab16edfd8e4916c5830bc239fb7665091b5000000000000000000000000]
[ro.hardware]: [mt5891]
[ro.hdmi.device_type]: [0]
[ro.hwui.disable_scissor_opt]: [true]
[ro.hwui.drop_shadow_cache_size]: [6]
[ro.hwui.gradient_cache_size]: [1]
[ro.hwui.layer_cache_size]: [48]
[ro.hwui.path_cache_size]: [32]
[ro.hwui.r_buffer_cache_size]: [8]
[ro.hwui.text_large_cache_height]: [1024]
[ro.hwui.text_large_cache_width]: [2048]
[ro.hwui.text_small_cache_height]: [1024]
[ro.hwui.text_small_cache_width]: [1024]
[ro.hwui.texture_cache_flushrate]: [0.4]
[ro.hwui.texture_cache_size]: [48]
[ro.mtk.sys_driver_only]: [0]
[ro.mtk.system.audiosync]: [1]
[ro.mtk.system.av_record_lib]: [1]
[ro.mtk.system.cec.hal]: [1]
[ro.mtk.system.ci.existed]: [1]
[ro.mtk.system.dvbs.existed]: [1]
[ro.mtk.system.hbbtv.existed]: [1]
[ro.mtk.system.marketregion]: [eu]
[ro.mtk.system.mheg5.existed]: [1]
[ro.mtk.system.oad.existed]: [1]
[ro.mtk.system.subtitle.existed]: [1]
[ro.mtk.system.timesync.existed]: [1]
[ro.mtk.system.ttx.existed]: [1]
[ro.mtk.twoworlds]: [1]
[ro.nrdp.hdr10.revision]: [1]
[ro.nrdp.validation]: [ninja_4]
[ro.opengles.version]: [196610]
[ro.product.board]: [TPM17XE_96]
[ro.product.brand]: [Philips]
[ro.product.cpu.abi]: [armeabi-v7a]
[ro.product.cpu.abi2]: [armeabi]
[ro.product.cpu.abilist]: [armeabi-v7a,armeabi]
[ro.product.cpu.abilist32]: [armeabi-v7a,armeabi]
[ro.product.cpu.abilist64]: []
[ro.product.device]: [PH7M_EU_5596]
[ro.product.first_api_level]: [23]
[ro.product.locale]: [en-US]
[ro.product.manufacturer]: [Philips]
[ro.product.model]: [TPM171E]
[ro.product.name]: [PH7M_EU_5596]
[ro.recovery_id]: [0x37a09ab16edfd8e4916c5830bc239fb7665091b5000000000000000000000000]
[ro.revision]: [0]
[ro.runtime.firstboot]: [1546524549207]
[ro.secure]: [1]
[ro.serialno]: [000070af2412bd2f]
[ro.setupwizard.mode]: [OPTIONAL]
[ro.sf.lcd_density]: [320]
[ro.system.hdr10.revision]: [1]
[ro.tpvision.product.id]: [TPM171E_R]
[ro.tpvision.product.swversion]: [TPM171E_R.003.001.012.000]
[ro.url.safetylegal]: [https://www.google.com/policies/privacy/]
[ro.wifi.channels]: []
[ro.zygote]: [zygote32]
[security.perf_harden]: [1]
[selinux.reload_policy]: [1]
[service.adb.tcp.port]: [5555]
[service.bootanim.exit]: [1]
[sys.boot_completed]: [1]
[sys.display-size]: [3840x2160]
[sys.hwc.improve.disable]: [0]
[sys.hwc.improve.enable]: [1]
[sys.isHbbTvActive]: [1]
[sys.isHbbTvStreamStart]: [0]
[sys.isMHEG5Active]: [0]
[sys.mtk.dmremoteservice.ready]: [1]
[sys.mtk.livetv.ready]: [1]
[sys.mtk.tif.dvr]: [1]
[sys.mtk.tif.timeshift]: [1]
[sys.mtk.tvremoteservice.ready]: [1]
[sys.playtv.booted]: [1]
[sys.sysctl.extra_free_kbytes]: [24300]
[sys.sysctl.tcp_def_init_rwnd]: [60]
[sys.usb.config]: [adb]
[sys.usb.configfs]: [0]
[sys.usb.state]: [adb]
[system_init.startsurfaceflinger]: [0]
[vold.has_adoptable]: [1]
[vold.post_fs_data_done]: [1]
[wifi.interface]: [wlan0]
[wlan.driver.status]: [ok]

replacing init.py yields:

Traceback (most recent call last):
  File "/home/pi/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/entity_platform.py", line 128, in _async_setup_platform
    SLOW_SETUP_MAX_WAIT, loop=hass.loop)
  File "/usr/lib/python3.5/asyncio/tasks.py", line 400, in wait_for
    return fut.result()
  File "/usr/lib/python3.5/asyncio/futures.py", line 293, in result
    raise self._exception
  File "/usr/lib/python3.5/concurrent/futures/thread.py", line 55, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/home/pi/.homeassistant/custom_components/media_player/androidtv.py", line 181, in setup_platform
    atv = AndroidTV(host, adbkey)
  File "/home/pi/homeassistant/lib/python3.5/site-packages/androidtv/__init__.py", line 230, in __init__
    self.properties = self.device_info()
  File "/home/pi/homeassistant/lib/python3.5/site-packages/androidtv/__init__.py", line 330, in device_info
    wifi_out = self._adb_shell('ip addr show wlan0')
  File "/home/pi/homeassistant/lib/python3.5/site-packages/androidtv/__init__.py", line 474, in _adb_shell_python_adb
    return self._adb.Shell(cmd)
  File "/home/pi/homeassistant/lib/python3.5/site-packages/adb/adb_commands.py", line 376, in Shell
    timeout_ms=timeout_ms)
  File "/home/pi/homeassistant/lib/python3.5/site-packages/adb/adb_protocol.py", line 411, in Command
    return ''.join(cls.StreamingCommand(usb, service, command, timeout_ms))
  File "/home/pi/homeassistant/lib/python3.5/site-packages/adb/adb_protocol.py", line 439, in StreamingCommand
    for data in connection.ReadUntilClose():
AttributeError: 'NoneType' object has no attribute 'ReadUntilClose'

Do this as suggested by a1xea4
I got it working few hours back but forget to mention.

Thanks @a1ex4

cd /config/deps/lib/python3.6/site-packages/androidtv/
mv __init__.py __init__.py.bak
wget https://raw.githubusercontent.com/JeffLIrion/python-androidtv/master/androidtv/__init__.py
Then restart HA and report back! :wink:

Sorry,
I tho it it’s already implemented,
I would like to have music app under apps.
How to get it?
Please guide.
Thanks in adv.

I guess you are using the component with the adb key, and unfortunately I’m not sure I’ll be able to fully make the component work with this implementation. Can you please try the newer __init__.py but with the component configured to connect to the adb server ? Should look like this:

  - platform: androidtv
    host: IP
    name: NAME
    adb_server_ip: 127.0.0.1

What do you mean ?

To control music.
I want to add music app.
How can I add it?

this works beautifully.

I took an initial stab at creating a Hass.io addon for setting up an ADB server. Currently, it doesn’t work – it won’t install. Contributions are welcome! The repository and all the info you need can be found here: https://github.com/JeffLIrion/hassio-adb-server-addon.

3 Likes

Dear,
A help needed,
When my android TV box is turned off,
My log is getting busy creating logs for not connected,
How to stop created Ng log when android TV is off

One more thing when my android is off the ui shows dark blue colour and when on it turns to light blue, please invert colours to match other media_player device.
When some thing is playing on amazon or any app, play symbol is seen( even if on idle)
But when I pause it, pause icon doesn’t appear,
Is it like that?
Please guide