Jingle before TTS

Please try reading my response

I didn’t say half a second, I didn’t say the duration of the MP3.

Sorry!
I just asked to understand how HA thinks.

However I set the pause of 1 second using the “delay” command, but the result does not change.

  - service: media_player.volume_set
    entity_id: media_player.mini_tutti
    data:
      volume_level: 0.45
  - service: media_player.play_media
    entity_id: media_player.mini_tutti
    data:
      media_content_id: https://xxxxxxx:xxx/local/airplane-ding-dong.mp3
      media_content_type: "audio/mp3"
      
  - delay: 00:00:01
  
  - service: tts.google_translate_say
    entity_id: media_player.mini_tutti 
    data:
      message: "Il microonde al primo piano ha terminato!"

How long is your ding-dong mp3?

Delay for that long (plus a bit just to confirm it works)

my ding dong lasts about 1 second

1 Like

So delay for 5 (or even 10) seconds.
Just to prove to yourself that the principle works.

1 Like

yes it worked.
first i tried it with 10 seconds and it made the sound.
so I went down to 5 seconds, up to 2 seconds which seems to be the minimum time to hear the sound.

I wanted to try 1.5 seconds but I don’t know how to set it with delay.

However, I do not know if it is a coincidence that it has to wait a little more than the duration of the mp3 to run.

You missed the whole wait part :wink:

  1. Wait for the state to become idle

https://www.home-assistant.io/docs/scripts#wait-template

- alias: "Wait until media player is stopped"
  wait_template: "{{ is_state('media_player.floor', 'stop') }}"

Replace stop with idle or whatever it is for yours

Now that everything seems to work as I wanted, I realized that this function makes me comfortable on all the automations and packages that I have active.
How can I do to recall these lines with a simple command within the active automation?
should i create a script or a separate automation?

the last working code is the following:

  - service: media_player.volume_set
    entity_id: media_player.mini_tutti
    data:
      volume_level: 0.7
  - service: media_player.play_media
    entity_id: media_player.mini_tutti
    data:
      media_content_id: https://xxxxx:xxx/local/dingdong.mp3
      media_content_type: "audio/mp3"
  - delay: 00:00:03
  - service: media_player.volume_set
    entity_id: media_player.mini_tutti
    data:
      volume_level: 0.5

to be inserted before my various “tts google translate say” of the respective automations.

I would put it in a script then call the script using

service: script.ding_dong

Calling it this way rather than `script.turn_on’ will cause your automation to stop processing until the script has ended.

This may however slightly affect the timing and cause a longer pause between the ding dong and the TTS (it my not be noticeable though) while the system waits for various states to catch up, you will have to experiment!

1 Like

As you predicted, with the script I had to increase the delay from 2 seconds to 3 seconds, otherwise it didn’t work.

Not sure if it’s still relevant, but you can use the custom integration Chime TTS to fix the issue of lag between a local mp3 and cloud TTS audio.

1 Like