Adding the FireTV doesn't work

Hey,

so I wanted to add my Nvidia Shield and FireTV. I connected to both via my PC and transfered the adbkey-file to the config folder (using Docker).

Since then it connects to my Shield just fine, just not my FireTV.

2019-05-31 11:25:47 WARNING (SyncWorker_8) [root] Couldn't connect to host: 192.168.178.27:5555, error: Broken pipe
2019-05-31 11:25:48 WARNING (SyncWorker_8) [homeassistant.components.androidtv.media_player] Could not connect to FireTV at 192.168.178.27:5555 using Python ADB implementation with adbkey='/config/adbkey'
2019-05-31 11:26:19 INFO (MainThread) [homeassistant.components.media_player] Setting up media_player.androidtv
2019-05-31 11:26:19 WARNING (SyncWorker_19) [homeassistant.components.androidtv.media_player] Could not connect to FireTV at 192.168.178.27:5555 using Python ADB implementation with adbkey='/config/adbkey'
2019-05-31 11:26:19 WARNING (MainThread) [homeassistant.components.media_player] Platform androidtv not ready yet. Retrying in 60 seconds.

The config:

- platform: androidtv
  name: FireTV
  device_class: firetv
  host: 192.168.178.27
  adbkey: "/config/adbkey"
  apps:
    com.amazon.tv.launcher: "Fire TV"
  turn_on_command: "input keyevent 3"
  turn_off_command: "input keyevent 223"

- platform: androidtv
  name: Nvidia Shield
  device_class: androidtv
  host: 192.168.178.21
  adbkey: "/config/adbkey"

Try this as a custom component. If that doesn’t work, you’ll need to use the ADB server approach.

https://github.com/JeffLIrion/home-assistant/tree/patch-19/homeassistant/components/androidtv

2 Likes

Also,

  1. When you connected via your PC, you should have told it to always allow connections from this computer. If not, you need to do that.
  2. Make sure you restart the Fire TV.
1 Like

Thank you for replying.

I just restarted and now the error is a different one:

2019-06-02 09:19:13 ERROR (SyncWorker_19) [homeassistant.components.androidtv.media_player] Failed to execute an ADB command. ADB connection re-establishing attempt in the next update. Error: 'NoneType' object has no attribute 'ReadUntilClose'

Shall I try the component or is the error about something different?

EDIT: It seems to be detected and I added the custom_component. Will see if the automation tonight triggers, thx. Not too sure if the error re-occurs and what it is.

Has the connection to your Fire TV been stable?

1 Like

No… sadly not really. It was stable in the evening, we went to sleep while it was running and on the next day it was all day unavailable. Also when turning it back on again it was unavailable. I didn’t try restarting it, because that is not usable IMO.
Also my Nvidia Shield becomes unavailable like every minute which makes some automations pretty useless.

I was just about to test an adb server but that doesn’t seem to work at all for whatever reason.
Using still the adbkey from my pc mounted into the container just like described here https://github.com/codeskyblue/adb

04-06-2019:14:12:13,18 DEBUG    [connection.py:24] Connect to adb server - raspberry:5037
04-06-2019:14:12:13,29 DEBUG    [connection.py:24] Connect to adb server - raspberry:5037
04-06-2019:14:12:13,33 DEBUG    [connection.py:75] b'000Chost:devices'
04-06-2019:14:12:13,36 DEBUG    [connection.py:75] b'000Chost:devices'
04-06-2019:14:12:13,38 DEBUG    [connection.py:47] Connection closed...
04-06-2019:14:12:13,40 DEBUG    [connection.py:47] Connection closed...
04-06-2019:14:12:13,41 DEBUG    [connection.py:24] Connect to adb server - raspberry:5037
04-06-2019:14:12:13,43 DEBUG    [connection.py:24] Connect to adb server - raspberry:5037
04-06-2019:14:12:13,46 DEBUG    [connection.py:75] b'000Chost:devices'
04-06-2019:14:12:13,49 DEBUG    [connection.py:75] b'000Chost:devices'
04-06-2019:14:12:13,51 DEBUG    [connection.py:47] Connection closed...
2019-06-04 14:12:13 WARNING (SyncWorker_13) [homeassistant.components.androidtv.media_player] Could not connect to FireTV at 192.168.178.27:5555 using ADB server at raspberry:5037
04-06-2019:14:12:13,55 DEBUG    [connection.py:47] Connection closed...
2019-06-04 14:12:13 WARNING (MainThread) [homeassistant.components.media_player] Platform androidtv not ready yet. Retrying in 180 seconds.
2019-06-04 14:12:13 WARNING (SyncWorker_12) [homeassistant.components.androidtv.media_player] Could not connect to Nvidia Shield at 192.168.178.21:5555 using ADB server at raspberry:5037
2019-06-04 14:12:13 WARNING (MainThread) [homeassistant.components.media_player] Platform androidtv not ready yet. Retrying in 180 seconds.

