Pass variables to shell_command

Hi guys,

I have been endlessly trying to pass parameters to a shell_command with no luck. I have tried every suggestion on the forums and the most progress I have made was to update the value to blank and not the actual value I am specifying in the data template.

My shell_command:

set_location: 'python /home/homeassistant/.homeassistant/scripts/set_global_user_state.py 1 "{{ location }}"'

Executing this script directly from terminal works great. It updates as it is supposed to so the issue is not within the py script.

I have tested the script in services by calling the shell_command.set_location service with the following service data:

data_template:
  location: "Test"

Problem is, the value does update, but it updates to a blank value instead of “Test”? as if the {{ location }} variable has nothing in it.

I also have the following automation set up and when manually triggered, the result is the same.

- id: 'xxxxx'
  alias: Update Global Location State
  description: ''
  trigger:
  - platform: webhook
    webhook_id: '2'
  condition: []
  action:
  - data:
      data_template:
        location: >
          {% states(''device_tracker.life360_jj'') %}
    service: shell_command.set_location

Any help would be appreciated!

Thanks
J

I made some progress by changing the following:

data_template:
  location: "Test"

to

data_template:
location: "Test"

After making this change, the test service call updated successfully to "Test".

I modified my automation to the following:

- id: 'xxxxx'
  alias: Update Global Location State
  description: ''
  trigger:
  - platform: webhook
    webhook_id: '2'
  condition: []
  action:
  - data:
      data_template:
      location: >
        {{ states("device_tracker.life360_jj") }}
    service: shell_command.set_location

it now updates the value to "{{ states(device_tracker.life3".

I have tried modifying my automation in various ways suggested by other posts, however, it keeps updating the value to either "{{ states(device_tracker.life3" or "{{".

- id: 'xxxxx'
  alias: Update Global Location State
  trigger:
  - platform: webhook
    webhook_id: '2'
  condition: []
  action:
  - service: shell_command.set_location
    data_template:
      location: >
        {{ states('device_tracker.life360_jj') }}