Automation/script ID for use in other scripts

Much like how trigger IDs can be assigned inside an automation to change the action depending on the trigger, what about automation IDs so that a script may act differently depending on which automation/ script called it.

You can already pass variables to scripts when calling them.

https://www.home-assistant.io/integrations/script/#passing-variables-to-scripts

Automation:

  action:
    service: script.my_test_sctipt
    data:
      called_by: "automation_7_lights_on"
      light: light.some_light

my_test script:

script:
  my_test_script:
    sequence:
      - choose:
          - conditions:
              - condition: template
                value_template: "{{ called_by == 'automation_7_lights_on' }}"
            sequence:
              - service: light.turn_on
                target:
                  entity_id: "{{ light }}"
          - conditions:
              - condition: template
                value_template: "{{ called_by == 'automation_7_lights_off' }}"
            sequence:
              - ...etc

This is a contrived example to show how to pass variables, there are obviously better ways to do this particular sequence.

I did not know that was possible to do in that manner. Thanks for the help! I’ll be sure to give that a try.

Tom,
I have a similar question but it is a script calling a script. Call them source and destination scripts. I would like the source to be able to identify itself to the destination but by using some like a this keyword rather than spelling it out. This is a special use case involving multiple scripts calling a single destination script. The destination script will take a different action depending on which script initiated it. I can do it manually by defining called_by myself, but would be interested in knowing if there was a way I could use a template to define called_by using some variable already defined by script. If there is not predefined variable, I will create one and define it, just wanted to make sure it something was not already defined.