Pass value to command line

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:

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

 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?



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.

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.

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

Obviously this doesn’t work but something like:

  light_dim: '/usr/local/bin/ {{ 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:

  light_dim: '/usr/local/bin/ {{ value }}'

Then, in your automation,

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

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

  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.

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.

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

the script.yaml file

  alias: AC ON
    - service: shell_command.set_ac_to_slider
  alias: AC OFF
    - 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

Thanks for your kind help. But I have done it the other way

You’re not actually doing it like in my example. I’m passing the variable via a data_template. I’m not sure if any template value is valid there.

Try passing the script a value from the automation’s action like in my example.

thanks for your help but i have done it without using automation action

I’m trying to use the shell command with an input select, to change the predefined heat programs of my Buderus central heating unit. The Buders KM271 serial board is configured with a stand alone FHEM instance, where i can send commands via telnet to.

So what I want to do is, to pass the input select value to the shell command and use the value to chance the heat program and use an automation to trigger the service.

  • action:
    • service: shell_command.set_heatprogramm
      alias: run_set_heatprogramm
      id: ‘1510046601796’
    • entity_id: input_select.heatprogramm_select
      platform: state

To change the FHEM values via telnet I use netcat (nc) to send the commands to FHEM, but I have no idea how to escape the state of the input select so thats inside the command line.

set_heatprogramm: ‘echo “set Buderus hk1_programm {{ states.input_select.heatprogramm_select.state }}” | nc 192.168.x.x 7072’

Due to the fact that i have to use " to send the whole set … string to fhem with netcat i have to include the input select state in which kind of formatting?

Logfile after selection:

2017-11-07 11:09:53 INFO (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: service_data=option=frueh, entity_id=input_select.heatprogramm_select, service=select_option, service_call_id=1973120752-35, domain=input_select>
2017-11-07 11:09:53 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: old_state=<state input_select.heatprogramm_select=mittag; friendly_name=Heizprogramm, options=[‘eigen’, ‘familie’, ‘frueh’, ‘mittag’, ‘nachmittag’, ‘senior’, ‘single’, ‘spaet’, ‘vormittag’] @ 2017-11-07T10:46:59.973644+01:00>, entity_id=input_select.heatprogramm_select, new_state=<state input_select.heatprogramm_select=frueh; friendly_name=Heizprogramm, options=[‘eigen’, ‘familie’, ‘frueh’, ‘mittag’, ‘nachmittag’, ‘senior’, ‘single’, ‘spaet’, ‘vormittag’] @ 2017-11-07T11:09:53.275219+01:00>>
2017-11-07 11:09:53 INFO (MainThread) [homeassistant.components.automation] Executing run_set_heatprogramm
2017-11-07 11:09:53 INFO (MainThread) [homeassistant.core] Bus:Handling <Event logbook_entry[L]: message=has been triggered, name=run_set_heatprogramm, domain=automation, entity_id=automation.run_set_heatprogramm>
2017-11-07 11:09:53 INFO (MainThread) [homeassistant.helpers.script] Script run_set_heatprogramm: Running script
2017-11-07 11:09:53 INFO (MainThread) [homeassistant.helpers.script] Script run_set_heatprogramm: Executing step call service
2017-11-07 11:09:53 INFO (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: service_data=, service=set_heatprogramm, service_call_id=1973120752-36, domain=shell_command>
2017-11-07 11:09:53 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_executed[L]: service_call_id=1973120752-35>
2017-11-07 11:09:53 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_executed[L]: service_call_id=1973120752-36>
2017-11-07 11:09:53 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: old_state=<state automation.run_set_heatprogramm=on; friendly_name=run_set_heatprogramm, id=1510046601796, last_triggered=2017-11-07T10:47:00.068473+01:00 @ 2017-11-07T10:23:24.406207+01:00>, entity_id=automation.run_set_heatprogramm, new_state=<state automation.run_set_heatprogramm=on; friendly_name=run_set_heatprogramm, id=1510046601796, last_triggered=2017-11-07T11:09:53.357611+01:00 @ 2017-11-07T10:23:24.406207+01:00>>

Here is my code:
- service: shell_command.enter_task
value: >

enter_task: ‘echo {{ value }}>>/home/homeassistant/.homeassistant/schedule’

name: Input task

Basically it is the same as yours. Tried every possible thing I could, but it just doesn’t work. If I remove {{value}} from the shell_command, it works fine, but as soon as I try to input any varibale/parameter in the command line, its not working.

PS. Ignore the indentation, they are correct, checked them several times. I just don’t know how to enter the code in the format as you did in your comment. New here

Do you need a space between the value and the redirection?

    enter_task: ‘echo {{ value }} >> /home/homeassistant/.homeassistant/schedule’


no templating within shell commands command_line is dumb and driving me nuts.

This was fixed 3 years ago - if it’s not working for you, create a new thread with your code for someone to have a look at, or if you’re 100% confident that your code is correct, report it as a bug.