Do you have the logs from when you were using the Python ADB implementation?

1 Like

No because my auto-updater updated the image last night at 4 and then my changes to adb server from yesterday went active.

But since it isn’t working at all anymore I just changed back again and the first that is being presented is:

2019-06-04 19:52:27 WARNING (SyncWorker_6) [homeassistant.components.androidtv.media_player] Could not connect to Nvidia Shield at 192.168.178.21:5555 using Python ADB implementation with adbkey='/config/adbkey'
2019-06-04 19:52:27 WARNING (SyncWorker_18) [homeassistant.components.androidtv.media_player] Could not connect to FireTV at 192.168.178.27:5555 using Python ADB implementation with adbkey='/config/adbkey'

The manual connection from pc to Shield works fine tho, the connection to FireTV says “failed”.

Each device (Fire TV and Android TV) will only allow for one connection. If you connected from one computer and you want to connect from another, you need to reboot the Fire TV / Android TV device. Similarly, if you connected via the adb binary and now you want to connect using Python, you need to reboot your device.

But as long as you’re using the same computer and the same method for connecting, you shouldn’t need to reboot the device to reconnect.

2 Likes

It appears there was another update last night and now the devices appear available again.
However my Shield becomes unavailable all the time and that is not usable…
I will test the FireTV again tonight then.

Do you have any suggestions what that could be about? I do plan some network changes for the near future but I’m afraid that is not gonna help since that should not be an connection issue.

CORRECTION: I just tested if it is recognized as available and actually turns on via HASS, which it does, but it becomes unavailable as well as the Shield…

Here is the log. The first line is getting repeaten all the time the devices become unavailable and the other lines about the remote id are appearing for both devices as well for whatever reason, looks like they’re just counting upwards.

2019-06-05 17:23:34 ERROR (SyncWorker_3) [homeassistant.components.androidtv.media_player] Failed to execute an ADB command. ADB connection re-establishing attempt in the next update. Error: 'NoneType' object has no attribute 'ReadUntilClose'
2019-06-05 17:24:51 ERROR (SyncWorker_12) [homeassistant.components.androidtv.media_player] Failed to execute an ADB command. ADB connection re-establishing attempt in the next update. Error: Incorrect remote id, expected 4347 got 4346
2019-06-05 17:25:48 ERROR (SyncWorker_17) [homeassistant.components.androidtv.media_player] Failed to execute an ADB command. ADB connection re-establishing attempt in the next update. Error: Incorrect remote id, expected 4351 got 4350
2019-06-05 17:26:04 ERROR (SyncWorker_9) [homeassistant.components.androidtv.media_player] Failed to execute an ADB command. ADB connection re-establishing attempt in the next update. Error: Incorrect remote id, expected 4353 got 4352
2019-06-05 17:26:09 ERROR (SyncWorker_9) [homeassistant.components.androidtv.media_player] Failed to execute an ADB command. ADB connection re-establishing attempt in the next update. Error: Incorrect remote id, expected 4355 got 4356

Thanks for the logs and info. Assuming you’re using the custom component, this indicates that the patch to the adb Python package didn’t fix all the issues. I looked at the code, but it’s complicated and it wasn’t clear how to fix it. So it looks like you need to use an ADB server in order to integrate these devices.

1 Like

Thx for info.

Regarding my answer from 2 days ago, it looks like that I’m unable to get the adb server working. I also posted the logs of the happening within hass. Any idea?

From this post it doesn’t look like the ADB server was connected to your devices. This page might contain some helpful info: ADB server setup.

1 Like

Thank you! I will definitely look into it on the weekend. Tho I removed the custom media_player and it has at least less “unavailableness” with 0.94 than before.

