I need to invoke TTS on more than one entity, but I have a configuration wish: top avoid too many tts scripts each setup per message and different locations, I was thinking about writing a python_script which takes from an automation the target entities as data as well as the message, which is finally a script.
this is the automation - currently with a fake trigger (I trigger manually from dev tools):
- alias: test
trigger:
- platform: state
entity_id: input_select.presence_all_preset
to: Lange weg
action:
- service: python_script.test
data:
entities:
- media_player.squeezebox_kueche:60
- media_player.squeezebox_az:10
message: script.play_goodmorningmessage2
The python script parses the information, whereby the entities are containing the entity name and the target volume for the announcement.
This is the problematic script which actually contains the message. Invocation of the script works fine as well as tts with ONE entity:
play_goodmorningmessage2:
alias: "Nachricht: Guten Morgen 2"
sequence:
- service: tts.google_say
data_template:
message: "Test für Python"
entity_id: "{{ media_players }}"
the variable “media_players” contains at the moment a list which is passed to the following in python:
# for clarification, this is added in this post only and not part of the script (though I used it for testing)
tts = "script.play_goodmorningmessage2"
mediaplayers = [ 'media_player.squeezebox_kueche', 'media_player.squeezebox_sz' ]
# the above variable contents have been checked and are derived from the python scrypt
def play_announcement(mediaplayers,tts,hass):
for entity in mediaplayers:
service_data = { 'media_players': entity }
hass.services.call('script', tts.split('.')[1], service_data, False)
return
play_announcement(mediaplayers,tts,hass)
My problems:
- I cannot invoke a script twice in parallel :-(. Is there anyway to do this? The above fails with the second target entity to play the same message. ANd I dont want to wait until the first one finishes (set False to True in Hass.service…)
- I can have a simple script to announce a TTS message at two entities only by
play_message:
alias: "Nachricht"
sequence:
- service: tts.google_say
entity_id: media_player.squeezebx_kueche, media_player.squeezebox_sz
data:
message: "Test für Python"
This works, but seems to be against YAML structure. using a YAML list like
entity_id:
- entity1
- entity2
doesnt work.
who has an idea how I can send the required information to the script to allow it to play on multiple entities? Or - how can I use a script like the above in parallel for multiple entities?
Intention:
- definition of multiple messages
- definition of target entities for a message to be played
- simple configuration of messages (they are complex templates actually), so that I can change a message at one place only and I dont need to change multiple scripts - which I would need to address multiple entities.
I hope the problem is understandable. Thanks a lot!
André