Get random value contain formula in TTS announcement

Hi everyone, I want to get announcement with random string but my random string contain formula so that instead of calculating the formula and read it, it’s read the formula string.
How can I fix this.
Thanks in advanced

For example : I have repeat loop actions and I want read out random times/ count index each time it passed


- service: tts.google_translate_say
  data:
    entity_id: media_player.voice
    message: ' 
             {% if repeat.index == 3 %} 
	          {{[ 
                 " {{3 - repeat.index}} times ", 
	             " 45 seconds "
	            ]| random }} '

I didn’t quite understand what you are trying to achieve, but you could try something like this:

- service: tts.google_translate_say
  data:
    entity_id: media_player.voice
    message: >
             {% if repeat.index == 3 %} 
	          {{[ 
                     (3 - repeat.index) | string + ' times', 
	             "45 seconds"
	            ]| random }} '
              {%endif%}
1 Like

I want to annouce to close the door after 3 times warning and want to make it say more naturally.
Your reponse work perfectly. I finally find out my mistake.
Thank you so much.

1 Like