Hey,

so it looks like we can close the connection issue. both seem to work fine now except some minor detection issues with Plex on the FireTV.

However it looks like the FireTV doesn’t react to source changes from within the HASS UI and the Shield doesn’t show an select drop down while I have “apps:” configured. Is that just to recognize Apps by Name or should be able to select the app to start? Or else how would I manage that?

Thx.

For Fire TV devices, the running apps should populate the sources list and selecting an app should open it. However, this latter part doesn’t seem to work for some people and some apps. I don’t know if there’s a universal way to launch apps.

Source selection isn’t implemented in this way for Android TV devices.

The apps configuration parameter only affects the app_name attribute, making it so that the UI shows, for example, “Plex” instead of “com.plexapp.android.”

You can send custom commands to launch apps or do whatever you’d like using the androidtv.adb_command service. Examples can be seen here.

1 Like

Got that. Thx.

One thing I’m right now coming across and is hell of annoying using docker logs -f, is the spamming of those entries:

14-06-2019:17:05:10,21 DEBUG    [connection.py:24] Connect to adb server - 127.0.0.1:5037
14-06-2019:17:05:10,59 DEBUG    [connection.py:24] Connect to adb server - 127.0.0.1:5037
14-06-2019:17:05:10,74 DEBUG    [connection.py:75] b'0022host:transport:192.168.178.21:5555'
14-06-2019:17:05:10,90 DEBUG    [connection.py:75] b"014Ashell:dumpsys power | grep 'Display Power' | grep -q 'state=ON' && echo -e '1\\c' && dumpsys power | grep mWakefulness | grep -q Awake && echo -e '1\\c' && dumpsys power | grep Locks | grep 'size=' && (dumpsys media_session | grep -m 1 'state=PlaybackState {' || echo) && dumpsys window windows | grep mCurrentFocus && dumpsys audio"
14-06-2019:17:05:10,124 DEBUG    [connection.py:47] Connection closed...
14-06-2019:17:05:10,134 DEBUG    [connection.py:24] Connect to adb server - 127.0.0.1:5037
14-06-2019:17:05:10,138 DEBUG    [connection.py:24] Connect to adb server - 127.0.0.1:5037
14-06-2019:17:05:10,152 DEBUG    [connection.py:75] b'0022host:transport:192.168.178.27:5555'
14-06-2019:17:05:10,168 DEBUG    [connection.py:75] b"014Bshell:dumpsys power | grep 'Display Power' | grep -q 'state=ON' && echo -e '1\\c' && dumpsys power | grep mWakefulness | grep -q Awake && echo -e '1\\c' && dumpsys power | grep Locks | grep 'size=' && (dumpsys media_session | grep -m 1 'state=PlaybackState {' || echo) && dumpsys window windows | grep mCurrentFocus && ps | grep u0_a"
14-06-2019:17:05:10,253 DEBUG    [connection.py:47] Connection closed...

My logger is already set to default warning.

This pull request should fix that: https://github.com/Swind/pure-python-adb/pull/14

But I don’t know if/when it will get merged in to that library.

1 Like

That sounds already pretty great. Will wait then.

Another thing that is still happen to me is, using Plex on the FireTV won’t change the state to playing. Looking at the history from yesterday again, it went from off to standby when we were watching Plex and after I fell asleep my wife changes to Netflix where it updates the state just fine to “playing”. Altough plex reacts to the play/pause button in the HASS UI accordingly.
Also Plex doesn’t have this problem on the shield.

State detection is a known issue that requires help from the community. (Also, it works slightly differently between Android TV and Fire TV devices.)

https://github.com/JeffLIrion/python-androidtv/issues/12

This package determines the state in the AndroidTV.update / FireTV.update methods using a collection of properties and reports that state to Home Assistant. You can see what those properties are by using the HA service androidtv.adb_command with "GET_PROPERTIES" as the command argument – they will be logged at the INFO level and they will be stored in the media player’s adb_response attribute (HA 0.94+), which can easily be viewed on the States tab. You can read more about the androidtv.adb_command service at the bottom of the Android TV documentation.

The state detection logic will differ depending on the app. So open an app, send the "GET_PROPERTIES" command a few times while it’s idle / on standby, playing, and paused, and try to figure out a better way to determine the state. Pull requests are welcome!

1 Like