I am relatively new to Home Assistant, it’s really awesome… But somehow I got stuck with the command line switch component… Sorry for opening a new topic but I wasn’t able to find any solution on the other topics, tried them but nothing seems to work…
I tried to setup a command line switch to turn on and off a windows 10 machine remotely therefore I use a Raspberry Pi connected over ethernet to my PC.
If I run the bash scripts through Putty, everthing works fine, but everytime I press the switch in my Home Assistant UI, I get an Error Message like this:
Does the HomeAssistant user have access to those scripts? Remember, when you run a script from within HA, it runs it as the HA user, not as root. Check the perms on the script.
Thanks for your prompt reply, I’ve added the user “homeassistant” to the group “root” with the command
“sudo adduser homeassistant root” when I look for the permissions with “cat /etc/passwd” I see the following line:
If HA runs in a virtualenv, you should test your script/command on the command line as HA user when venv is activated.
For Hassbian:
sudo su -s /bin/bash homeassistant
source /srv/homeassistant/bin/activate
There are several problems with the $PATH variable in the venv, so HA cannot find the commands.
Run your commands with the full path, so insteed of echo try /bin/echo for the command_on: statement and in the scripts.
You can get the full path with which echo as normal user without the venv.
If your script is executable (chmod a+x), you don’t need bash /path/to/script.sh , its enough when you type /path/to/script.sh , but i would always type the full path to the script.
That`s all i can say to command_line problems in HA at the moment…
@VDRainer I finally got the switch working, thanks for your help. For your information or for others who are facing the same issues. Here are the steps I made to get the scripts working.
I’ve copied the scripts into the .homeassistant folder
made them executable with a+x as VDRainer mentioned
logged into the virtual envrionment also as VDRAiner mentioned
Made the virtual environment use passwordless ssh to my second raspberry pi
In my config file, I’ve written the full path to the scripts, without bash - only the path
Did you create a keyfile for ssh, or did you remove the password on machine 2? (Hoping for the first alternative, or you might create trouble for yourself later on).
Hi guys,
I am reviving this topic, I seem to have some issues with this command line.
I have used it in the past just fine, but now I can’t figure out what is happening.
I get:
This will generate a textfile in your config folder, it will display the log of your command.
I am on HassIO so you may have to change the paths according to yours. Also I am not using a password, instead I am using a Key File for autentification.
That’s to make ssh runs correctly and is using the correct id_rsa file.
Try find out which folder your id_rsa file is located under and probably don’t need your 1st sudo command.