Native support for Android TV / Android devices

pip3 install androidtv
solved the issue

When ha is connected to my nividia shield, it sometimes becomes unresponsible.
I push buttons and nothing happens.

I had the same issue.as said earlifer, this can be fixed with the following:
cd /srv/homeassistant/lib/python3.5/site-packages/androidtv/
mv __init__.py __init__.py.bak
wget https://raw.githubusercontent.com/JeffLIrion/python-androidtv/fe6e9ffadfd86ef4c45ce75c3a87e0495bfa45c1/androidtv/__init__.py
then restart HA…
hope you ll be ok after this :slight_smile:

thanks, but now i have different error:

Update for media_player.android_tv_media fails
Traceback (most recent call last):
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/entity.py”, line 220, in async_update_ha_state
await self.async_device_update()
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/entity.py”, line 348, in async_device_update
await self.hass.async_add_executor_job(self.update)
File “/usr/lib/python3.5/asyncio/futures.py”, line 380, in iter
yield self # This tells Task to wait for completion.
File “/usr/lib/python3.5/asyncio/tasks.py”, line 304, in _wakeup
future.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/homeassistant/.homeassistant/custom_components/androidtv/media_player.py”, line 262, in __adb_decorator
return func(self, *args, **kwargs)
File “/home/homeassistant/.homeassistant/custom_components/androidtv/media_player.py”, line 323, in update
success = self.androidtv.update()
File “/srv/homeassistant/lib/python3.5/site-packages/androidtv/init.py”, line 315, in update
re.DOTALL | re.MULTILINE)[0]
IndexError: list index out of range

Hi Guy’s,
is there anyone that could help me resolve this issue.
my shield never fails, yet for some reason I can’t get my sony braiva to stay connected, it worked fine for about a week.

wait for a week, a solid androidtv version is coming
It’s under review,
So may be next release

4 Likes

Strange, but since this became official I’m still getting the following in hassio v0.90.1:

019-03-22 20:59:52 ERROR (MainThread) [homeassistant.components.media_player] Error while setting up platform androidtv
Traceback (most recent call last):
File “/usr/local/lib/python3.7/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.7/asyncio/tasks.py”, line 416, 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/local/lib/python3.7/site-packages/homeassistant/components/androidtv/media_player.py”, line 105, in setup_platform
device_class=config[CONF_DEVICE_CLASS])
File “/usr/local/lib/python3.7/site-packages/androidtv/init.py”, line 53, in setup
aftv.device_properties = aftv.get_device_properties()
File “/usr/local/lib/python3.7/site-packages/androidtv/androidtv.py”, line 151, in get_device_properties
wifi_out = self.adb_shell(‘ip addr show wlan0’)
File “/usr/local/lib/python3.7/site-packages/androidtv/basetv.py”, line 99, in _adb_shell_python_adb
return self._adb.Shell(cmd)
File “/usr/local/lib/python3.7/site-packages/adb/adb_commands.py”, line 376, in Shell
timeout_ms=timeout_ms)
File “/usr/local/lib/python3.7/site-packages/adb/adb_protocol.py”, line 411, in Command
return ‘’.join(cls.StreamingCommand(usb, service, command, timeout_ms))
File “/usr/local/lib/python3.7/site-packages/adb/adb_protocol.py”, line 439, in StreamingCommand
for data in connection.ReadUntilClose():
AttributeError: ‘NoneType’ object has no attribute ‘ReadUntilClose’

Any other info I can offer here? No t sure where to start troubleshooting. This is on a new hassio vm install. Everything else seems to work fine after migrating from the docker.

1 Like

This is covered in the documentation, although it wasn’t as clear as I thought it was so I submitted a pull request to make it more clear.

https://deploy-preview-9012–home-assistant-docs.netlify.com/components/androidtv#adb-troubleshooting

The Python ADB implementation isn’t working for your device, so you need to use the ADB server approach.

1 Like

Thanks for that. I was under the impression that I had to use the add on for adb under hassio. That’s how I set it up. I didn’t add the adb server IP. Now that I’ve done that it’s all good. Thanks for the quick help.

Not sure wether I’m correct in this thread as I’m trying to use Home Assistants “native” component with FireTV support (introduced in 0.90). But I ran into an issue when trying to set it up. Posted about it here, maybe you can have a look?

I’m getting the same errors.

Did you use the server method by installing the ADB addon? @capstan1 looks like you have the Android TV addon configured to use the server so I just wanted to make sure you had the server set up and configured. You also need to make sure the server is able to connect to your devices. The device will prompt to trust this computer. If that doesn’t happen, then that’s your issue.

I have Hassio 90.1, ADB - Android Debug Bridge 0.3.0 installed.

ADB Bridge log:

[20:48:24] INFO: Connecting to device: 192.168.1.189…
connected to 192.168.1.189:5555

I accepted the auth on the TV so it looks they are communicating.

But in the Hassio log:

2019-03-25 20:49:45 ERROR (MainThread) [homeassistant.components.media_player] Error while setting up platform androidtv
Traceback (most recent call last):
File “/usr/local/lib/python3.7/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.7/asyncio/tasks.py”, line 416, 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/local/lib/python3.7/site-packages/homeassistant/components/androidtv/media_player.py”, line 115, in setup_platform
device_class=config[CONF_DEVICE_CLASS])
File “/usr/local/lib/python3.7/site-packages/androidtv/init.py”, line 53, in setup
aftv.device_properties = aftv.get_device_properties()
File “/usr/local/lib/python3.7/site-packages/androidtv/androidtv.py”, line 152, in get_device_properties
wifimac = re.findall(WIFIMAC_REGEX_PATTERN, wifi_out)[0]
IndexError: list index out of range

