Templating for Assist responses - Reuse data from another line

I have been creating quite a few custom responses lately, and I’m trying to fine tune the code that I canc opy and paste to new responses.

In the example below (just like all the others I’ve created so far), I’m using the same quoted text for both the text: line, and the message: line. But isn’t there a small piece of code I can put in the message: line, that will use the same data entered on the text: line? Would make copying code from the action: line onwards a breeze to other custom responses :slight_smile:

# Solar & EV
intent_script:
  Battery:
    speech:
      text: "The house battery has a charge of {{states('sensor.battery_state_of_capacity') | round(0)}} percent"
    action:
      service: "tts.google_translate_say"
      data:
        message: "The house battery has a charge of {{states('sensor.battery_state_of_capacity') | round(0)}} percent"
      target:
        entity_id: >
          {{ states('sensor.choose_speaker_cmd') }}

You can use YAML Anchors. You give the text block a name starting with a “&” (e.g. &msg1) and you reuse it using the anchor name starting with a “*” (e.g. *msg1). This should work for you:

# Solar & EV
intent_script:
  Battery:
    speech:
      text: &msg1 "The house battery has a charge of {{states('sensor.battery_state_of_capacity') | round(0)}} percent"
    action:
      service: "tts.google_translate_say"
      data:
        message: *msg1
      target:
        entity_id: >
          {{ states('sensor.choose_speaker_cmd') }}
1 Like

Thanks for letting me know. Do I need to use a different anchor id for each? Would be great if I don’t need to change any code beyond action: :slight_smile:

I believe you can use an anchor id only once. So for different text blocks you need Different IDs. But try it out.