It’s using the Python ADB implementation to connect, not the ADB server (otherwise the log message would differ). What does your configuration look like? It should include adb_server_ip. If it does, then I suspect the current built-in component is being used, not this custom component. Perhaps with the restructuring of the custom component/platform directory structure, something needs to change in the configuration?
First off, thank you. I just purchased an Insignia Fire TV edition to replace my old TV and Fire TV Gen2, and was saddened to find that the standard firetv component (https://www.home-assistant.io/components/media_player.firetv/) couldn’t control or even connect to the new Insignia TV. I managed to install your custom component and the ADB server on Hass.io, and it’s connecting!
I too am wondering about the play/pause status as it seemed to register properly using the standard firetv component. I realize you know more than I do on this subject, so I trust when you say it’s a limitation of adb commands. I just found it odd that the standard component seemed to recognize play.pause. Thanks again!!
This component works by polling your Fire TV device at regular intervals. It uses the output of ADB commands to determine properties – namely, screen_on, awake, wake_lock_size, and current_app – and uses these to predict the state of the device. The result will be the same regardless of whether you’re using the Python ADB implementation or an ADB server. This method works well for detecting whether the device is off or idle (i.e., in screensaver mode). However, it is not so accurate when it comes to detecting whether or not the device is playing, paused, or on standby. This is a difficult task, since not all Fire TV apps adhere to the same API (as I understand it) and also because many apps aren’t for playing videos at all, and so this state detection doesn’t really apply.
The code that does the state detection has been moved into the firetv package in the update function. If you’d like to try to improve it, you can use the media_player.firetv_adb_cmd service to send ADB commands to the device and view their output, if any, in the Home Assistant log (logging level = INFO). For example, if you send the command
(which is the concatenation of the SCREEN_ON_CMD and SUCCESS1_FAILURE0 strings), then the output will be “1” if the device is on and “0” if it is off. It may be necessary to determine the state differently depending on the current app, as indicated by the “TODO” in the update function.
You’re welcome to submit pull requests with improved state detection to the firetv repository.
I’m going to step away from this project for personal reasons. While it’s been fun tinkering and trying to make this component as good as possible, I simply have more important things that I need to focus on right now.
Before signing off, here’s where things are at.
Pull requests
I was hoping to get the latest changes integrated into Home Assistant before the next release, especially because I think the changes to the structuring of custom components may cause issues for people. Unfortunately, my pull requests haven’t gotten approved yet, so I think this will have to wait. Here are my current and planned pull requests.
Originally, I was going to submit this after pull request #1 had gone through, under the assumption that it would be easier to get two smaller PRs approved. However, after waiting a few days I decided to submit this before #1 had been merged, thinking that this demonstrated a reason for bumping the version of the firetv package and would perhaps be more likely to get reviewed and approved. It contains all of the changes in the first pull request, so whether it gets approved on its own or whether it gets approved after #1 makes no difference.
(Planned pull request) Register ‘media_player.firetv_adb_cmd’ service. I haven’t yet submitted a pull request for this, since it depends on pull request #2. This links to a branch of my home-assistant repo that contains all the changes that I intended to submit as a pull request. In addition, here is a link to a branch of my home-assistant.io repo that contains the corresponding documentation update: firetv_adb_cmd documentation.
This component is effectively the same as the final version that I had planned for the built-in component, with the one difference being that it is backwards compatible.
Help wanted
If someone could please see these changes through to completion and integration into Home Assistant, that would be much appreciated.
I have a Gen2 (1K). I’m not using the add-on, so it may be different…but I would think not very much different. I also have to use the Android Debug Bridge to build the keys and such.
Tried the native way again (getting the keys using Android Debug Bridge) and then using the configuration you are showing.
FireTV Shows up in Lovelace and I can control it once, then it disconnects and won’t reconnect until I restart HA. It’s the same as described here.
It’s not seeing your custom component due to how they are picked up now, so it’s not overwriting the inbuilt one.
Should be called media_player.py in a folder named after the component, so…
@jaaem what does your yaml look like? I also noticed that you need to run adb connect <IP> on the device you wish to connect with in order for it to connect.
Thanks. I edited a version of the docker script, and it seems to work now. I only hard coded one device, but hopefully it will work
#!/bin/bash
DEVICES=(192.168.1.167)
echo "Starting up ADB..."
while true; do
adb -a server nodaemon > /dev/null 2>&1
sleep 10
done &
echo "Server started. Waiting for 30 seconds..."
sleep 30
echo "Connecting to devices."
for device in $DEVICES; do
adb connect $device
done
echo "Done."
while true; do
for device in $DEVICES; do
adb connect $device > /dev/null 2>&1
done
sleep 60
done
This unfortunately has been a headache and a half trying to get it work with HA. Both HA and ADB containers are running in unraid. If I just pull sorccu/adb container and then manual connect and restart ha. It connects np. Once I try adding a script for it to auto connect it does connect np but HA will not connect to adb at all. So stuck with this. This is the script im using. The Jaaem one I tried but the container just shuts down right away.
#!/bin/sh
sleep 5
DEVICES="192.168.0.206"
echo "Connecting to devices."
for device in $DEVICES; do
adb connect $device
done
echo "Done."
while true; do
for device in $DEVICES; do
adb connect $device > /dev/null 2>&1
done
sleep 60
done
Regarding your script, you might need to wait until HA recognizes that the device is on before calling the media_player.select_source service. You can do that via:
- wait_template: "{{ not is_state('media_player.fire_4k_tv', 'off') }}"
timeout: 00:00:10
To find out the app_id, open the app and look at the app_id attribute for the media player on the states page.