TTS say random sentence from array of sentence with a template inside does not work

Hi,

I am trying to get tts to say a random sentence from array of sentence with a template inside but it does not work while a solo message with the template inside or the random selection of a sentence separately does work. See also the code below.

How can I fix this?

script_test_office_speaker_say:
  alias: Script Test Office Speaker Say
  sequence:
  - service: tts.cloud_say
    data:
      entity_id: media_player.office_speaker
      message: >
        {{ (
          ' Now playing playlist called BLA',
          ' Starting playlist called BLA'
        )|random }}
      # example: 
        # ## DOES WORK
        # ' Now playing playlist called {{states("input_text.playlist_chosen_random_source")}}'
        # ## DOES  WORK
        # {{ (
        #   ' Now playing playlist called BLA',
        #   ' Starting playlist called BLA'
        # )|random }}
        # ## BELOW DOES NOT WORK
        # '{{ (
        #   ' Now playing playlist called {{states("input_text.playlist_chosen_random_source")}}',
        #   ' Starting playlist called {{states("input_text.playlist_chosen_random_source")}}'
        # )|random }}'

See this post:

Don’t use templates inside the tuple (move it outside, as shown in the linked post).

1 Like