Does a sub-script 'inherit' a variable from a calling script?

trying to cut down on code, I hoped this would be valid, but not sure so please have a look?

      - service: script.notify_github #_update   <--- had the 2 scripts independently before, see following commented script
        data_template:
          repo: >
            {{state_attr(trigger.event.data.entity_id,'name')}}
          url: >
            {{state_attr(trigger.event.data.entity_id,'latest_release_url')}}
#
#      - service: script.persistent_notify_github_update
#        data_template:
#          repo: >
#            {{state_attr(trigger.event.data.entity_id,'name')}}
#          url: >
#            {{state_attr(trigger.event.data.entity_id,'latest_release_url')}}

script:
  notify_github:
    sequence:
      - service: script.notify_github_update    #<----these script now get the variable from above, but need to pass them on, do they?
      - service: script.persistent_notify_github_update

  notify_github_update:
    sequence:
      - condition: state
        entity_id: inut_boolean.notify_system
        state: 'on'
      - service: notify.system
        data_template:
          title: >
            Github update for {{repo}}
          message: >
           {{repo}} was updated to {{url.split('tag/')[1]}}.
           Visit the release page {{url}} to download.
           Download the [latest release]({{url}})

  persistent_notify_github_update:
    sequence:
      - condition: state
        entity_id: input_boolean.persistent_notification_create
        state: 'on'
      - service: persistent_notification.create
        data_template:
          title: >
            Github update for {{repo}}
          message: >
          ![image](/local/various/github_icon.png)  {{repo}} was updated to {{url.split('tag/')[1]}}.
           Visit the release page {{url}} to download.
           Download the [latest release]({{url}})
          notification_id: '{{repo}}'

thanks for having a look

If I understand correctly, no they don’t.

I have several places where I have to pass a variable on from ‘script1’ through ‘script2’ because it is not needed until ‘script 3’.

I think you’ll just have to repeat the data_template

ok thanks. In which case I’d better revert to the 2 individual scripts :wink: would be a nice feature though.

devs cannot implement any feature possible and want a strong use case for it :wink:

just an idea - instead of passing separate variables you can wrap them all into one JSON bundle using | to_json at the top level and extract what you need/add something at a lower level.
it’s a bit more difficult to maintain as you don’t clearly see what’s available until you look at the top level but it might have its use.

just change

script:
  notify_github:
    sequence:
      - service: script.notify_github_update    #<----these script now get the variable from above, but need to pass them on, do they?
      - service: script.persistent_notify_github_update

to

script:
  notify_github:
    sequence:
      - service: script.notify_github_update
        data_template: {'repo': '{{repo}}', 'url': '{{url}}'}
      - service: script.persistent_notify_github_update
        data_template: {'repo': '{{repo}}', 'url': '{{url}}'}

its only 2 extra lines and it’s eqivalent to:

script:
  notify_github:
    sequence:
      - service: script.notify_github_update
        data_template: 
          repo: '{{ repo}}'
          url: '{{url}}'
      - service: script.persistent_notify_github_update
        data_template:
          repo: '{{ repo}}'
          url: '{{url}}'
1 Like

thanks @petro!

will change accordingly, very nice indeed.
answer to question in topic is No, but it can rather easily be ‘solved’. As @klogg suggested in his first reply, only a bit different :wink:

Ill mark this as solved then!

in my editor this looks a bit funny (as if the template isn’t parsed correctly):

dont these templates need a quote, or , as below, a multiline: