Been playing around today with an older TV, a Pi Zero, and passing CEC commands to turn the TV on and off.
Up to this point I have been able to get all commands running directly on the RPI, through the HA SSH Web Terminal, and I also have an SSH key installed (and confirmed working) for password-less remote SSH commands.
But, it just won’t run from within a HA entity.
I’ve taken a copy of the example from the Bravia TV component page, and changed the IP and name.
This is sitting inside a switches yaml file alongside another working switch template.
I have been looking at this for hours, and I can’t tell if my syntax is incorrect, despite being the same from the component page, or if it’s something else I’m unaware of? I can’t understand why it would work from the HA SSH Web Terminal, but not an entity?
Success! Here is an update for anyone else reading this thread.
Firstly, SSH and keys are not a strong point for me, so it was a bit of a learning curve, and the addition of not quite reading another person’s instructions properly.
A couple of points:
I believe that I was using and referencing the correct users. Both on the RPI and on Hassio.
I had been generating the keys and sending them to the RPI using ssh-copy-id -i root@ip_address, which I believe created different keys and put them in a different location to what the above-linked instructions said. Again, note to self to RTF instructions.
And lastly, in the above-linked instructions, they had additional options in the ssh command which weren’t in the HA command line switch example. I believe these options were important for success.
Don’t take my word for it that it was all the above, but I know that having addressed those I now have it working.
@Grepen
In the beginning I had the same problems as you. The steps and additional options you need are as follow:
Create a folder in your config directory called something like “ssh”
Copy your private keyfile to the newly created folder
SSH into your hassio server and chown the keyfile so only that user has access to it (otherwise your keyfile will be ignored because all users are able to read your private key). Chown command: chown -R hassio:hassio /config/ssh/id_rsa
Lastly change your ssh commands to: command_on: "ssh -i /config/ssh/id_rsa -o StrictHostKeyChecking=no [email protected] '*your command to execute*"
These steps helped me to successfully execute my python scripts on a raspberry pi. Hope it is usefull to you guys.