Hi, I have a shell_command
that I need to pass an input_number
to. Said shell_command
has a pipe in it because I’m echo-ing a string that is piped into nc
.
My issue is that the shell_command
works fine if I have everything hard-coded. But when I replace the hard-coded value with states("input_number.my_number")
, Home Assistant decides to echo everything, including the pipe character |
and what’s behind it.
To illustrate simply:
configuration.yaml
:
shell_command:
my_command: echo "oh hi mark" | grep mark
The above correctly echoes “oh hi mark” then greps the result, showing “oh hi mark” as stdout if I run the command via Home Assistant > Developer Tools > Services > select my_command, and it correctly shows an empty stdout if I grep on a non-present string.
But now let’s use a variable instead:
shell_command:
my_command: echo '{{ states("input_number.my_number") }}' | grep it_wont_work
Now if I run this via the Dev Tools, what I get as stdout is:
stdout: 15.0 | grep it_wont_work
stderr: ""
returncode: 0
That’s wrong: stdout should be the output of grep (i.e. ""
), not of the whole echo line.
How can I fix this?
Thank you.