media_player:
- platform: androidtv
name: MEDIA PLAYER NAME
host: 192.168.0.111
# optional config entries: apps, device_class, state_detection_rules, turn_on_command, turn_off_command
Do not include adbkey or adb_server_ip in your config
Instructions
If you are running an ADB server, stop it
Reboot your Android TV / Fire TV device
Turn on your Android TV / Fire TV device, then reboot HA
You should see a pop-up on your TV asking if you want to trust this computer. Click yes. You should have 60 seconds to do this. If you have less time, please let me know. If you wait longer than 60 seconds, please tell me what happens.
Details (for those interested)
There are two ways to communicate with Android TV / Fire TV devices:
This was not reliable for newer devices, but it should be fixed in HA 0.100
Currently, this requires you to connect to the device and copy the key to your HA config before it can be integrated
What this custom component does is generate the key for you and allow you 1 minute to approve the connection, avoiding all of the setup necessary for the Python ADB approach. The generated key is stored as <config>/.storage/androidtv_adbkey.
I have a pull request that adds this functionality to HA, but before it gets reviewed I need to know if this actually works.
Ok, makes sense… but how to install this? …adding the hacs-url as repo didn’t add it, sorry if this is a stupid question but I’m still quite new to hass
Hey @JeffLIrion, I installed the custom component via method 2. I tested one scenario but now I’m at a standstill because the Fire TV is refusing ADB connections to HA after the first failed attempt. More on that later.
Tested on:
Amazon Fire TV Stick 4K
Home Assistant 0.99.3 via Hass.io on Docker
I tested to see what would happen if I waited over 60 seconds before accepting the ADB connection on the Fire TV.
COnfigured FIre TV to WiFi, set static IP (on router side), and accept ADB connections
I copied the \androidtv folder to \customcomponents
Added AndroidTV configuration to configuration.yaml
Restarted Home Assistant
After HA restarted, the pop-up appeared on the Fire TV to accept the ADB connection.
I waited ~65 seconds before accepting the ADB connection and closing the pop-up.
The Fire TV was not added to Home Assistant (as expected)
Sounds like this scenario is working as planned. Now, I wanted to test what would happen if I accepted the ADB connection in under 60 seconds. However, the pop-up dialog no longer appears even after restarting Home Assistant. What do I need to do to attempt the ADB connection again?
I can see this being a problem for people who miss the 60-second window to approve the ADB connection. Some additional instructions or log messages would help me out.
Edit: forget what I said earlier about the Fire TV no longer connecting to Home Assistant. After taking a break for an hour, I see the Fire TV in the Home Assistant UI now. I’ll test again after deleting the androidtv_adbkey files.
I was going to suggest deleting the config/.storage/androidtv_adbkey files and trying again.
Edit: it may be because HA tried to setup the component again too soon (probably before a minute had even elapsed). I think when it fails multiple times to setup a component, it waits longer between retries. Maybe that’s why it worked an hour later?
Yes, it worked. Though is that the expected result when waiting over a minute before accepting the ADB connection pop-up? I think it’s fine…
For my second test, I deleted the androidtv_adbkey files, restarted HA, accepted the Fire TV ADB connection pop-up, and the Fire TV appeared as a media player in Home Assistant. It works!
I’ll do more testing to see whether the Fire TV stays connected to Home Assistant. I used the previous custom component of yours and had some issues where the Fire TV entity would disappear from Home Assistant. I’ll need to look more into that and get back to you.
I want to say i installed your custom component on a different HA instance and Fire TV a week ago. I’ll test again with your latest component soon.
Anyways, to see if I could replicate the issue I let the Fire TV play a video off of Amazon Prime. Didn’t see any issues and the Fire TV state was reporting Paused which is accurate enough for me. There were a few times when the Fire TV state went to Unavailable, but it didn’t happen during playback.
I thought I fixed the issue where the device would become unavailable… If you collect debug logs, I’ll take a look at them. Just set the log level via the logger.set_level service:
2019-10-11 08:17:12 ERROR (SyncWorker_15) [custom_components.androidtv_2.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-10-11 08:17:45 ERROR (SyncWorker_13) [custom_components.androidtv_2.media_player] Failed to execute an ADB command. ADB connection re-establishing attempt in the next update. Error: Incorrect remote id, expected 4 got 3
2019-10-11 08:18:07 ERROR (SyncWorker_15) [custom_components.androidtv_2.media_player] Failed to execute an ADB command. ADB connection re-establishing attempt in the next update. Error: ('Unknown command: 54525731', 1414682417, (1093, 256))
2019-10-11 08:18:29 ERROR (SyncWorker_6) [custom_components.androidtv_2.media_player] Failed to execute an ADB command. ADB connection re-establishing attempt in the next update. Error: ('Unknown command: 615731ba', 1633104314, (1277191531, 1936417647))
2019-10-11 08:18:51 ERROR (SyncWorker_0) [custom_components.androidtv_2.media_player] Failed to execute an ADB command. ADB connection re-establishing attempt in the next update. Error: ('Unknown command: 6f6f672e', 1869571886, (778398823, 1919184481))
You’re not using the custom component. I can tell because there is no 'ReadUntilClose' method used in the custom component, only in the built-in component up until HA 0.100.