Hi everybody,
to be able to run a docker command by pressing a button o turning on/off a switch I used to run hassio.addon_stdin service but since I update to the last version of the addon the support for stdin has been removed. I tried to use the shell_command integration but as I expected the docker exec command is not found and the script that I run end with the exit code 127. I know that the shell_command will run inside the homeassistant docker of my installation. Is there anybody that can explain to me how to get the same result in another way? maybe ssh into the a0d7b954_ssh docker and then run the command?
thank you to anybody will try to help me…
What exactly is it you’re trying to accomplish? Maybe there’s an easier way than using SSH.
Hi, I have to run some docker command with the “docker exec” over the dockers running in my home assistant installation.
Actually I’m running command over a docker image that I created ad hoc for retreiving data from the IPMI interfaces and send ipmitool command to those interfaces and to silence the UPS beeper (I’ve installed the nut addon)
I used to do this task by calling a service hassio.addon_stdin over the a0d7b954-ssh
. It worked flawlessly for months unitl I decided to update the ssh addon without noticing that the support for the addon_stdin has been removed (it was clearly stated so that’s my fault).
Now I’m stuck because the shell_command integration run those commands in the homeassistant container and will not recognize any docker command (as expected)… I’m trying to revert the ssh version to the 9.1.1 by modifing the data inside the backup file I’ve made with no success to be honest…
Have you tried setting up command_line entities or shell_commands?
You should be able to run SSH commands within HA which will connect to the SSH addon, seems like you need to do some trickery to get the authentication to work, but something like this might do it:
Yes, I’ve already tried something like that but I’m not able to ssh into the homeassistant host itself…
I’ve tried to ssh into [email protected]
but it keeps asking me the password
I’ve tried to ssh into root@ a0d7b954-ssh
but it didn’t resolve the host name
The keys setup seem to be correct… as far as I know. I’ve putted the public key in the autorized-keys of the ssh addon configuration but when I try to run the command ssh -i /path/to/priv.key root@… it keeps asking for the password
I miraculously managed to retreive an old back up and I’ve restored only the ssh addon… so now it is working again, but it will be good to find out another solution just in case
Bumping old topic because I tried a same thing and succeeded. This is more-or-less what I did:
-
connect to HAOS through putty/ssh (IP address of HA in local network; mine is 192.168.17.8) and confirm that your actual “docker exec …” command works here
-
log into ha-core container
docker exec -it homeassistant /bin/sh
you end up in /config folder, shared with HA host
- create ssh keys with no password
mkdir ssh_core_to_host
cd ssh_core_to_host
ssh-keygen
chmod 400 id_rsa*
- export public key to HA host (note the host IP at the end, yours will be different)
ssh-copy-id -f -i /config/ssh_core_to_host/id_rsa.pub [email protected]
- test if you can login without password, then logout
ssh -i /config/ssh_core_to_host/id_rsa -o StrictHostKeyChecking=no [email protected]
exit
- test your actual commands (mine were of ebusd contaner, to get/set value of some registers)
ssh -i /config/ssh_core_to_host/id_rsa -o StrictHostKeyChecking=no [email protected] -t 'docker exec addon_2ad9b828_ebusd /usr/bin/ebusctl r -c bai PrEnergyCountHc1'
- put your commands into configuration.yaml and restart HA core
shell_command:
read_prenergycounthc1: "ssh -i /config/ssh_core_to_host/id_rsa -o StrictHostKeyChecking=no [email protected] -t 'docker exec addon_2ad9b828_ebusd /usr/bin/ebusctl r -c bai PrEnergyCountHc1'"
reset_prenergycounthc1: "ssh -i /config/ssh_core_to_host/id_rsa -o StrictHostKeyChecking=no [email protected] -t 'docker exec addon_2ad9b828_ebusd /usr/bin/ebusctl w -c bai PrEnergyCountHc1 0'"
read_prenergysumhc1: "ssh -i /config/ssh_core_to_host/id_rsa -o StrictHostKeyChecking=no [email protected] -t 'docker exec addon_2ad9b828_ebusd /usr/bin/ebusctl r -c bai PrEnergySumHc1'"
reset_prenergysumhc1: "ssh -i /config/ssh_core_to_host/id_rsa -o StrictHostKeyChecking=no [email protected] -t 'docker exec addon_2ad9b828_ebusd /usr/bin/ebusctl w -c bai PrEnergySumHc1 0'"
This survived ha core updates, seems solid.