Hello there,
I use a command line switch to control the state of my own traccar server. Until recently (a few weeks perhaps?) everything was fine. But then the state of the switch stopped working. I still can use the “on” command, but then the switch falls back to “off” state and doesn’t update.
I tried checking the commands manually, which works fine, and checked the value template in the templating checker, which returns “false” which is fine, as i can’t give the commandline response to it as a value. But anyways: the syntax seems to be OK.
anybody here able to help me with this? i have tried n versions of command_state and value_template now. nothing seems to work.
the documentation is way to sparse to help me with this. I’m grateful for any hints how to produce working commandline switches with state
I’ll keep writing, to document my findings, also perhaps somebody runs in to the same problem.
First to know: I do NOT use Docker, my homeassistant is a clean core install on a minimal raspbian. So Problems between host and Container can’t be the issue.
Instead it seems to be the case that homeassistant uses sh as a shell which means many things do not work, and even whole scripts, called with /bin/bash fail at certain points (using of awk or xargs), to make it more complicated: Every of the following commands has been testet with the user running homeassistant, with bash an sh, and they always work. But if i want to use them as state or off command they behave different.
echo foo
works fine.
ps -ef
does work but is pretty useless
ps -ef | grep forecast
same
ps -ef | grep forecast | grep -v grep
fails with “grep not found”
pgrep -f forecast_server.py
works fine, but always returns 0, and i still haven’t found a way to parse the stdout response for “value”
and last:
pkill -f forecast_server.py
works in no iteration (with /bin/bash, as /usr/bin/pkill …)
Just
/bin/bash pkill -f forecast_server.py
gives me a slightly helpful hint: /usr/bin/pkill: /usr/bin/pkill: cannot execute binary file
Has anybody an idea how to find out what works in hass and what not without guessing? Or preferably a method to force hass to simply use bash. I would like to have it back like about december 2020, where it just worked with the setup in my first question. This starts to get really annoying. (I’m using the python-forcast thingie now, because the traccar does not like being killed, revived and killed again in rapid succession, but the commands were identical)
Ah, Sorry, forgot to mention this: I tried with direct paths. But for every command i listed there is no difference in behaviour when using $command or /usr/bin/$command
just when using /bin/bash in combination it complains as aforementioned.
It really looks like there is a special reduced set of instructions, and even using /bin/bash $script.sh results in failure if using one of the “unknown forbidden words”