Get Home Assistant talking through Sonos speaker using Googles Text-To-Speech service

In our house we have different automations that use our Sonos speakers to say something. For example if Aurora (our daughter) opens her window, the speaker in the kitchen tells us. Our alarm also warns us if any intrusion is registred at night when we are sleeping.

To do this a TTS (Text-To-Speech) service is required. Home Assistant have integrations for different TTS services.

Setup TTS service

I have chosen Googles TTS (Text-To-Speech) service to convert text to speech. It’s quick and works quite good in Danish. It’s also the same voice used as on our Google Hubs, so I secure a look-a-like environment for our kids and my wife.

I have setup the service by adding the following line to my configuration.yaml:

Furthermore my src/apps/tts.yaml file contains the following:

You can find more information in the Home Assistant documentation for the TTS integration.

Creating a “Sonos Say” script

We use our Sonos speakers a lot. We love music, so they are running almost the whole time playing our favorite music. This also means I had a challenge when wanting Home Assistant to talk to us. I don’t want the music to stop completely, and I don’t want the volume to change.

I searched the Home Assistant forums to look if someone else had the same challenge. I found a script created by Dominik Lenarczyk (find the post here) that does what I want, so I used it and modified it a little bit (mostly around the delays to make it fit).

With this script I can simply just call it with different variabels from my automations, and then it stops playing the current playlist, turns up the volume, speak my selected text, and then starts playing my playlist from where it stopped.

I created my script file in src/scripts/sonos_say_tts.yaml – it looks like this:

Using my script in an automation

As an example on how we use it, I show the YAML configuration / code for when Aurora opens her window.

This above automations uses our Sonos Play3 in our kitchen to say on danish that “Auroras windows has been opened”.

Try it out – it’s quite useful for a lot of different scenarios and automations, and the script make is quite easy to use again and again.

Leave a Reply

Your email address will not be published.