DirecTV - Switching Channels - Input & Automation

Hi gang!

I’m pretty much replicating the example at the bottom of this HA component:

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 :slight_smile: the example below is where the shell_command of the automation never fires. Thanks for your time and input!

Version of HA: 0.56.2 current as of 2017-10-30


  set_ac_to_slider: '/bin/echo ran > ~/jz.txt'

    name: TV Channel
    min: 1
    max: 3
    pattern: '[0-9]*'
    initial: 241

    name: TV Chan
    initial: 24
    min: 1
    max: 99
    step: 1


- alias: run_set_ac
    - platform: state
      entity_id: input_number.tv_chan
    - platform: state
      entity_id: input_text.tv_channel
    - service: shell_command.set_ac_to_slider
    - service: light.toggle
      entity_id: light.office_closet_light

Which OS are you using? Does the HA user have enough privileges to execute the commands?

Using Lubuntu 17.04

You’re a friggin saint :slight_smile: 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
  • Save the sudoers file with Ctrl-X and restart HA.

All the best!

You’re welcome @JZhass! Please mark the answer as solution (grey check box below the post) so other people know it’s solved

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!

  living_room_tv_channel: '/bin/echo ran {{ channel }}> ~/jz.txt'


- id: directv_living_room_channel
  alias: "DirecTV Living Room Channel"
    - platform: state
      entity_id: input_text.living_room_tv_channel
    - service: shell_command.living_room_tv_channel
        channel: '202'
        ip: ''
        devicemac: 0

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.

  living_room_tv_channel: '/bin/echo {{ states.input_text.living_room_tv_channel.state }} > ~/jz.txt'
  set_ac_to_slider: '/bin/echo ran > ~/jz.txt'

Proof that template works:

First of all try the command without quotes, like:

living_room_tv_channel: /bin/echo {{ states.input_text.living_room_tv_channel.state }} > ~/jz.txt
living_room_tv_channel: /bin/echo {{ channel }} > ~/jz.txt

If it doesn´t work try one of these:

living_room_tv_channel: '/bin/echo "{{ states.input_text.living_room_tv_channel.state }}" > ~/jz.txt'
living_room_tv_channel: '/bin/echo "{{ channel }}" > ~/jz.txt'

And also, see this post:

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 :slight_smile:

Have a great one and I’ll make sure to post back with results after trying every linked piece of content.

Thanks again!!!

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 :slight_smile: seems logical to me. I’ll post back with some good results hopefully…

1 Like

Wow @j.assuncao I am coming up empty. No matter what I try from your linked post or from the site example, nothing works.

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'

Who knows, it might work!

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 :slight_smile: 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?

Have a wonderful weekend!