AndroidTV Binding [3.2.0;4.0.0)

This binding is designed to emulate different protocols to interact with the AndroidTV platform.

I would GREATLY appreciate feedback from users even if to just confirm that it’s working as expected. Please include device model and software version so I can add it to the readme as confirmed working.

AndroidTV Binding

This binding is designed to emulate different protocols to interact with the AndroidTV platform.
Currently it emulates the Nvidia ShieldTV Android App to interact with an Nvidia ShieldTV for purposes of remote control.

Supported Things

This binding supports a single thing type:

  • shieldtv - The ShieldTV

Discovery

ShieldTVs should be added automatically to the inbox through the mDNS discovery process.

Binding Configuration

This binding does not require any special configuration files.

This binding does require a PIN login process (documented below) upon first connection.

Thing Configuration

There are three required fields to connect successfully to a ShieldTV.

Name Type Description Default Required Advanced
ipAddress text IP address of the device N/A yes no
keystore text Location of the Java Keystore N/A no no
keystorePassword text Password of the Java Keystore N/A no no
Thing androidtv:shieldtv:livingroom [ ipAddress="192.168.1.2" ]

Channels

Channel Type Read/Write Description
keypress String RW Manual Key Press Entry
pincode String RW PIN Code Entry
app String RW App Control
appname String RO App Name
appurl String RO App URL
String ShieldTV_KEYPRESS "KEYPRESS [%s]" { channel = "androidtv:shieldtv:livingroom:keypress" }
String ShieldTV_PINCODE  "PINCODE [%s]" { channel = "androidtv:shieldtv:livingroom:pincode" }
String ShieldTV_APP "APP [%s]" { channel = "androidtv:shieldtv:livingroom:app" }
String ShieldTV_APPNAME "APPNAME [%s]" { channel = "androidtv:shieldtv:livingroom:appname" }
String ShieldTV_APPURL "APPURL [%s]" { channel = "androidtv:shieldtv:livingroom:appurl" }

KEYPRESS will accept the following commands as strings (case sensitive):

  • KEY_UP
  • KEY_DOWN
  • KEY_RIGHT
  • KEY_LEFT
  • KEY_ENTER
  • KEY_HOME
  • KEY_BACK
  • KEY_MENU
  • KEY_PLAYPAUSE
  • KEY_REWIND
  • KEY_FORWARD
  • KEY_POWER
  • KEY_POWERON
  • KEY_GOOGLE

The list above causes an instantanious “press and release” of each button.
If you would like to manually control the press and release of each you may append _PRESS and _RELEASE to the end of each.
(e.g. KEY_FORWARD_PRESS or KEY_FORWARD_RELEASE)

APP will display the currently active app as presented by the ShieldTV.
You may also send it a command of the app package name (e.g. com.google.android.youtube.tv) to start/change-to that app.

Pin Code Process

For the ShieldTV to be successfully accessed an on-screen PIN authentication is required on the first connection.

To begin the PIN process, send the text “REQUEST” to the pincode channel while watching your ShiledTV. A 6 digit PIN should be displayed on the screen.

To complete the PIN process, send the PIN displayed to the pincode channel. The display should return back to where it was originally.

This completes the PIN process. Upon reconnection (either from reconfiguration or a restart of OpenHAB), you should now see a message of “Login Successful” in openhab.log

Full Example

Thing androidtv:shieldtv:livingroom [ ipAddress="192.168.1.2" ]
String ShieldTV_KEYPRESS "KEYPRESS [%s]" { channel = "androidtv:shieldtv:livingroom:keypress" }
String ShieldTV_PINCODE  "PINCODE [%s]" { channel = "androidtv:shieldtv:livingroom:pincode" }
String ShieldTV_APP "APP [%s]" { channel = "androidtv:shieldtv:livingroom:app" }
String ShieldTV_APPNAME "APPNAME [%s]" { channel = "androidtv:shieldtv:livingroom:appname" }
String ShieldTV_APPURL "APPURL [%s]" { channel = "androidtv:shieldtv:livingroom:appurl" }

