SmartHome/J - Addons for openHAB 4

4.1.0

Android Debug Bridge Binding

This binding allows to connect to android devices through the adb protocol. The device needs to have usb debugging enabled and allow debugging over tcp, some devices allow to enable this in the device options but others need a previous connection through adb or even be rooted. If you are not familiar with adb I suggest you to search “How to enable adb over wifi on <device name>” or something like that.

Supported Things

This binding was tested on the Fire TV Stick (android version 7.1.2, volume control not working), Fire TV Cube (fire os version 7 / android version 9) and Nexus5x (android version 8.1.0, everything works nice), please update this document if you tested it with other android versions to reflect the compatibility of the binding.

Discovery

As I can not find a way to identify android devices in the network the discovery will try to connect through adb to all the reachable ip in the defined range, you could customize the discovery process through the binding options. Your device will prop a message requesting you to authorize the connection, you should check the option “Always allow connections from this device” (or something similar) and accept.

Binding Configuration

Config Type description
discoveryPort int Port used on discovery to connect to the device through adb
discoveryReachableMs int Milliseconds to wait while discovering to determine if the ip is reachable
discoveryIpRangeMin int Used to limit the number of IPs checked while discovering
discoveryIpRangeMax int Used to limit the number of IPs checked while discovering

Thing Configuration

ThingTypeID description
android Android device
Config Type description
ip String Device ip address
port int Device port listening to adb connections (default: 5555)
refreshTime int Seconds between device status refreshes (default: 30)
timeout int Command timeout in seconds (default: 5)
mediaStateJSONConfig String Expects a JSON array. Allow to configure the media state detection method per app. Described in the following section

Media State Detection

You can configure different modes to detect when the device is playing media depending on the current app.

The available modes are:

The configuration depends on the application, device and version used.

This is a sample of the mediaStateJSONConfig thing configuration - the label is optional:

[{"name": "com.amazon.tv.launcher", "mode": "idle"},{"name": "org.jellyfin.androidtv", "mode": "wake_lock", "wakeLockPlayStates": [2,3]}, {"name": "com.amazon.firetv.youtube", "label":"YouTube", "mode": "wake_lock", "wakeLockPlayStates": [2]}]

Channels

channel type description
key-event String Send key event to android device. Possible values listed below
text String Send text to android device
tap String Send tap event to android device (format x,y)
media-volume Dimmer Set or get media volume level on android device
media-control Player Control media on android device
start-package String Run application by package name. The commands for this Channel are populated dynamically based on the mediaStateJSONConfig.
stop-package String Stop application by package name
stop-open-url String Open a URL with the default application (http, rtsp, aso)
current-package String Package name of the top application in screen
shutdown String Power off/reboot device (allowed values POWER_OFF, REBOOT)
wake-lock Number Power wake-lock value
screen-state Switch Screen power state
hdmi-state Switch HDMI power state

Available key-event values:

Full Example

Sample Thing

Thing androiddebugbridge:android:xxxxxxxxxxxx [ ip="192.168.1.10", port=5555, refreshTime=30 ]

Sample Items

Group   androidDevice    "Android TV"
String  device_SendKey       "Send Key"                            (androidDevice)   {  channel="androiddebugbridge:android:xxxxxxxxxxxx:key-event" }
String  device_CurrentApp       "Current App"                            (androidDevice)   { channel="androiddebugbridge:android:xxxxxxxxxxxx:current-package" }