Help for ADB controll of Nvidia Shield with Synology Device

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.

hassio is in a container - so your running docker exec on a container with seemingly no docker tools. Does the above actually yield a result.

The objective should be to ssh from hassio (as that is where the shell_commands run) to your synology NAS (the host) and then (&&) run the docker exec command (which is like ssh but its dockers way of connecting to a container to run commands)

Yes, but only if you run the community addon “SSH & Web Terminal” and have “Protection Mode” OFF.
That gives you access to docker in the core or hass.io.

And im sorry, but im am not running on a Synology device, im running in an VM on Proxmox on an intel Nuc

Probably best then to either start a new thread or head to #hassio on discord

did you get anywhere with this? saw a related issue in another post. anyway as you know the problem is that when you generate your ssh key it goes into /root/.ssh/ and when you restart hassio it will be lost.
so i understand you can add a flag to the ssh login command to tell it where to pull the key from.

So try the following:
generate your ssh key. once you have it in /root/.ssh/ copy it to your config folder so it will persist.

you can then send the shell command like this:

ssh i /path/to/key [email protected] “docker exec -it ADB adb shell input keyevent KEYCODE_WAKEUP”

see if it works

I gave up, i cant ssh into the homeassistant docker to generate the ssh key.
Non of all the diffrent ways i have found have worked.
Maybe becaus im running the intel-nuc version?


The USB method here: https://developers.home-assistant.io/docs/en/hassio_debugging.html dident work.

If you press the >_ for console it doesn’t let you access the container?
Are you doing it from within your local network?
I mean using the http:ip for your portainer, as opposed to the external https:
Can’t access the container if you’re outside your network

These usb instructions are for accessing the os. Not the container.
What os are you running on the nuc.?

Been messing around with various options and found something i liked so thought I’d share…

Prompted by this thread:

and this thread:

instead of doing the ADB lifting on the synology - i installed MQTT client, ADB Shell [tasker], Secure Settings (although only got secure settings to work a few times to wake the device) on the shield.
EDIT:
I actually used ADB as well for wake which works WAY more reliably, used the same command
input keyevent KEYCODE_POWER

Essentially i’m sending a MQTT command to the shield from HA - Tasker is listening via MQTT Client and then based on the action / appname in the topic / message then completes an action.

I can run an app (so have the icon in my lovelace UI like netflix :slight_smile:)
I can wake the device up and turn the TV on
I can turn the device (and TV) off
I can also pause (and resume) whatever i’m watching.
(and have a sensor that reports on whatever is being shown)

in case anyone wanted the info:
input keyevent KEYCODE_MEDIA_PAUSE
input keyevent KEYCODE_MEDIA_PLAY