Confirmed/Unconfirmed Models

Year Name Model Android Ver Shield Ver OH4.0.0 OH3.4.0 Unverified
2015 Shield TV P2571 X
2015 Shield TV Pro P2571 X
2017 Shield TV P2897 11 9.1.1 X X
2017 Shield TV Pro P2571 11 9.1.1 X
2019 Shield TV P3430 X
2019 Shield TV Pro P2897 11 9.1.1 X

Changelog

Version 0.1 (342d4f9)

  • Initial merge in from shieldtv to androidtv

To-Do

  • Add GoogleTV protocol
  • Add dynamic channel for apps
  • Add periodic app db updates
  • Resolve random unknown packets
  • Add support for keyboard entry

Resources

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

3 Likes

Very interesting. I would like to test it, but would need some info on the keystore, mainly where to find it and how to setup the password. Thank you.

EDIT: I’ve pulled the readme file into the original thread to make it easier for people to access.

EDIT2: Keystore commands are unnecessary after v0.3.

Updated to version 0.2.

Updated to version 0.3

Updated to version 0.5

This is the final draft as submitted on https://github.com/openhab/openhab-addons/pull/13934 for review and merge.

Hello,

Many thanks for this binding. As you requested feedback, here is mine :+1:

I have Model P2897 (shield TV 2017, android version 11, shield version 9.1.1.), on openHAB 3.4, and it works (mostly).
Retro engineering this is a real accomplishment, bravo !

I said “mostly”, because the app channel is never receiving the current application.
(But I can send commands to it and the app launch, and it’s the most important point !).
I debugged it on my dev environnment, and the reader thread never receive the message starting with “08ec07”. It receives the other messages although.

I also tested to send some remote command with the key press channel and it also works.

Also, the mdns discovery didn’t work. But it seems it didn’t make it to the 3.4 release ? Only 4.0 ? (it’s not a request to include it, I know keeping two versions is cumbersome)

If I can make some recommandations :smile: :

  • the channel are all “advanced”, is it mistake ? If I guess correclty, the “advanced” channels should be deviceName and the raw channels, but not pin code, app name and key.
  • I was deceived by the thing status after creation, before sending PIN. I thought it was broken, because it was stuck in “Offline - initializing”. Maybe you could use the ThingStatusDetail.CONFIGURATION_PENDING status ?

Again, thanks for your work !

Thank you for giving it a test and I’m glad it’s (mostly) working.

Can you confirm the version number you’re seeing on the cli? The channels being incorrectly marked as advanced was fixed and committed a few days ago and that should have been pulled into the 3.4.0 release. I have had reports of successful auto discovery so let’s definitely make sure you’re on the right image. As it sits right now they should have full parity between 3.4.0 and 4.0.0.

As far as the current app, this is going to sound dumb, but did you check after sending a key press? There’s a weird anomaly where the shield doesnt send that string until after a key press is sent to the device. I’m not sure why it does that, but I’ve seen it be flaky several times.

I can definitely update the thing status a little differently before the PIN process. I’ll make a note and commit it in the next round.

You are right, I hadn’t the right version.
I built it directly from git (commit e717897d8d27fe26b140a59c81dff80ce1a190bb, branch shieldtv-3.4.0).
The mDns is working with the build in the marketplace.

As far as the current app, this is going to sound dumb, but did you check after sending a key press?

You are also right ! It works now. Strange bug, indeed !

Thanks

Gotcha. Please definitely ignore the shieldtv-3.4.0 branch on my github. It’s not up to date with all of the current commits. To build the 3.4.0 builds I’m pulling from the 3.4 branch off of openhab directly and adding the binding in from my 4.0.0 branch (with the version number changed back so it compiles correctly).

Glad to hear the app is working now. The protocol is not the best. I am going to work on adding more support for the apps in a future release. Theres a few things I can do but they require some substantial time that I haven’t had yet.

