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.
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 : “com.netflix.ninja” 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": "com.netflix.ninja", "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.
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:
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?
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