I probably should have written up my previous investigation on this already, but this is indeed the proper way to handle the states (I was thinking about having a simple app to track the states and do push updates to homeassistant). The problem at that point was (it may have been a year since I looked at it last time) that many of the apps do not use the media session (my experiences on Kindle FireTV stick) for controlling even when the API has been there since Android 4.0.
Thanks for the info! I recall reading something similar, perhaps for the Android TV component: there is an API for determining playback state, but many apps don’t adhere to it.
I believe the Android TV component tries to accomplish this task of state detection by using info about the audio output. If you’re interested, you could look at the component that I’ve previously linked to or the thread in this forum.
My opinion is that it’s not reasonable to expect the component to always detect the correct state. (But if someone wants to try to achieve that, their efforts are certainly welcome!) I also don’t think that differentiating between playing, paused, and idle states is a big deal, at least not for my use cases. The component can detect whether it’s on/off, send basic commands (most importantly power on/off and play/pause), and launch apps. That’s good enough for me
Basic support is fine, I’m not arguing on that, however, having the ability to, e.g., control the lights based on the play state is somewhat popular application I just wanted to leave the note behind in case someone is digging already on the topic or wants to improve it, unfortunately I have personally no time to further it at this point.
I just posted this in two other threads, but here it is again.
Regarding the Fire TV component, this is already implemented in my custom component. I’m working on getting it integrated into the official component.
Configuration example:
media_player:
- platform: firetv
name: Fire TV
host: 192.168.0.111
adb_server_ip: 127.0.0.1
Comparing the Fire TV and Android TV components, I haven’t tried the Android TV component, but there are some device-specific tweaks and so I expect that each component will work better for its intended devices.
@JeffLIrion
I’m getting the same as @forums2012 above.
Remains in paused state when app is open and playing, though it doesn’t seem to recognise Plex, nor does it pull a list of apps.
State detection has its limitations. It can’t always determine playback status accurately.
As for the list of running apps, please delete any firetv and firetv* folders in the deps folder in your configuration directory and then restart Home Assistant. This will cause it to install the latest version of the package from GitHub. Please let me know if that fixes the running apps!
Ahhh cheers.
Well, after doing that it picked up the Plex app, so that’s progress.
Can select Plex, play, pause, forward, back.
Can’t power on though. Ah well. May require a little more figuring out on my end.
Gotcha. That worked. Can now turn on via the component.
Looks like it’s just picking up whatever app it first detects.
Eg
if the firetv is off when I restart hass, when it turns it on it detects the home.
If the firetv is on with an app open when I restart hass, it just detects that app in sources.
Afraid not.
tested with no apps running, restarted hass, and it just saw the launcher.
Tried with multiple apples running, restarted hass, and it only had plex in the list (though multiple were running but i was at the launcher)
I am running using an adb server rather than built in if that helps
Yep that worked.
Showed running apps in source though if app hasn’t been started then didn’t appear until it had been started on the fire.
Would it not make more sense for source to list installed apps instead? Allowing HA to open apps that aren’t already running in background?
"pm list packages -3"|cut -f 2 -d ":"
^ would list user installed apps, then adding known pkgs such as com.amazon.tv.launcher and other preinstalled apps would be a more useful sources list would it not?
I guess pushing aapt to a temporary directory on the device to be able to get an array of these app id’s and their friendly names would be a step too far though…