AndroidTV Binding [3.2.0;4.2.0)

@mhilbush with great pleasure. However, I am not sure if I will be able to change directory to userdata to run the second command since access to directorys within the docker is limited.

No worries. The first option should reveal if there’s an issue with multiple binding versions installed.

Userdata should be one of the mounted folders through the docker. If not, you’d lose yiur database when doing an update. I run in a docker on my synology and that’s how they do it there.

Thank you @morph166955. I have the userdata and access to it, but not all the commands of the console work (i.e. the sudo commands do not work) and some directories cannot be accessed through the console.

I’m going to do a dangerous thing. I’m going to give a sneak peak of the googletv protocol part of the binding. I preface this as, this is VERY alpha, it’s not complete, but I really am interested to see if it works on more than what I can do my limited testing. Please do not use this as a production jar. The shieldtv code is the same as submitted on the PR so it should be stable.

The googletv side works the same as the shieldtv side. Currently the only channels which work are PIN and KEYPRESS. I’ve not implemented the parts of the message parser which provide information about apps yet. You will need to do the same pin REQUEST process as the shield.

My hope is that those watching can report back that it worked on xyz androidtv device and that basic keypress functionality works. To note, play/stop/pause/forward/reverse is not implemented.

Your things/items should be configured as “androidtv:googletv:name” instead of “androidtv:shieldtv:name”.

Autodiscovery may work, I’ve had mixed results and would love to know a yes/no on that as well. Also curious to see if discovery works when the adb binding is installed and in use (they both use the same mdns name for discovery).

If you do have success, what would be most helpful to me is if you could put the binding logging into trace and send me a transcript of the log (via DM to avoid clogging this up). As the binding is intended to work across different vendors, I’d like to make sure there aren’t things being missed or misinterpreted as best as possible.

Thank you!

https://github.com/morph166955/openhab-addons/releases/download/androidtv-beta/org.openhab.binding.androidtv-3.2.0-4.0.0-SNAPSHOT-7687805.jar

Duly noted. I’ll give it a try sometime in the next day or two.

I republished the jar. Something didn’t compile right for the 3.x pieces. This should fix it. If you were having a problem on an OH3 install, please redownload the 7687805 jar.

Success! Kinda. Sorta.

I have ADB installed (from the SmarthomeJ Addons), but I’m not actively using it. I enabled an ADB thing before dropping the .jar into my addons folder, and got this on repeat.

2023-02-24 17:09:11.920 [ERROR] [y.mdns.internal.MDNSDiscoveryService] - Participant 'org.openhab.binding.androidtv.internal.discovery.GoogleTVDiscoveryParticipant' threw an exception
java.lang.NullPointerException: null
	at org.openhab.binding.androidtv.internal.discovery.GoogleTVDiscoveryParticipant.getThingUID(GoogleTVDiscoveryParticipant.java:92) ~[?:?]
	at org.openhab.binding.androidtv.internal.discovery.GoogleTVDiscoveryParticipant.createResult(GoogleTVDiscoveryParticipant.java:79) ~[?:?]
	at org.openhab.core.config.discovery.mdns.internal.MDNSDiscoveryService.createDiscoveryResult(MDNSDiscoveryService.java:222) [bundleFile:?]
	at org.openhab.core.config.discovery.mdns.internal.MDNSDiscoveryService.considerService(MDNSDiscoveryService.java:214) [bundleFile:?]
	at org.openhab.core.config.discovery.mdns.internal.MDNSDiscoveryService.serviceResolved(MDNSDiscoveryService.java:207) [bundleFile:?]
	at javax.jmdns.impl.ListenerStatus$ServiceListenerStatus.serviceResolved(ListenerStatus.java:106) [bundleFile:3.5.7]
	at javax.jmdns.impl.JmDNSImpl$1.run(JmDNSImpl.java:911) [bundleFile:3.5.7]
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) [?:?]
	at java.util.concurrent.FutureTask.run(FutureTask.java:264) [?:?]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) [?:?]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) [?:?]
	at java.lang.Thread.run(Thread.java:829) [?:?]

I uninstalled ADB and put the .jar back in the Addons folder…but these keep popping up. So, something’s not working with autodiscovery.

Manual discovery worked, though.

(Side note: it would be great if there was a way to manually trigger the PIN Code from the thing page and then enter the code as a thing setting. It wasn’t a big deal to add a string item to my sitemap, but that would just simplify the process a bit. Not a high priority.)

After setting the PIN code, I was able to add the KeyPress channel and trigger up/down/left/right commands. I’ll send you my trace log.

Thank you! What kind of device was it? I see what’s wrong with the discovery code and can fix that easily enough in the next drop. The mdns advertisement is a little different between shield and google.

I see your point on the PIN on the thing config. The problem I’ve always had was that it seems to cause enough of a disruption in the backend that it resets the process and the pin becomes invalid. I use the API or the CLI to do mine. openhab:send GoogleTV_PINCODE “REQUEST” and then replace REQUEST with the PIN. Saves the need for modification of the sitemaps and such. If it was any more than a one time thing I’d probably spend the time to do it on the thing config, but since you only really ever touch it that one first time, it’s probably not worth the time to fuss with the code.

It’s a Chromecast with Google TV (4K). I’ve also got an HD version, but I haven’t tried that yet.

Thanks for the tip on using the API. I agree it’s not worth the time to code into the binding. Maybe add a fill-in-the-blank suggestion of the HTTP commands that would be needed to your instructions?

Works on my Sony Bravia XBR-X900E TV running Android 9.

is it possible to send notifications from openhab to my shield with this binding?

Everyone owe’s @mhilbush lunch for the finds he made today.

