How continue play the previous music after a tts voice announcement?

Hi @ArielBaravalle,
I agree with @fanuch

Here is a modified version of the script that takes two parameters:

  • the tts message
  • the media player entity_Id so you ca use it with different media players in different cases.

and finally I added taking a back up of the volume prior the TTS, securing the TTS message is played at a given level example 75% and then restoring the original volume.

alias: TTS and resume
variables:
  mediaplayer_State: '{{ states(tts_entity) }}'
  mediaplayer_media_content_id: '{{ state_attr(tts_entity,''media_content_id'') }}'
  mediaplayer_Source: '{{ state_attr(tts_entity,''media_channel'') }}'
  mediaplayer_volume_level: '{{ state_attr(tts_entity,''volume_level'') }}'
sequence:
  - service: media_player.volume_set
    data:
      entity_id: '{{ tts_entity }}'
      volume_level: 0.75
  - service: tts.google_translate_say
    data:
      entity_id: '{{ tts_entity }}'
      language: en
      message: '{{ msg }}'
  - delay:
      hours: 0
      minutes: 0
      seconds: 5
      milliseconds: 0
  - service: media_player.volume_set
    data:
      entity_id: '{{ tts_entity }}'
      volume_level: '{{ mediaplayer_volume_level }}'
  - service: media_player.play_media
    data:
      entity_id: '{{ tts_entity }}'
      media_content_id: '{{ mediaplayer_media_content_id }}'
      media_content_type: music
  - delay:
      hours: 0
      minutes: 0
      seconds: 10
      milliseconds: 0
  - choose:
      - conditions:
          - condition: template
            value_template: '{{ mediaplayer_Source != None }}'
        sequence:
          - service: media_player.select_source
            data:
              entity_id: '{{ tts_entity }}'
              source: '{{ mediaplayer_Source }}'
  - choose:
      - conditions:
          - condition: template
            value_template: '{{ mediaplayer_State != ''playing'' }}'
        sequence:
          - service: media_player.media_pause
            data:
              entity_id: '{{ tts_entity }}'
mode: single

and here is an action example from an automation showing how to call the script and pass the parameters:

  - service: script.turn_on
    target:
      entity_id: script.tts_and_continue
    data:
      variables:
        msg: this is a test message, replace it by yours
        tts_entity: media_player.spisestue

Let me know if you have other challenges
good luck :slight_smile:

3 Likes