Using tts to play a random text with a given name

Hi to all, I want write a script where tts play a random message with a given name as parameter.
This is the script:

 tts_wellcome:
   alias: "Wellcome"
   sequence:
     - service: tts.google_say
       entity_id: media_player.salotto
       data_template:
           message: >
             {{ ("Hi, {{ name }}. Wellcome back at home.",
              "Wellcome back {{ name }} .",
              "Happy to see you again {{ name }} !"
              )|random }}

and this is the action invoking the script:

 id: notify_max_at_home
  initial_state: true
  trigger:
  - platform: state
    entity_id: input_boolean.maxhome
    to: 'on'
  action:
  - service: script.tts_wellcome
    data:
      name : "Max"

I haven’t error in the configuration but the speaker says “name” instead of “Max”.
How can I solve this?

try nAme ?

Sorry I have traslated the variable from italian “nome” to “name” writing the post, and i have forgot to change it, but in the code i have the right variable, “name” in this case. I have edit the post.

not sure if this is it, but try adding the entity_id to the data_template?

 tts_wellcome:
   alias: "Wellcome"
   sequence:
     - service: tts.google_say
       data_template:
         entity_id: media_player.salotto
         message: >
           {{ ("Hi, {{ name }}. Wellcome back at home.",
              "Wellcome back {{ name }} .",
              "Happy to see you again {{ name }} !"
              )|random }}

also, and again, probably not the cause, but there’s peculiarities with spaces in Yaml, so try:

 id: notify_max_at_home
 initial_state: true
 trigger:
   - platform: state
     entity_id: input_boolean.maxhome
     to: 'on'
 action:
   - service: script.tts_wellcome
     data:
       name : "Max"

or even leave out the dashes - if you are only listing 1 trigger or action:

 id: notify_max_at_home
 initial_state: true
 trigger:
   platform: state
   entity_id: input_boolean.maxhome
   to: 'on'
 action:
   service: script.tts_wellcome
   data:
     name : "Max"

Unfortunatelly your suggestion doesn’t work. Dash and spaces are present because i made a copy and past of the single service, in the real I call more services

Looking deeper in the forum I have found the solution.

Thankyou anyway for your promp answer.

tts_wellcome:
   alias: "Wellcome"
   sequence:
     - service: tts.google_say
       entity_id: media_player.salotto
       data_template:
           message: >
             {{ ("Hi, " ~ name +". Wellcome back at home.",
              "Wellcome back " ~ name +" .",
              "Happy to see you again " ~  name +" !"
              )|random }}

a yes, that’s because one can’t use a {{}} template in a {{}} template. You can however use a variable in a template, which is what is you are doing right now.
sorry for not picking that up.

just in case you might it somewhere else:

      - service: tts.google_say
        data_template:
          language: >
            {{states('input_select.intercom_language')|lower}}
          entity_id: >
            {{states('sensor.intercom')}}
          message: >
            {{states('input_text.message')}}

is a perfectly valid script using templates

its all a matter of details in what you want to do, templates, passing variables, subscripts. Nothing is impossible…