ADB Android TV -How to Get Status

Hello fellows,
yesterday, I evolved a little piece my openhab system.
Since yesterday, I was remote commanding my television through openhab, emulaing the IR - LED of the physical original remote, to an ESP32 sensors and actuators node, inside the livingroom.

After buy a new android smart TV, I looked forward to integrate it in a better way and I discovered and succesfully implemnted the ADB android debugging bridge witch allows me to replicate and send the remote command through the net.

A little piece is missing to the system, and here I ask your help if possibile:
now, theoretically, I can also know if the TV is ON or OFF (with a LED emulation was not possible because the comunication is mono-directional) .

So the question is:
How can I have a feedback from the TV to the OH3 system to be able to know something about his status (on - off ecc.)?

I try to understand [media state detection] (Android Debug Bridge - Bindings | openHAB)
on the official documentation, because seems something linked to my targhet, but I did not understand how it works.

Thank you to help me.
Best regards.

very shortly, is there a way to get status feedback from the android device connected via ADB binding to OH enviroment?


Several channels can get informations from the device. If you want something like a “status”, there are 3 channels :

  • “awake-state” : seems to be a kind of ON/OFF channel ? It’s an “advanced” one,so if you use GUI, you have to tick the “Show advanced” on the thing channel tab to configure it.
    This channel seems to be undocumented, and usually it means that it is not reliable…

  • “current-package” : the current application running foreground. The name is a developper friendly one. Example : “” is the netflix application.

  • “media-control” : It is a “player” channel, and the channel is bidirectionnal. You can use a player item linked to this channel, and get state (play, pause) or post command to it.
    Hopefully this channel will work “out of the box” with most applications running.

But, to use this last channel, sometimes you will have to advise the binding on how to check if an application is playing something. This is the purpose of the “mediaStateJSONConfig”. If the application you want to monitor/control with the “media-control” channel is not using the Android standard “media_session” service , then you will have to use this parameter to help the binding understand it.
You fill this parameter with a list of applications, with, for each one, a “mode” for the media detection you want to use, and optionaly (if you choose the “wake_lock” mode) a parameter “wakeLockPlayStates”. This parameter uses an android special state, that could be set by the application to tell Android to keep the device awake.
For example, netflix set to “0” the wake_lock when not playing, and I saw sometimes the number 2 or 4 when it is playing something.
So you will set {"name": "", "mode": "wake_lock", "wakeLockPlayStates": [2,4]} and the binding will be able to know if your device is playing something.
(But in fact, for Netflix, you don’t have to use the wake_lock workaround, as the default mode “media_state” is working)
How can you get the wake_lock value for your application ? Simple : launch it, play something with your application, and use the “wake_lock” channel to get the right number to use in the “wakeLockPlayStates” parameter for this application.

You can also use the mode “audio”. As the documentation says, it detects if your application is actively outputting sound and guess the playing state with this.
This is for the sole purpose of helping the channel “media-control” to have the right state information.

Beware, the information update occurs at fixed times (every 30 seconds, you can configure it), so it is not good for real time scenario.

Could you get it running?

Hi Eric, What do you mean? The Android Debug binding to access Android TV?
It was very easy. Just enable developer options on the tv and enabled the USB debugging inside the dev options.
After that, I installed the binding and on his configuration I put Just the TV IP address.
Lastly, i have to accept on the TV a connection message…

Very use full.
Will be top if I can know if the TV is already on/off or the actual program.

Mh ok. Yes I want to use adb binding with my firetv stick.
I enabled the usb debugging and tried adb via shell. Iaccepted the connection message.I am able to send adb commands from my shell.
But when I create my thing it is not updating one single channel at all.

You have to create a Point on your model, linked with SendKey event channel of the ADB TV item.
After that, in your sitemap, you can map the events as buttons.
here my sitemap extract that works very good:

Frame label="TV" {
				Text icon="TV" label="Status TV" item=TelecomandoTVSalotto_AwakeState
                Slider item=TelecomandoTVSalotto_Volume label="Volume"
				Switch item=TelecomandoTVSalotto_SendKeyEvent label="[]" mappings=[KEYCODE_CHANNEL_DOWN="P-",KEYCODE_VOLUME_DOWN="V-",KEYCODE_VOLUME_MUTE="M",KEYCODE_VOLUME_UP="V+",KEYCODE_CHANNEL_UP="P+"]
				Switch item=TelecomandoTVSalotto_SendKeyEvent label="[]" mappings=[KEYCODE_TV_TELETEXT="TEXT",KEYCODE_1="1",KEYCODE_2="2",KEYCODE_3="3",KEYCODE_4="4"]
				Switch item=TelecomandoTVSalotto_SendKeyEvent label="[]" mappings=[KEYCODE_5="5",KEYCODE_6="6",KEYCODE_7="7",KEYCODE_8="8"]
				Switch item=TelecomandoTVSalotto_SendKeyEvent label="[]" mappings=[KEYCODE_9="9",KEYCODE_0="0",KEYCODE_LAST_CHANNEL="    ↻    "]
				Switch item=TelecomandoTVSalotto_SendKeyEvent label="[]" mappings=[KEYCODE_APP_SWITCH="APP",KEYCODE_ALL_APPS="⛯",KEYCODE_HOME="⌂",KEYCODE_BUTTON_MODE="≡"]
				Switch item=TelecomandoTVSalotto_SendKeyEvent label="[]" mappings=[KEYCODE_POWER=" ON ",KEYCODE_DPAD_UP="   ˄    ",KEYCODE_BACK=" ⟽ "]
				Switch item=TelecomandoTVSalotto_SendKeyEvent label="[]" mappings=[KEYCODE_DPAD_LEFT="   ˂  ",KEYCODE_DPAD_CENTER=" OK ",KEYCODE_DPAD_RIGHT="   ˃   "]
				Switch item=TelecomandoTVSalotto_SendKeyEvent label="[]" mappings=[KEYCODE_GUIDE=" GUIDA",KEYCODE_DPAD_DOWN="   ˅   ",KEYCODE_INFO="  ⓘ  "]

Oooh, now I noticed!!!
Thank you! This is a good starting point to implement something and is what looking for ^^ many thanks!!!

I really are only intested to get the status of the fire tv stick. so the sendkey is not really needed. Or is it needed for the functionality to request the status?

Awake - state on “Advanced options” as dalgwen Said is what I was Looking for… On if TV is on Off if switched off =)

So I just created a new thing from UI, with only one channel (the awake channel in advanced options) but the value of the channel remains NULL and I keep getting the following log entries:
2021-12-24 10:51:48.713 [WARN ] [e.internal.AndroidDebugBridgeHandler] - Unable to refresh awake state: Timeout

I just changed the log level to TRACE and this is the output:

2021-12-24 10:52:53.716 [DEBUG] [e.internal.AndroidDebugBridgeHandler] - Refresh device status

2021-12-24 10:52:53.717 [DEBUG] [ge.internal.AndroidDebugBridgeDevice] - - shell:dumpsys activity | grep mWakefulness

2021-12-24 10:52:58.717 [WARN ] [e.internal.AndroidDebugBridgeHandler] - Unable to refresh awake state: Timeout

When I execute the command from shell I get the following:

root@openhab-ansible:/var/log/openhab# adb shell dumpsys activity | grep mWakefulness

Do you use also a linux system? Did you install adb there or is this not necessary for the binding?

After a restart of the stick android asked me again to allow adb connection and now it is working. So thank you for your help