Shell_command not evaluating variable/template values

This worked before as is, I think it got broken in one of the last versions but I’m not sure.
I use the value of an input_number and pass it as int to shell_command
I’ve also enabled DEBUG traces to verify the data exists and it looks OK, however, the shell command is executed with the variable name and not with its value

switch:

    my_switch:
        friendly_name: MySwitch
        value_template: "{{ is_state('switch.some_switch', 'on') }}"
        turn_on:
          service: shell_command.turn_on
          data_template:
            duration: "{{ states.input_number.my_input_number.state | int }}"
        turn_off:
          service: switch.turn_off
          data:
            entity_id: switch.some_switch

and the relevant shell_command:

  turn_on:  'python3 /config/control.py -m on -d {{ duration }}'

Logs:

home-assistant   | 2018-10-06 19:10:32 DEBUG (MainThread) [homeassistant.components.websocket_api] WS 140126865050704: Received {'type': 'call_service', 'domain': 'switch', 'service': 'turn_on', 'service_data': {'entity_id': 'switch.my_switch'}, 'id': 18}
home-assistant   | 2018-10-06 19:10:32 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: domain=switch, service=turn_on, service_data=entity_id=switch.my_switch, service_call_id=5f203ee32e29478cbf87045961929ee6>
home-assistant   | 2018-10-06 19:10:32 INFO (MainThread) [homeassistant.helpers.script] Running script
home-assistant   | 2018-10-06 19:10:32 INFO (MainThread) [homeassistant.helpers.script] Executing step call service
home-assistant   | 2018-10-06 19:10:32 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: domain=shell_command, service=turn_on, service_data=duration=30, service_call_id=af508fade98b407d88491ada1ac395bf>
home-assistant   | 2018-10-06 19:10:32 DEBUG (MainThread) [homeassistant.components.shell_command] Stdout of command: `python3 /config/control.py -m on -d {{ duration }}`, return code: 1:

Notice the duration=30 that passed to the shell_command, but the stdout of the command containes the variable name {{ duration }} and not the value.

I’ve tried putting quotes around the {{ duration }}, without white spaces {{duration}} and without the single quote on the entire command. nothing works.

What you copied here does not contain the stdout of the command. What you show is the raw command (before template rendering) and the returned status code from running the command. (Unfortunately the rendered arguments are not output to the log.) The next output line (which you didn’t include here) should show the actual stdout from running the command.

1 Like