Help for ADB controll of Nvidia Shield with Synology Device

Hello,

me once again. I am gettign everyday a lil closer and smarter about this new progamming thing here. Just started and once again would need somebodys help.

What I want to do:
Send shell command to my ADB connected Nvidia Shield

How far I got?
I was able to send via a docker adp app inside of the docker terminal, commands to the shield which also worked fine. When I tried to sent them from HA nothing worked. Anyway I guess the whole Adp Docker App is not even correct installed. I can’t find any config files/folder for it nether I didnt know which options to choose from all this setting/setups inside docker when I installed the app. I just choosed something.

So can anybody give me a guidlines for newbys how I do it step by step correctly?

For my understanding the correct way would be:

  1. install any ADP App inside docker (I prefer by cmd line if someone can help me. At least I can’t do anything wrong, I guess)
  2. Get somehow the ADP Container connected and listinging to HA.

Is this so far correct?

Really appritiate if somebody could help me how to do. I don’t have hass.io.

My System:
Synology DS916 running HA v69.1 in Docker

Thanks in advance…

Really nobody can give me hint just to get started?

Hi im running docker on Ubuntu and used this thread Open Android Tv app as an action for home assistant automation

Dont install anthing on the docker image.

1 - use this to generate a key from the docker into your host system. Basically
ssh-keygen -t rsa (just press enter, enter, enter till you get the key)
ssh-copy-id [email protected] (pass the key to your host your NAS)

2 - Copy the python script to your python folder

3- Install adb (apt get install adb) on your host (NAS)

4- create a shell command: example. for instance my command for kodi is this.
shell_command:

kodi_on_livingtv: ssh -l hass 192.168.XXX.XXX “python ~/docker/homeassistant/python_scripts/shield.py -a org.xbmc.kodi -r 0”

Since I’m in docker I have to ssh into my host and then fire the python command

5- you have to activate developer options in your nvidia shield. settings, select develper options and clicke 8 times or something like that. Then activate adb debugging.

First time you fire the command, you need to got to your shiled and accept the pop up screen.

that should be it.

1 Like

hey, dont suppose its possible to use https://hub.docker.com/r/sorccu/adb/
use that as a docker image (i really want to leave my host completely untouched).

Only issue is I have no idea how to envoke the adb running on the docker?
does one SSH into it then run the command?

I have set up sorccu/adb in an docker container on my HASS.io via Portainer.
I can send the adb commands from the addon “SSH & Web terminal” using these commands:
I am logged in as root via SSH (dont know if that is necessary)

# Connect ADB to your Nvidia Shield TV (you need to accept the fingerprint on the screen @ your shield)
docker exec -it ADB adb connect 192.168.111.11 (use your own ipadress of your Shield)

# Send the "wakeup" code to get your shield out of sleepmode (or screensaver)
docker exec -it ADB adb shell input keyevent KEYCODE_WAKEUP

# Send the "sleep" code
docker exec -it ADB adb shell input keyevent KEYCODE_SLEEP

# Start Youtube
docker exec -it ADB adb shell monkey -p com.android.youtube.tv -v 1

# Start KODI
docker exec -it ADB adb shell monkey -p org.xbmc.kodi -v 1

# Start TV4play
docker exec -it ADB adb shell monkey -p se.tv4.tv4playtab -v 1

# Start Twitch
docker exec -it ADB adb shell monkey -p tv.twitch.android.app -v 1

# Start Netflix
docker exec -it ADB adb shell monkey -p com.netflix.ninja -v 1

I have not been able to figure out how to use these commands from hass.io using the command_line switch yet.

1 Like

I use shell_command:
So I’d guess you could do

shell_command:
  connect:docker exec -it ADB adb connect 192.168.111.11

Which pattern did you use for the container? This?

docker run -d --privileged -v /dev/bus/usb:/dev/bus/usb --name adbd sorccu/adb

Hmm, dont know, since i did the setup inside portainer.
Maybe you know if i can see that in portainer?

Thank you. in portainer you’d add the image sorccu/adb, the volume -v /dev/bus/usb:/dev/bus/usb
and the privileged argument.
Anything else?

Here are some screenshots of my portainer setup of adb.

With this setup i get an error…

shell_command:
  shield_wake1: docker exec -it ADB adb shell input keyevent KEYCODE_WAKEUP

automation:
  - alias: shield_wake2
    trigger:
      platform: state
      entity_id: sun.sun
    action:
      service: shell_command.shield_wake1

