But you said the error messages are still there…
Sorry, they disappeared after another restart of HA.
It’s actually doable, one trick is to check the state of the audio output tracks, if there is audio comming out then the state is playing.
Although I couldn’t manage to get more info, like current playing media metadata. One way I thought about is with the notification system, I don’t if it’s everywhere the same but on my Mibox I have a now playing notification with everything needed. Though I could’t find anything from an ADB command to fetch it. Will continue to look!
Hey, if I can get media state & ability to pause/play that’s good enough for me.
Depending on how the media state is read, the results may differ between platforms. From what I gathered earlier when trying to find a way to properly detect the state changes, the best way would be to see if the screen is awake and/or if the volume control is active. However, the latter requires that the app doing the playback is using the common android media api (whose name eludes me currently), but that’s the most effective way to check if there is something being played.
yeah well that doesn’t happen much…
Installed this as a custom component and it works fine, once the adb connect is issued everytime I restart HA
Is there any way to make that happen, if I do a script that runs at startup, it would require to have the box started.
Which custom_component did you install? And can you provide a step-by-step guide?
This one, from A1ex4 : https://github.com/home-assistant/home-assistant/pull/16975
Put the androidtv.py in custom_component/media_player.
In the configuration, I have created a media_player (amongst others) :
media_player: - platform: androidtv host: !secret boxtv_host name: 'Box TV'
Restart HA, it won’t work.
Then on your server, you must have adb installed. (I have an Ubuntu 18.04 Server)
Open the connection :
adb connect <ip address>
Of course, if the box isn’t in the same network, you’ll have to ensure port 5555 is routed through the firewall if any.
The box should ask to confirm the adb connection, I’ve checked the ‘never ask again’ option.
adb devices should return :
# adb devices List of devices attached 192.168.9.12:5555 device
And it works perfectly until I restart HA or the box, then I have to repeat the adb connect instruction.
So, if I’m running hassio on a pi, I would run the adb connect
command directly on the pi? Not sure how I would do that since ssh AFAIK only gives me access to the hassio cli.
As per your issue, I’m sure there has to be some way to automate the connect/reconnect, but I’m not well-enough versed in python when it comes to the HA environment (otherwise, sure) or adb (in general) to help with that unfortunately. But, I’m very interested in this feature (auto-connect/reconnect) being implemented as well.
Actually, I don’t quite understand your issue after looking at the androidtv.py
file & pure-python-adb
module (which is what the component uses). According to the pure-python-adb
's README the component should be able to automatically connect. See this line in the androidtv.py
which should automatically connect to the device. So, I’m not seeing why you’re having to use the adb connect <ip address>
command on your server. Unless I’m missing something?
Your config does not seem to match what is shown in the PR.
What do you mean ? I use the secret file, but this is parsed long before the component works ?
It is ok, as long as the adb connection is made (manual)
Me neither, that’s why I posted the question here
The adb library should do the adb connect by itself.
I found a workaround that should work even for the hass.io. The idea is to run the adb connect command when I detect the box comes on the network, using the device tracker.
First, do a shell command :
shell_command:
adb: '/usr/bin/adb connect {{ ip_adb }}'
Now the automation :
- alias: 'A_ ADB start' trigger: platform: state entity_id: device_tracker.box_tv to: 'home' condition: - condition: state entity_id: media_player.box_tv state: 'Unavailable' action: - service: shell_command.adb data_template: ip_adb: '192.168.9.12'
The condition is probably not necessary !
I still haven’t tried the component out yet for a few reasons.
- The Pi I’m going to be using for the brain of my setup is being kept packed away (after I set-up the basics on it already) until we move into a house.
- I haven’t used my android box in a little while
- I notice there’s a lot of nuances & variations/tweaks needed for the component to accurately detect media-state dependent on the apps playing the media. If you have a look at the PR you’ll see how others have reported said nuances.
- Lastly, I kind of really wanted to wait until the component was ready for prime time/the PR was merged and the component became “official.” There’s no telling how long it’ll be until then and the author of the component just moved, so the odds of any further dev on it in the near future appear very slim unless someone else steps up and offers to contribute to the project.
Well, even if I could do some basic dev for my own use, I won’t put others at risk publishing officially
I’ve been using this for a couple of weeks and it’s working fine, using the automation to create/maintain the adb connection.
It can handle any media application that exposes itself, mostly Plex and Netflix (which is a pain to control with the IR remote on a non-androidTV device).
Sure, there must be a lot more that can be done, display the title that is playing for a start. But still, the media_player component has its limits too.
I was trying to mess with it for the first time last night and couldn’t even get adb to work on my windows computer. From everything I’ve read the only way to initiate the initial connection is via physically connection (USB), which is a big turn-off for me. Did you manage to get adb to connect without first using direct USB connection to the server?
you remember the name, it should be possible to download apk somewhere
I don’t.
Did a quick search and found CastReceiver, but that’s very limited and won’t do the job for the requirement here.
FYI, I created a thread to discuss the androidtv component, you should be able to try it now.
How to create that device_tracker.box_tv? Wifi? BT? Or what?