Pass value to command line

Yeah, I thought about just modifying the shell_command and submit a PR, but just didn’t get around to it yet because of the additional stuff required, such as a test and documentation. Will try to do it soon.

Let me know if you need help with those steps. I’m all gung-ho about the capability and just blogged and posted a video using it.

Isn’t it funny how our wives push us to go that extra step in getting it off phones and on to other terminals (tablets, remotes, etc) for them to use?

What do you mean?

@dennisaion, haha yes, totally. My wife doesn’t want to pull out her phone and press a few buttons to get the lights to go on or off. she wants one tiny action. The IR remote works well in a one-bedroom apt.

1 Like

@partofthething Mine asked for physical switches (also single action) around the house. And so the Wall Mounted Touchscreen project ( Wall mounted touchscreen ) was born. :laughing:

@hordur I couldn’t wait. I’m sorry. The template capability is now live in 0.22.

1 Like

This is awesome! I couldn’t find the explanation of the write up. Is there a simple example of how you set brightness or color of lights? I’m not familiar with the oncmd used in the link. Thanks!

1 Like

I’m trying too use a template in a sheel command. I´m using a input slider to pass the value.

Here is my setup:

input_slider:
 tv_volume:
    name: TV Volume
    initial: 8
    min: 1
    max: 20
    step: 1

shell_command:
 lg_volume_9: sudo echo ke 01 9 > /dev/ttyUSB0
 set_volume_tv: 'sudo echo kf 01 {{ states.sensor.input_slider.volume_tv | int }} > /dev/ttyUSB0'

When I run the lg_volume_9 works very well, but when I run set_volume_tv doesn´t work.

I try also transform the input slider as a sensor and doesn´t work.

What is the solution for me?

Thank´s

try:

set_volume_tv: 'sudo echo kf 01 {{ states.input_slider.volume_tv.state | int }} > /dev/ttyUSB0'

Thanks for the help.

But don’t work.

I m trying other away. My Lg tv have netcast, i will try use the input slider to change te volume.

Sorry,
I’ve got mines working without quotes:
set_volume_tv: sudo echo kf 01 {{ states.input_slider.volume_tv.state | int }} > /dev/ttyUSB0

Is it possible to use shell_command with data_template or some way to pass the entity_id as a variable to the shell command?

I’m trying to use one shell command for many things and I want to reference the calling entity name in the shell command.

This currently works but doesn’t allow much flexibility because the light name is specified.

shell_command:
  light_dim: ''/usr/local/bin/light_dim.sh {{ states.input_slider.light_office_ceiling.state | int }}'

Obviously this doesn’t work but something like:

shell_command:
  light_dim: '/usr/local/bin/light_dim.sh {{ states.input_slider.{{ state.entity_id }}.name }}'

That way I don’t have to have a shell command for each light.

In your shell_command, just use:

shell_command:
  light_dim: '/usr/local/bin/light_dim.sh {{ value }}'

Then, in your automation,

  action: 
    - service: shell_command.light_dom
      data_template:
        value: >
          {% template logic to determine value to send %}

“value” is passed as an argument to the shell_command.

5 Likes
  1. How did someone like your post before me??
  2. THANKS! I thought the parameters for data_template had to be available in the component.

Hi,
I am trying to set my AC to any temperature using an input slider and IR commands but unable to do it.
I can turn ON and OFF the AC using scripts but changing the temperature using the input slider is not working for me can you help me in that.

Post your automation/config so that we can help debug. (Use preformatted text, btw).

Confirm that your IR commands to change temp work when set manually (use the services dev tool to test).

Yes IR commands are working manually. The configuration.yaml file is below.

automation:
  - alias: run_set_ac
    trigger:
      platform: state
      entity_id: input_slider.ac_temperature
    action:
      service: script.set_ac_to_slider    
       
input_slider:
  ac_temperature:
    name: A/C Setting
    initial: 24
    min: 20
    max: 24
    step: 2

the script.yaml file

set_ac_to_slider:
  alias: AC ON
  sequence:
    - service: shell_command.set_ac_to_slider
ac_off:
  alias: AC OFF
  sequence:
    - service: shell_command.ac_off

the shell commmand.yaml file

ac_off: irsend SEND_ONCE Orientac OFF
set_ac_to_slider: 'irsend SEND_ONCE Orientac ACon_{{ states.input_slider.ac_temperature.state }}'

You may need {{ states.input_slider.ac_temperature.state | int}} as i think it defaults to float

Try just using a variable in the shell command and pass the input slider value to the shell command from your script instead. I know that way should work, I haven’t tried it the way you are doing it personally. @ih8gates example above should work. Pass value to command line