Jingle before TTS

sure, this is part of my scripting engine taking care of all of that:

      - service: media_player.volume_set
        data:
          entity_id: >
            {{states('sensor.intercom')}}
          volume_level: >
            {{states('input_number.intercom_volume')|float}}
      - service: tts.google_say
        data:
          language: >
            {{states('input_select.intercom_language')|lower}}
          entity_id: >
            {{states('sensor.intercom')}}
          message: >
            {{states('input_select.intercom_message')}}

hmm, not working:

> - id: '1602057758939'
>   alias: tts-terasa
>   description: ''
>   trigger:
>   - entity_id: switch.sonoff_1000e2cd1a
>     from: 'off'
>     platform: state
>     to: 'on'
>   condition: []
>   action:
>   - data:
>       media_content_id: http://192.168.1.15:8123/local/media/Airplane-ding-dong.mp3
>     entity_id: media_player.living
>     service: media_player.media_play
>   - data:
>       entity_id: media_player.living
>       language: cs
>       message: My message.
>     service: tts.google_translate_say

with error:
Logger: homeassistant.components.automation
Source: helpers/script.py:693
Integration: Automatizace (documentation, issues)
First occurred: 12:21:23 (6 occurrences)
Last logged: 12:24:38

tts-terasa: Error executing script. Invalid data for call_service at pos 1: extra keys not allowed @ data[‘media_content_id’]

OH, should be: media_player.play_media

yes, ws just posting this:

  sound_bite:
    alias: Sound bite
    mode: restart
    sequence:
      service: media_player.play_media
      data:
        entity_id: >
          {{states('sensor.sound_bite_player')}}
        media_content_id: >
          {{states('sensor.sound_bite')}}
        media_content_type: music

Yes.

You have read the docs for the media_player integration? They’re right here if you missed them.

1 Like

I am trying to modify my current automation for notification of messages at the end of a condition, but although I have added the lines you described with the appropriate changes to my addresses, the result remains unchanged.
The notification arrives but the jingle does not play, I do not understand where I am wrong.
Below the lines used:

  action:
 
  - data_template:
      message: Il microonde primo piano ha terminato!
      title: Casa
    service: notify.notify

  - service: media_player.play_media
    data:
      entity_id: media_player.mini_tutti
      media_content_id: https://myduckdnsaddress:myport/local/airplane-ding-dong.mp3
      media_content_type: music

  - service: tts.google_translate_say
    entity_id:  media_player.mini_tutti 
    data:
      message: "Il microonde al primo piano ha terminato!"                      

I suspect that no sooner has the ‘ding-dong’ been sent to the media player, the TTS gets sent.

Try putting a delay after the ding dong.

O r better yet wait for the state of the media player to change to playing and then to paused.

1 Like

Exactly what klogg said:

  1. Send the ding-dong
  2. Pause for a second (so that the change of state can be detected by HA)
  3. Wait for the state to become idle
  4. Send the TTS

Thank you for for the replies.
Later on returning home I will try.
To understand, should I put a generic pause of even 0.5 seconds or should I put a pause identical to the duration of the running mp3?

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