It works perfectly on my W10 PC. I copied the .py file to \hassio\config\python_scripts\bus-sensor.py and included the following in the configuration.yaml:
sensor:
- platform: command_line
name: Next bus
command: python /home/pi/.homeassistant/config/python_scripts/bus-sensor.py
After restarting HA, I get the following error in the Log:
Command failed: python /home/pi/.homeassistant/config/python_scripts/bus-sensor.py
I have tried changing “python” with “python3” and the path to “/config/python_scripts/bus-sensor.py” but nothing works.
Hello … Welcome to Home Assistant community !
Strange that .homeassistant directory is a sub directory of “pi” …
If I have to do this in my Home Assistant installation (in a virtual environment), the command should be:
python3 /home/homeassistant/.homeassistant/config/python_scripts/bus-sensor.py The py file should be executable as well (chmod x) I think. command is a string so maybe add quotes as well… Here is an example from my installation…
Thanks for your answer! I tried as you said, but, unfortunatelly, still the same error. This is the config now:
sensor:
- platform: command_line
name: Next bus
command: "python3 /home/homeassistant/.homeassistant/config/python_scripts/bus-sensor.py"
When I try to navigate to that path through ssh I get:
core-ssh:~# cd /home/homeassistant/.homeassistant/config/python_scripts/
-bash: cd: /home/homeassistant/.homeassistant/config/python_scripts/: No such file or directory
You have probably copied the file to the wrong directory or you are searching for the file in the wrong directory…
If you look at \hassio\config\python_scripts\bus-sensor.py … does it exist ?
if yes, why not: “python \hassio\config\python_scripts\bus-sensor.py”
For some reason the double backslash is not appearing in the original post. But that path is where I placed the .py file from my Windows PC using Samba.
When I try to run python from ssh I get this:
core-ssh:/home# python3 foo
-bash: python3: command not found