So, I’m wrapping my head around this problem for some hours and still don’t know, if this is plainly impossible with HA or if I just didn’t understand, how to properly use data_template, value_template, json etc. in HA, respectively yaml.
The problem: Basically I want to define a list with items consisting of a sentence and its associated language, I want to randomly choose an item and pass it to Google TTS.
Choosing a random sentence from the list is easy with data_template:
- service: tts.google_say
entity_id: media_player.livingroom
data_template:
message: '{{ ["Hello", "World"] | random }}'
language: 'en'
But how to randomly chose a sentence together with the proper language? Obviously, the following example isn’t working as expected, as the values for both parameters are selected seperately, but I hope this makes it more clear, what I want to achieve:
- service: tts.google_say
entity_id: media_player.livingroom
data_template:
message: '{{ ["Hello World", "Hallo Welt", "Bonjour monde"] | random }}'
language: '{{ ["en", "de", "fr"] | random }}'
Besides, separate lists for sentences and languages would be hard to read and awful to edit if the lists get longer. So ideally it should be possible to have a sentence and it’s language defined in one line.
But how can I define a list consisting of items holding a sentence and its language, randomly choose an item and pass it to google_say?
Is it possible to set and use local variables in script sequences? Or is it possible to define lists as json strings, pass them to a script and parse them?
Or do you have any other ideas?