Constructing sentences for TTS

Yes i have HA in italian. I linked Google Calendar to my HA and today for the calendars i put in this automation i don’t have any entry… But why Google Home stops to say after those lines?

It says:

 Buongiorno. Oggi è
          Thursday, 30th August
          Ora è Nubi Sparse con 25 gradi.

And then stops…

I deleted the data related to the day and now it stops always after the first two lines.

Now it says:

Buongiorno Umani.
          Il tempo è Poco Nuvoloso con 26 gradi.
          Oggi sarà Poco nuvoloso fino a stasera,

And then stops…
Really strange…
Maybe quotes problem?

are you tracking hourly_summary in your dark sky’s monitored_conditions ?

Yes, otherwise i would get error in template editor…
The editor shows correct output…

what does script.accendi_radio_googlehome_mini do?
I’m wondering whether you’re not giving it enough time to run before you do something else…

Ah, maybe…, wait… this is the script:

accendi_radio_googlehome_mini:
  alias: Accendi Radio su Google Home Mini
  sequence:
    - service: media_player.volume_set
      data_template:
        entity_id: media_player.googlehome0461
        volume_level: 0.60
    - service: media_player.play_media
      data_template:
        entity_id: media_player.googlehome0461
        media_content_id: "http://stream1.rds.it:8000/rds64k"
        media_content_type: 'audio/mp4'

ok. for the sake of this excecise, comment out the delay and script and try again. Should say everything
then you can change your delay to a wait_template:
wait_template: "{{ states.media_player.googlehome0461.state != 'playing' }}"

Yes, you’re right… without the script it says all…
Now i will add the wait_template in place of delay, right?

yes. For the days not sure why it’s in English…
Guess you could do a whole list of replace:
| replace("Monday","Lunedi") | replace...

Ok, i’ll try. How to add wait_template ? It’s another service? Or what?

remove
- delay: "00:00:10"
and replace with
- wait_template: "{{ states.media_player.googlehome0461.state != 'playing' }}"

Ok, thanks… i will try it later… btw i will let you know if all is finally working as expected.

If i use wait_template in the script or in the automation the tts doesn’t work… if i use delay it works…

I wonder whether the automation generates the TTS and sends the play command too fast and moves on. The GH isn’t yet playing and therefore the wait template is valid. Can you try and add a delay of 1 or 2 sec before the wait template?
The idea here is not to try and guess how long the announcement will be and simply wait for the GH to stop playing…

Ok, i’ll do some tests…

wait_template and delay are, in my opinion, quite broken in Home Assistant. If, for any reason, a script or automation gets triggered while it’s waiting/delaying, HA quits the delay and continues processing the rest of the commands, but doesn’t actually run the script a second time. So it’s bad twice.

I have found that using a python_script instead will allow two calls of the script to run concurrently. So, when I really need something like this, I use a python_script.

However, in this case, you should use something like assistant-relay:

https://github.com/greghesp/assistant-relay/tree/v2

You can send as many TTS notifications as you’d like and it’ll play them all, one by one, in order. It has the added benefit of not stopping whatever the google home was doing before the TTS. It pauses it, plays your TTS notification, and then continues playing whatever media you had going. The downside is, it will only broadcast to ALL google home devices. You can’t select a specific media player.

There are lots of approaches to the python_script… but I think the general idea should be that it implements a queue. It’d need to check a boolean that indicates a TTS is currently playing. If it’s on, it should add the TTS to a queue and end. If it’s off, it should set the boolean, play the tts, then unset the boolean. Then it should check the queue, if there are any items in it, it should call itself with an empty notification to play. When the script gets an empty notification, it’ll check the boolean and, if not set, set it, then play the next item in the queue, unset the boolean, and then check the queue again.

It’s a tedious bit of code to write. :confused: