Hi i made sensor that must grep file and put result to sensor
content of bash script
#! /bin/bash
grep $@ $(dirname $(realpath "$0"))/davis_forecast.csv |sed -r 's!^[^,]+!!' |cut -c2-|head -1
On host all work fine:
~$ sh /usr/share/hassio/homeassistant/python_scripts/davis_forecast.sh 192
В основном облачно и ожидается похолодание. Вероятны осадкив течении 12 ч временами сильные. Ветренно.
and i make sensor
- platform: command_line
name: Прогноз погоды
command: "sh /usr/share/hassio/homeassistant/python_scripts/davis_forecast.sh 192"
And recive in log
2021-07-18 11:51:15 ERROR (SyncWorker_2) [homeassistant.components.command_line] Command failed: sh /usr/share/hassio/homeassistant/python_scripts/davis_forecast.sh 192
How did you install Home Assistant? It is probably running inside a docker container, which does not have your script in /usr/share/hassio/homeassistant/python_scripts/
. Your config directory should be mounted as /config
inside the container, so I would try moving the shell script there (and the csv file it tries to read).
Also, I would put the path to the csv file in quotes in case it contained spaces.
$ shellcheck -
#! /bin/bash
grep $@ $(dirname $(realpath "$0"))/davis_forecast.csv |sed -r 's!^[^,]+!!' |cut -c2-|head -1
In - line 1:
#! /bin/bash
^-- SC1114: Remove leading spaces before the shebang.
In - line 2:
grep $@ $(dirname $(realpath "$0"))/davis_forecast.csv |sed -r 's!^[^,]+!!' |cut -c2-|head -1
^-- SC2068: Double quote array expansions to avoid re-splitting elements.
^-------------------------^ SC2046: Quote this to prevent word splitting.
^--------------^ SC2046: Quote this to prevent word splitting.
For more information:
https://www.shellcheck.net/wiki/SC1114 -- Remove leading spaces before the ...
https://www.shellcheck.net/wiki/SC2068 -- Double quote array expansions to ...
https://www.shellcheck.net/wiki/SC2046 -- Quote this to prevent word splitt...
What is your installation method of HA?
If you are using some form of containers, then the path from the host and the path in HA are different.
So, I guess that /usr/share/hassio/homeassistant/python_scripts/davis_forecast.sh
is not correct from within the container.
yes - there was problem that i ran it wit absolute path. make it relative and it work
BTW how to run script from other path (for example from /home dir)
What exactly did you change? Please post your current config of the command line sensor and the contents of your script.
If you are running Home Assistant in a docker container (check with docker ps
), I don’t think the /home
directories of the host OS will be mounted inside the container.
- changed shell script to
#! /bin/bash
grep "$@" "$(dirname "$(realpath "$0")")/davis_forecast.csv" |sed -r 's!^[^,]+!!' |cut -c2-|head -1
In my way it’s not critical - i will never make dir or file with spaces in name. But it’s bug.
2. changed sensor
- platform: command_line
name: Прогноз погоды
command: "sh /config/python_scripts/davis_forecast.sh {{ states('sensor.forecast_rule') }} "
for real sensor i change value 192 to template {{ states(‘sensor.forecast_rule’) }}