I get this error:

2018-11-26 20:51:30 ERROR (MainThread) [homeassistant.components.shell_command] Error running command: `docker exec -it ADB adb shell input keyevent KEYCODE_WAKEUP`, return code: 127
NoneType: None

I inserted sun.sun only to have anything so i can trigger it manually to test.

how are you running your hass, is it hassio on a Pi?

I run HASS.io on an Intel Nuc.
Proxmox running VM’s
A VM with debian 9.4.0 and HASS.io installed in that…
(Found a guide here in the forum long ago)

So in order to fire the command from hassio, you need to ssh into the operating system (debian) and then run the docker command. Something like this.

shell_command:
  wake_nvidia: ssh -l hass 192.168.1.xxx "docker exec -it ADB adb shell input keyevent KEYCODE_WAKEUP"

where 192.168.1.xxx is the ip of your Debian

problem is you need to create an ssh key and then save it so it doesnt get lost on hassio restart. I dont run hassio, but I saw a post here on how to create the key and make it persistent.

Now i remember, it’s at this point i have hit the wall earlier to.
I have no idea how to get around this.
I have added a file “authorised_keys” (with my public ssh key) in the root, in the /root/.ssh/ and in /config/ but i still get this error:

2018-11-26 21:57:34 INFO (MainThread) [homeassistant.components.automation] Executing shield_wake2
2018-11-26 21:57:34 INFO (MainThread) [homeassistant.helpers.script] Script shield_wake2: Running script
2018-11-26 21:57:34 INFO (MainThread) [homeassistant.helpers.script] Script shield_wake2: Executing step call service
2018-11-26 21:57:34 ERROR (MainThread) [homeassistant.components.shell_command] Error running command: `ssh -l root 192.168.111.90 "docker exec -it ADB adb shell input keyevent KEYCODE_WAKEUP"`, return code: 255
NoneType: None

that’s the thing. I run hass on docker. so in my set up i mount a volume from the host to the hass container, where it creates and saves the ssh key.

I dont think you can just save the key in your hassio config directory.

have a look in the forum. there’s a way around this, I’ve seen it but cant remember where

ps. i think this is it

have a look

heres a video on how to

this is not it. this is for logging into hass.io

That is how i have it setup allready.
What i dont understand is why hassio needs to ssh into it self to run the command?

because hassio is running in a container. that container doesnt have a docker installation.
your docker engine is on the os (debian)
so debian needs to fire the command

ok, so been playing with this and have a suggested workaround.
you cant mount volumes on hassio. it’s locked
so what you could do is run a script when you start your system that would copy the ssh key into the correct directory into the hassio folder.

these would be the steps:

  1. enter the hassio container - sudo docker exec -it homeassistant /bin/bash
  2. generate key - ssh-keygen -t rsa
  3. copy key to host - ssh-copy-id [email protected]
  4. exit the container - exit
  5. copy the key file from container to host - sudo docker cp homeassistant:/root/.ssh/id_rsa /home/xxxx/.ssh/id_rsa
  6. on restart copy the key file back into the hassio container root directory -sudo docker cp /home/xxxx/.ssh/id_rsa homeassistant:/root/.ssh/id_rsa
  7. create a script that runs this command on start using may be systemd or similar

But how come that when i ssh into hassio with root user, and come to this screen:

Using username "root".
Authenticating with public key "Hass_SSH_key"

  _    _                 _
 | |  | |               (_)
 | |__| | __ _ ___ ___   _  ___
 |  __  |/ _` / __/ __| | |/ _ \
 | |  | | (_| \__ \__ \_| | (_) |
 |_|  |_|\__,_|___/___(_)_|\___/



Our Cli:
$ hassio help
➜  ~ docker exec -it ADB adb shell input keyevent KEYCODE_SLEEP
➜  ~ docker exec -it ADB adb shell input keyevent KEYCODE_WAKEUP
➜  ~

i can run all my command’s
(this is new since the latest update of the addon SSH & Webterminal)
(If you disable “protection mode”)

Dosent that mean that i now have access to docker inside hassio?
I am running all my docker exec -it ADB commands inside the hassio container arent i?
And would that not mean that i would be able to run it directly with a shell command or command_line switch?

In the addon description it says:
“Has the option to access the Docker instance running Hass.io host system.”
https://github.com/hassio-addons/addon-ssh/blob/v3.5.1/README.md

Oh, that’s good.
So you can manually run the command from inside hassio.

so i dont know why you’re getting that error.