My need: DirecTV channel changing using a numeric input rather than slider because there are way too many channels. That means I need to pass a parameter on value change to shell_command as simplest method. The value change being sensed seems to work well with input_text and input_number component types. I can easily make my light switch toggle on any change of value with the config below.
However, when trying exactly the same thing as in that quoted example, which is using the shell_command component. When doing so, the automation service command never fires. I can use the same exact shell command in a standard command_line switch and it easily executes. There seems to be an issue with automation->action->service->shell_command or shell_command component in general but I’d guess there’s be a lot more folks posting the problem.
Hope that makes sense the example below is where the shell_command of the automation never fires. Thanks for your time and input!
You’re a friggin saint I should have taken that hint from other similar posts especially because I needed this exact provision for Apache/PHP on another project. However, what had me fooled is command_line switch was working, only automations were not. Anyway here’s the solution and I appreciate your quick/correct response!!! I’ll also post the final DirecTV channel changer when done.
In Linux run this command: sudo visudo
Add the following underneath the root user: your_user ALL=(ALL:ALL) ALL
Sorry @j.assuncao one more issue is that the passed variable is not respected just like the original sample from here. I cannot get a passed parameter to work like the channel below. The text file never gets created as soon as I used the curly braces. When I remove the parameter then the text file gets created again. Let me know if I should open up a separate thread on this. Thanks again!
shell_command:
living_room_tv_channel: '/bin/echo ran {{ channel }}> ~/jz.txt'
If you test in Developer Tools > Templates the variable {{ channel }} what is the result? I think you should be using something like {{ states.input_text.living_room_tv_channel.state }}
If I use templates then it works great and shows the number as expected. Keep in mind the goal is to pass a variable/parameter via automation->action and not store everything as a state. Having said that, I tried what you mentioned and it unfortunately also fails me. See the below 1st example never works while the 2nd example always works properly. If I change it NOT to have a templated value then it works again just like the 2nd example.
So damn weird, none of the templated attempts work at all. As soon as I have curly braces, it all fails. Tried quotes, no quotes, etc. I’ll pick this up later once I’ve had a chance to consume the post you provided along with other linked posts on that one. Seems like there are lots of gotchas around the subject and one dude wrote his own component type to get this worked out
Have a great one and I’ll make sure to post back with results after trying every linked piece of content.
Yes, that is weird… Sorry for not being able to help you more. Personally i don’t use any command line scripts (with or without templates) but i’ll need that soon as i am planning to send commands for my TV box. Guess i’ll start my work on that sooner than expected… lol…
Please post here your results and i’ll do the same. I have the feeling that this is going to be a post with many reads…
You got it and thanks again! Why would folks not want to be able to change their TV channel from HA, right seems logical to me. I’ll post back with some good results hopefully…
Tried with {% variable %} and normal {{ states.input_text.tv_channel.state }} and a few more mixes and variations. I’m never able to pass a parameter to the shell_command.
I may respond to the thread you quoted given the action there. Thanks for all of your help.
Hi @JZhass. I just remembered that I had a similar problem when sending time and date within a template for a notification (for Zanzito). I had to use {% raw %} {% endraw %} to get the variables to show.
So, try using living_room_tv_channel: '/bin/echo "{% raw %} {{ channel }} {% endraw %}" > ~/jz.txt'
Didn’t work again with the raw/endraw tags… I even tried something that must have worked for that poster here and same results after changing the shell_command to: dtv_channel: '/bin/echo {{ip}} > ~/jz.txt’
However, then changing the command to the following always executes correctly with my trigger and I can see jz.txt created every time: dtv_channel: '/bin/echo test > ~/jz.txt’
Frustrating I’m thinking of opening a GitHub bug on this. Can somebody please confirm that they’re successfully using passed parameters to shell_command and on the current version of HA?