So I know this has been talked about a bunch on other threads but nothing mentioned in those seem to be helping me. I’m trying to setup a shell_command for the first time and I can’t seem to get it to accept any parameters. The command does work without parameters though so I’m not sure what is going on.
I’ve defined the shell_command in my configuration.yaml file like this:
So if I replace {{ entity_id }} with just a hard coded value and don’t provide any service data the service call works. It only errors as soon as I add that parameter. I have tried wrapping the whole command in single quotes too and that doesn’t seem to change anything.
Any ideas what could be wrong? I’m guessing it is something super simple but I can’t quite figure it out.
Haven’t heard of lovelace_gen before. Quite new to everything here. Looks like it provides UI for generating configurations. I am handwriting my configuration.
I was just trying to use the Developer Tools and providting entity_id myself.
I’ve changed entity_id to now message.
This is what my full configuration looks like now:
configuration.yaml of my command:
The service call you’re using should not have a data_template. Try just data:. The only other suggestion I have would be to put the message in an input_text and try {{states(“input_text.example”)}} instead of {{ message }}
It maybe that shell_command does not send along the data. The example in the documentation actually directly references the state of another entity
I call it from Developer tools → Services with dir: '/' or dir: /config/ it works as expected (apart from always showing unexpanded template ls -l {{ dir }})
My command always return 0 and yours returns 1 (error).
If I pass an invalid argument though, it returns 1 and the error is exactly as yours.
So my advice is to run in console that node C:\path\to\node\script\showToast.js with a proper parameter and see if it works.
Thanks a ton! This is what helped me figure out the problem! This let me finally see what what actually being executed. Darn Windows! It seems when using parameters that the \ in my path were actually escaping characters and thus getting trimmed out. Escaping the \ characters did the trick. So my shell_command now looks like this:
Thanks for publishing the working code. Could you mark a solution post (you should have a Solution checkbox next to each post) so your topic appears as Solved and future readers could easily find the solution?
I’m looking to set up a shell_command to run CATT, that I can pass player and video IDs through to as service data. Have struggled to find concrete steps from start to finish, but this thread seems like the closest thing. Based on the information here, I would have though this is the expected config:
configuration.yaml:
shell_command:
cast_test_youtube_2: 'catt -d {{ player }} cast {{ video | urlencode }}'
Service Data: player: "192.168.0.29" video: "https://www.youtube.com/watch?v=W1ilCy6XrmI"
When I call the service, the HA logs show that the template doesn’t expand:
[homeassistant.components.shell_command] Stderr of command: `catt -d {{ player }} cast {{ video | urlencode }}`, return code: 1:
b'Error: The chosen file does not exist.\n
Trying to a better idea of what was going wrong, I also made some commands to echo into a test file:
At this stage I feel like I’ve tried a million variants of double- single- and no-quotes in various positions in the command and service data. I can’t understand where this is going wrong, so any help would be appreciated