Solution. Pinned here for future reference and if anyone else wants to use it.
- Set up SSH from HA to libreelec
Guide modified from
https://dovydas.xyz/homeassistant/hyperion/ssh/hassio/2018/01/22/controlling-anything-via-ssh.html
1.1 MASTER:
Connect to the MASTER. This will not work “out of the box” so first follow tutorial on how to connect to the HA to Libreelec
ssh [email protected]
Now attach to the Homeassistant docker container. List available docker containers.
docker ps -a
find one looking something like homeassistant/homeassistant3
. Copy its CONTAINER ID looking something like b7dfc2f4d0c4
. Then attach to your container
docker exec -it b7dfc2f4d0c4 /bin/bash
now finally generate your SSH key, but this time in a different directory
mkdir /config/ssh
ssh-keygen -t rsa -f /config/ssh/id_rsa
lets checkout our two brand new PUBLIC & PRIVATE keys
cd /config/ssh
ls -al
cat id_rsa.pub
if all went well you public key output should look something like this:
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDyiprxeHAAieq2YtiXhFgSQIhZwvY6zsPAhsNU/N6yJ+JptVJGWBNY0tAD4eQiSsl88Qe4ryWVmtnw83jUjDMZp24uRtEAPnPW3f9N8mbDnyCEtbYhIDn1KseL3SuRWyFzk0fcMExZfsXrxgZ5nD/yQKvjcHm52LrhDfauxYADItonBZA+6mXh0E1LBrk6gP884IpLLbT9xetW2ZLP6htJDTPc2k9qN1cRVj3DD5Ppfyct1FmfZcAyi3Ua2dPxzngI5RUsjLBaqP+3lluc7fJVYK7fhnGZ36E/JNEamlzktBuLG1+1G3wxCshMFFBBuLTHb7qhtueIBY/4+wduJlFD root@libreelec
COPY this value it is your PUBLIC key we will use later!
1.2 SLAVE:
ssh [email protected]
ssh-keygen -t rsa
Okay we have our keys setup but what about passwordless connection from MASTER? Its easy we have to add the the public key we copied before to our SLAVE machines’ authorized_keys
file.
echo "PASTE YOUR MASTER KEY INSTEAD OF THIS TEXT" >> ~/.ssh/authorized_keys
On some systems authorized_keys
file must have specific unix permissions set and it will fail silently if you do not add these permissions so lets do that. Line below will only make the file readable and writable to our user
chmod 600 ~/.ssh/authorized_keys
Okay our connection should be good to go. So what we just did is we created a SSH key pair on both MASTER and the SLAVE machines & we installed MASTERS public key onto SLAVE. Now the SLAVE trusts the MASTER machine and allows it to connect without a password.
2. Testing SSH connection MASTER → SLAVE
lets connect to our MASTER machine again
ssh [email protected]
then lets issue a command to our SLAVE
docker exec -it b7dfc2f4d0c4 /bin/bash
ssh -i /config/ssh/id_rsa -o StrictHostKeyChecking=no root@libreelec 'vcgencmd display_power'
-
- Set up command line sensor using this guide : https://www.home-assistant.io/integrations/sensor.command_line/
in configuration,yaml , add
sensor:
- platform: command_line
command: ssh -i /config/ssh/id_rsa -o StrictHostKeyChecking=no [email protected] 'vcgencmd display_power'
name: Kodi Sleep Status