Installed and working. Here are the specifics.

Year: 2019
Name: Shield TV Pro
Model: P2897
Android Ver: 11
Shield Ver: 9.1.1
OH Ver: 4.0.0

Thanks for the support!

Thank you! I’ve updated the chart above with the info. I’ve also added a note about the oddity of the app info not being sent from the shield until a key is pressed. The next version (to be done after the PR review is done and merged) is going to attempt to make the app bits a little more robust. There is a large dump of data pertaining to the apps that I haven’t had time to decode and implement yet. Eventually I want to create a small table that will provide the end users with more information about the apps.

Many, many thanks,

I also confirm it working with Openhab 3.4, on a 2017 Shield TV (P2897). Made some HABPanel buttons and now have a pseudo-remote control working.

Some smaller issues:

  • Discovery did not work but manually added the thing via IP address and that worked like a charm
  • the APP chanel does not always work (shows the Launcher app most of the time, even when the app is eg Netflic)
  • sending app package names to switch to them works for some (eg the youtube example, or com.netflix.ninja) but not for others (eg Kodi). Haven’t figured out why yet. I get the package names when selecting an application and getting its Information; that may not be the most reliable way.

But again, these are minor things so great stuff !!

It does not seem to be necessary. At least, I left it open (just passed the IP information from my shield) and everything seems to work.
Edit: sorry, missed morph166955’s reply saying the same (blush)

I will absolutely agree that the app messages are flaky. This is unfortunately because the shield isn’t reliable in sending the app name. Just to confirm, had you recently restarted OH or anything like that when it wasnt working? There is a known issue where it won’t send app data until there is a keypress sent to the shield. If you set logging to trace you should see the messages come in and get parsed to confirm if they’re being sent or not.

As a note, the next version should be more robust on the app side. There is a database sent out which I haven’t had the time to inplement yet. I have noticed that some of the app names seem to be slightly different than what they require to fire. Kodi may be one of those.

As far as discovery, did you click the scan button to force a discovery to go? I have noticed that it doesn’t send the requisite mdns message very often. Hitting scan makes OH send a request which it usually replies to. Also, just to confirm, your OH is on the same network as the shield correct? mdns has issues crossing vlans on some networks.

Just to note, I have pulled the current 4.0.0 code base into the shieldtv-3.4.0 branch. There will be a breaking change coming at some point when the core crypto updates to 4.0.0 are implemented and then applied to the shieldtv binding. This isn’t happening soon, but when it does I will likely do a final compile and sunset the 3.4.0 releases.

1 Like

Hi,
I’m not very familiar with github. I put the .jar file into my addons folder of
oh 3.4. The binding doesn’t even show up in my ui after reboot. Perhaps it has something to do with that oh 4.0 stuff…I would love use and test the binding with my shield. Is it possible to put a link to the latest .jar file for oh 3.4 here so that I can download and copy it to my
addons folder?
Best wishes!

STOP! Now I see it! I’ll give it a try :grinning:

Hi again,

works wonderfully with my shield tv pro bought last year,
same one like mhilbushe’s one P2897 Android 11, Shield Ver 9.1.1.
The Keycommands even seem to react a bit faster than in the
android debug Binding.
However, wouldn’t it be usefull to let openhab know wether the
shield is running or not? The KEY_POWER toggles the ON/OFF.
So for me it’s a bit hard to use this in rules. In the android binding
there are different keys for “Power_Off and Power_On”. So I can
either start e.g. Netflix with the shield being off or change to Netflix while the shield is powered on by using one trigger button.
Anyway thanks a lot for this great work!

Glad to hear that is working! I completely agree on the power. The problem is that the android app only has a power toggle so i couldn’t capture the power state. This first release is strictly to mirror what the app does. It is on my todo list to basically brute force the command chain to see if i can stumble on the direct buttons as well as to trigger any kind of state messages. In also considering pulling in the ADB code to get the info i can’t get from the protocol.