Pausing in an automation action

I am using Google TTS to say a message through a Sonos speaker. The action works correctly and I get the spoken message but I wanted to make sure that the volume was at a certain level when the message was spoken and then return it to the previous volume.

I found a nice solution using scenes and a numeric helper but I have one problem…

I can set the volume up to .5, but it seems like the scene restore happens before the message is completed.

Is there a way to delay the last part of this so that the scene restore doesn’t happen until the message is completed?

alias: Tank -  Black tank is over 90%
description: ""
trigger:
  - platform: numeric_state
    entity_id:
      - sensor.black_tank_level
    for:
      hours: 0
      minutes: 2
      seconds: 0
    above: 90
condition: []
action:
  - service: input_number.set_value
    data:
      value: "{{(state_attr('media_player.living_room','volume_level')|float)}}"
    target:
      entity_id: input_number.mm_volume
  - service: media_player.volume_set
    target:
      entity_id: media_player.living_room
    data:
      volume_level: 0.5
  - service: tts.google_translate_say
    entity_id: media_player.living_room
    data_template:
      message: Shixxer is full  Current level is {{states('sensor.black_tank_level') }}  

  ## Can I pause here until the previous TTS completes?

  - service: media_player.volume_set
    data:
      volume_level: "{{states('input_number.mm_volume')}}"
    target:
      entity_id: media_player.living_room
mode: single```

Just a standard delay?

delay:
  hours: 0
  minutes: 0
  seconds: 2
  milliseconds: 0

I tried adding “Delay 10” In different places without success. If I add it after the TTS message, the TTS message doesn’t work at all. If I add it in the set volume service nothing happens.

Delay: 10

'''

that doesn’t look valid, it should be

delay: 00:00:10

For a 10 second delay. You could also do it longhand:

delay:
  hours: 0
  minutes: 0
  seconds: 10
  milliseconds: 0

I tried that format as well. The documentation for delay states that a single 2 digit number is assumed to be seconds.

Fair enough, but “Delay” is not “delay” and caps make a difference.

You can use the custom integration Chime TTS to play a TTS notification at a desired volume level. Once the playback finishes (regardless of how long/short the TTS message is), it restores the original volume level.

1 Like

Good point, went back and tried delay 00:00:10 in several places. No joy :frowning:

This feature is built-in to the Sonos integration. See the examples of how to use the announce option with the volume level: Sonos - Home Assistant. TTS calls require a special syntax to pass in the volume properly.

This will fade any playing music and overlay the announcement at the provided volume level. When finished your music will resume at its previous volume.

1 Like

That’s perfect, works like a charm!

Thank you!