Updated jar at: https://github.com/morph166955/openhab-addons/releases/download/androidtv-beta/org.openhab.binding.androidtv-3.2.0-4.0.0-SNAPSHOT-985d618.jar

Two absolutely awesome new channels -

Power is now a fully functional channel. Switch type, accepts ON and OFF. State should update as well.

Keycode is also a super powerful channel. Google has implemented about 300 different keys into the protocol. You can send any key code you like with this. Reference the bottom of the readme below for the list. To note, the ones above 255 seem to be very flaky. I don’t have a TV which has any of those so I can’t test them. The rest all seem to work-ish. You send the number to the channel, it does the work to send the key.

Switch GoogleTV_POWER “POWER [%s]” { channel = “androidtv:googletv:theater:power” }
String GoogleTV_KEYCODE “KEYCODE [%s]” { channel = “androidtv:googletv:theater:keycode” }

Keycodes at openhab-addons/README.md at androidtv-googletv · morph166955/openhab-addons · GitHub

To note, discovery is still broken but is on the list to be fixed soon. Please just ignore those errors.

1 Like

Can you explain a little more what you’re looking to do? I’m not understanding the question.

if i can send a notification from openhab to display to shieldTv like “the washer is done” or “dinner is ready”.

I have no idea how to do that with the protocol stack yet. I can add it to do the to-do list to see if anyone else has been able to make that work.

1 Like

Ok folks, the moment everyone’s been waiting on is here! The googletv protocol stack is close to baked. I have a few small things to tweak in but it’s looking good (THANK YOU @mhilbush).

I’ve also just merged the googletv stack onto the shieldtv thing. So what does that mean. All of the things available on the googletv protocol are now available on the shieldtv. Like power, volume, mute, google keycodes. All of it.

So what do you have to do to upgrade?

  1. Install the new jar from here (I’ll update the main thread so the marketplace folks get a hit once we get a few positive test results): https://github.com/morph166955/openhab-addons/releases/download/androidtv-beta/org.openhab.binding.androidtv-3.2.0-4.0.0-SNAPSHOT-152e942.jar

  2. You may notice that your thing status is offline because GoogleTV is waiting for a PIN. To use this, you must run the PIN process TWICE for a new device. So request, pin, request, pin. If you had already done the PIN process for the shield and are upgrading the jar, you should only have to do it the one time for the googletv side. The on screen displays should look very different between the two. The first is authenticating shieldtv, the second is googletv. You should see the thing status tell you when the first comes online. Once both are hooked you should go ONLINE.

  3. Add the power, volume, mute channels. Power and mute are read/write. Volume (for the moment) is read only (I’m still working on the command to set the volume, hopefully this is soon). The binding will know which protocol to send commands on.

A full list now looks like:

String ShieldTV_KEYBOARD “KEYBOARD [%s]” { channel = “androidtv:shieldtv:theater:keyboard” }
String ShieldTV_KEYPRESS “KEYPRESS [%s]” { channel = “androidtv:shieldtv:theater:keypress” }
String ShieldTV_KEYCODE “KEYCODE [%s]” { channel = “androidtv:shieldtv:theater:keycode” }
String ShieldTV_PINCODE “PINCODE [%s]” { channel = “androidtv:shieldtv:theater:pincode” }
String ShieldTV_APP “APP [%s]” { channel = “androidtv:shieldtv:theater:app” }
String ShieldTV_APPNAME “APPNAME [%s]” { channel = “androidtv:shieldtv:theater:appname” }
String ShieldTV_APPURL “APPURL [%s]” { channel = “androidtv:shieldtv:theater:appurl” }
Switch ShieldTV_POWER “POWER [%s]” { channel = “androidtv:shieldtv:theater:power” }
Dimmer ShieldTV_VOLUME “VOLUME [%s]” { channel = “androidtv:shieldtv:theater:volume” }
Switch ShieldTV_MUTE “MUTE [%s]” { channel = “androidtv:shieldtv:theater:mute” }

=============================

For users who are here just for the GoogleTV stack (anything that isn’t an Nvidia Shield), just replace shieldtv with googletv and you’re good to go. You only do the PIN process once. Also note, APPNAME and APPURL don’t work as we don’t get an APPDB from googletv. Also, starting apps by sending a command isn’t working yet for you. That’s hopefully coming with the volume control once I figure out what the correct syntax for the command is.

2 Likes

I can confirm that the mDNS errors are gone on both of my Chromecasts with Google TV (HD and 4K). When I deleted my things, they popped up in autodiscovery and I didn’t have to go through the PIN process again.

The APP and POWER channels are working, but I haven’t tested anything else.

Thanks, @morph166955 and @mhilbush!

1 Like

It seems like @morph166955 has posted a new binding and mine stopped working as usual. I have used the command you have given me and this is what it returned:

274 │ Active │ 80 │ 4.0.0.202302171450 │ org.openhab.binding.androidtv

After posting the above I tried to uninstall the binding and found that there was no new version. Therefore, I downloaded the jar file and put it in the addons, but don’t seem to be able to display it in the bindings.
I then stopped the container and restarted to check if the binding became available, but to no avail. I looked at the Shield in things and found it to be online and fully functional, despite having unistalled the binding. I then run the command line again and this is the result:

277 │ Active │ 80 │ 4.0.0.202302171450 │ org.openhab.binding.androidtv

Another thing I cannot understand is why despite having the Sonoff binding up and running, since I have installed it it does not appear in the binding menu. Any clues?

So thats interesting. I haven’t updated the main thread yet so absolutely nothing should have happened. Thats still the jar from the main thread, not the new one I posted last night. I’d open an issue on github for one of the developers to look at this.