Constructing strings before sending them to tts

Hi peeps,
I want to construct a full string BEFORE sending them to a tts, because my google speakers are very inconsistent lately (they start late, they start tts the second part before the first one is finished and so on
I tried the delay option, the waking them up just before action, the wait template the ‘… (my sentence)’ trick but nothing is satisfying
In need sth like a string attach command based on randomization.
To (hopefully make it more clear): I want to have an ‘hello’ then an ‘i want to inform you about’ and then the statechange or sth other

I use templates, cause I want to have my speakers action based on other sensors like presence and so …

template_begroeting_tts:
  alias: template_begroeting_tts
  sequence:
    - service: tts.reversotts_say
      data_template:
        entity_id: "{{ entity_id }}"
        message: >-
          {% if now().strftime('%H')|int < 12 -%}
            . . . Goede morgen. . .
          {%- elif now().strftime('%H')|int >= 12 and now().strftime('%H')|int < 17 -%}
            . . . Goede middag. . . 
          {%- else -%}
            . . . Goede avond. . . 
          {%- endif %}
        #language: "nl"
        cache: true

then a randome inform sentence:

template_notificatie_random_tts:
  alias: template_notificatie_random_tts
  sequence:
    - service: tts.reversotts_say
      data_template:
        entity_id: "{{ entity_id }}"
        message: >-
          {{ [". . . Mag ik er beleefd op wijzen dat . . . ", 
          ". . . sorry dat ik u even dien te storen maar . . . ", 
          ". . . ik laat u weten dat",
          ". . . Even ter herinnering dat", 
          ". . . Ik ontvang de melding dat", 
          ". . . Even ter herinnering dat", 
          ". . . ik heb zonet gedetecteerd dat", 
          ". . . ik detecteer dat",
          ". . . mijn sensoren melden me dat",
          ". . . een gebruiker vroeg mij een actie dus . . . ",
          ". . . ik informeer u even dat"]  |random }}
        #language: "nl"
        cache: true
    - delay: "{{ wachttijd}}"

and then the actual information (part of an automation that called the two scripts above and then : )

            - service: tts.reversotts_say
              data:
                entity_id: media_player.allespiekers
                message: ". . . . . de Praktijk modus werd uitgeschakeld"
                cache: true

any idea’s like string + string or someting like string = .appendstring ??
thanks !
Kjoere

Why not just create templates for the portions and then literally just say them all at once?

message: >-
{{states(‘sensor.greetings_template’)}} {{states(‘sensor.randomthing’)}} etc…

There’s a pretty good video from Jeff on the Slacker Labs channel about using macros in Jinja tempates to build a briefing script that incorporates multiple parameters that might be helpful to you.

1 Like

Thanks Calisro, I did some script testing and your idea seems to work just fine.
Now I just need to adapt my 287 automations lol