I’m trying to replicate my Google Home “Bedtime” script in HA, which reads out the weather, turns off lights and locks doors, and then plays some white noise.
Most of this is no problem, except that I can’t seem to figure out how to get the script to wait for TTS to complete before proceeding. As this is a “forecast” with an indeterminate amount of text to read, using delay seems like a bad solution. I tried moving the TTS portion to its own script, call it from the “Bedtime Routine” script, but as this new script also immediately turns OFF while the TTS is still active, this option also just skips the TTS altogether.
Here’s my script(s) right now.
nightly_forecast_tts:
alias: Nightly Forecast TTS
sequence:
- service: tts.cloud_say
data:
entity_id: media_player.master_bedroom_soundmachine_mpd
message: Turning off lights and locking doors. {{states.sensor.forecast.state}}
options:
gender: female
language: en-GB
mode: restart
icon: mdi:text-to-speech
master_bedroom_sleep:
alias: Master Bedroom Sleep
sequence:
- service: media_player.volume_set
data:
volume_level: 0.4
entity_id: media_player.master_bedroom_soundmachine
- service: script.nightly_forecast_tts
- service: homeassistant.turn_off
data:
entity_id:
- light.back_entry_patio_lights
- switch.front_porch_sconces
- light.front_foyer_main_lights
- light.kitchen_main_lights
- light.master_bedroom_brendan_table_lamp
- switch.rear_entry_lights_6
- service: script.master_bedroom_sleep_noise
mode: restart
icon: mdi:sleep
master_bedroom_sleep_noise:
alias: Master Bedroom Sleep Noise
sequence:
- service: media_player.select_source
data:
source: Sleep
entity_id: media_player.master_bedroom_soundmachine
mode: restart