Any idea to fix? I googled it but that just caused me more confusion…
Thanks

I have Hassio 90.1, ADB - Android Debug Bridge 0.3.0 installed.

If i edit out the philipstv section below then the shieldtv is picked up and works great, if I include the philipstv section I get the errors below and neither devices are picked up…any ideas? I have had the secure box popup on both tv’s and have accepted the connection permanently.

configuration.yaml:

  • platform: androidtv
    host: 192.168.10.35
    name: ShieldTV
    adb_server_ip: 127.0.0.1
    apps:
    com.google.android.tvlauncher: “Home”
    com.google.android.youtube.tv: “Youtube”
    com.amazon.amazonvideo.livingroom: “Amazon Prime Video”
    com.plexapp.android: “Plex”
    com.netflix.ninja: “Netflix”

  • platform: androidtv
    host: 192.168.10.31
    name: PhilipsTV
    adb_server_ip: 127.0.0.1
    apps:
    com.google.android.tvlauncher: “Home”
    com.google.android.youtube.tv: “Youtube”
    com.amazon.amazonvideo.livingroom: “Amazon Prime Video”
    com.plexapp.android: “Plex”
    com.netflix.ninja: “Netflix”

ADB Bridge log:

[22:58:13] INFO: Starting the Android Debug Bridge server…
error: could not install smartsocket listener: Address already in use
[22:58:14] INFO: Starting the Android Debug Bridge server…
error: could not install smartsocket listener: Address already in use

repeats…

if I restart app then the error goes and connects to both shieldtv & philipstv

the hassio log:

Error while setting up platform androidtv
Traceback (most recent call last):
File “/usr/local/lib/python3.7/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.7/asyncio/tasks.py”, line 416, 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/local/lib/python3.7/site-packages/homeassistant/components/androidtv/media_player.py”, line 119, in setup_platform
if not aftv.available:
File “/config/deps/lib/python3.7/site-packages/androidtv/basetv.py”, line 218, in available
adb_devices = self._adb_client.devices()
File “/config/deps/lib/python3.7/site-packages/adb_messenger/command/host/init.py”, line 19, in devices
result = self._execute_cmd(cmd)
File “/config/deps/lib/python3.7/site-packages/adb_messenger/command/host/init.py”, line 10, in _execute_cmd
conn.send(cmd)
File “/config/deps/lib/python3.7/site-packages/adb_messenger/connection.py”, line 77, in send
return self._check_status()
File “/config/deps/lib/python3.7/site-packages/adb_messenger/connection.py”, line 80, in _check_status
recv = self._recv(4).decode(‘utf-8’)
File “/config/deps/lib/python3.7/site-packages/adb_messenger/connection.py”, line 56, in _recv
return self.socket.recv(length)
ConnectionResetError: [Errno 104] Connection reset by peer


Its great on the shieldtv, but frustrating that the philips won’t work especially as its just had a major update to the android interface (now same as shieldtv)

I’ve found that restarting the TV (not just turning off and on) and restarting hassio gets it to reconnect. Not ideal, but I have 5 Android TV’s so I was able to check as this happened in different sets multiple times.

I fixed this in the next release. In the meantime, you can use it as a custom component.

Thanks for your reply @panteragstk ! The addon is connecting succesfully:

[06:48:18] INFO: Connecting to device: 192.168.0.7…
connected to 192.168.0.7:5555

So my Mibox3 has been an absolute pain with this and the ADB binaries. Everything would work fine while it was on, but would constantly either drop connection or take about 30 secs per update cycle, fail to respond or just go into a reconnect loop when it was switched off. Testing with from the command line showed either horrible response times or a timeout.

And it finally dawned on me why! F#*king Android Doze! The damn thing is dropping into battery saving mode, throttling the cpu and dropping the wifi into “location and whitelisted apps only” mode.

One quick install of Wake Lock v3 on the Mibox, set to autostart and keep full CPU and Wifi locks, and everything works like magic…

I should just learn by now, if something is acting odd on Android, it’s probably Doze mode…

Now I’m off to test if that fixes the builtin adb server too…

Edit: Yes, yes, it looks like it does… Goddamn power saving…

2 Likes

I have Hassio 0.90.2 , ADB - Android Debug Bridge 0.3.0 installed.
This components work fine with my phone, but not with my androidtv

ADB Bridge log:

[18:23:02] INFO: Connecting to device: 192.168.1.10...
connected to 192.168.1.10:5555

But in Hassio Log i get this

Error while setting up platform androidtv
Traceback (most recent call last):
File “/usr/local/lib/python3.7/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.7/asyncio/tasks.py”, line 416, 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/local/lib/python3.7/site-packages/homeassistant/components/androidtv/media_player.py”, line 115, in setup_platform
device_class=config[CONF_DEVICE_CLASS])
File “/config/deps/lib/python3.7/site-packages/androidtv/init.py”, line 34, in setup
return AndroidTV(host, adbkey, adb_server_ip, adb_server_port)
File “/config/deps/lib/python3.7/site-packages/androidtv/androidtv.py”, line 59, in init
self.device_properties = self.get_device_properties()
File “/config/deps/lib/python3.7/site-packages/androidtv/androidtv.py”, line 152, in get_device_properties
wifimac = re.findall(WIFIMAC_REGEX_PATTERN, wifi_out)[0]
IndexError: list index out of range

How i can fix this?