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```
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.
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.
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.