dwaan / homebridge-adb

Homebridge script to control remote ADB enabled Android device
MIT License
74 stars 14 forks source link
adb android homebridge homebridge-adb homebridge-plugin homekit

npm-version npm-total-downloads Donate

Homebridge ADB and Shell Scripts

A HomeBridge plugin to control remote ADB enabled Android device. The idea is to make random Android based TV box can be controlled with Home App. It make any Android device appear as TV accesory. Where you can control on/off status, volume and dpad control via Control Center remote, and launch certain predefined app defined in the configuration.

This plugins register it self as external accesorries. Make sure after adding Homebridge bridge in Home App, manually "add accesories" to add the android device in the Home App.

Prerequisite

  1. Install Homebridge, Homebridge Config UI X (this plugin support web configuration over there), and this plugins

    sudo npm install -g --unsafe-perm homebridge homebridge-config-ui-x
    sudo npm install homebridge-adb
  2. Install ADB tools inside Homebridge server. Open Homebridge Config UI X in your browser then navigate to terminal or ssh to your homebridge server, and then run this command:

    • If the homebridge server run inside Ubuntu, use this command:
      sudo apt-get install android-tools-adb android-tools-fastboot
    • Or, if the homebridge run inside Docker container like the one from oznu/docker-homebridge, please refer to Docker container section
    • Or, if you're using other OS, please refer this link to download the ADB tools: https://developer.android.com/studio/releases/platform-tools
    • Check if the ADB installed properly by running this command:
      adb --version

      This will output something like Android Debug Bridge version x.x.x

  3. Enable remote developer mode in your Android device. Visit this documentation for more information https://developer.android.com/studio/debug/dev-options

  4. IMPORTANT: Some Android device doesn't support "Remote ADB" by default. If your device is one of them, connect your device with USB cable to any computer with ADB installed. Open terminal and run this command:

    adb tcpip 5555

    if no error produced, disconnect unplug the USB cable from the computer.

  5. OPTIONAL Run this command to make sure you can connect to device:

    adb connect your-device-ip

    If all goes well, there will be a popup window in your android device asking for debug permission. After you accept the request, you might want to do kill the adb server to make a fresh connection

    adb kill-server

    After that reconnect your device again with previous adb connect. Test your adb connection by running this command:

    adb -s your-device-ip shell "getprop ro.product.model"

    This command will output your device model.

Docker container based on oznu/docker-homebridge

Configuration

Here an example of configuration that you can use.

"platforms": [
    {
        "platform": "HomebridgeADB",
        "accessories": [
            {
                "name": "NVIDIA Shield",
                "interval": 1000,
                "ip": "192.168.1.1",
                "path": "/usr/bin/adb",
                "timeout": 1000,
                "playbacksensor": true,
                "playpauseobutton": "KEYCODE_MEDIA_PLAY_PAUSE",
                "backbutton": "shell sh ./myscript.sh",
                "infobutton": "KEYCODE_HOME KEYCODE_HOME",
                "category": "TV_STREAMING_STICK",
                "hidenumber": true,
                "hidehome": true,
                "hideother": true,
                "debug": true,
                "skipSpeaker": false,
                "inputs": [
                    {
                        "name": "HBO Max",
                        "id": "com.hbo.hbonow"
                    },
                    {
                        "name": "Apple Music",
                        "id": "com.apple.android.music"
                    }
                ]
            },
            {
                "name": "Meizu",
                "ip": "192.168.1.2",
                "playbacksensor": false,
                "mac": "97:b6:e8:46:9f:cb",
                "inputs": [
                    {
                        "name": "Termux",
                        "id": "com.termux",
                        "adb": "monkey -p com.termux 1"
                    }
                ]
            }
        ]
    }
]

If you're using Homebridge Config UI X, you can configure your device there, but there's a small hiccup with Inputs. It only display one input, but if you press add, it will display the rest of the inputs.

Questions and Support

If your have any question, refer to FAQ.md first before sending GitHub issues.

If want to support this plugin, you can buy me an Ice cream by follow this link. Or feel free to share and stared this repo.

Sidenote

There is currently an Android TV homebridge plugins that work with "Android TV remote control protocol version 2", it should have simpler setup. You can check the plugin here and see if it's work with your device. However, it will only work with Android TV devices, not every Android devices. Note: I'm not the contributor of the that plugin.