Using TTS to get Home Assistant to Tell You What To Wear
Home Assistant allows for Text-To-Speech (TTS) functionality, which is ultra powerful and can provide essential alerts (e.g. weather changes) or just act as your personal Jarvis/Friday. In this guide, we’re going to create a script to make an announcement on a specific speaker with helpful wardrobe information.
Getting Started
This guide builds on a previous project that we’ve done: Use Home Assistant to Help Plan Your Wardrobe, and it’s worth ensuring that you’ve completed that before starting here. The project here is simple, now that we’ve got a sensor/variable with some predefined clothing choices in Home Assistant, we can use the TTS functionality, and some scripting to broadcast a helpful message on a nearby speaker.
Note: You will need a speaker that is defined as a Media Player within Home Assistant. In my case, I’m using a Sonos speaker with the inbuilt Sonos integration.
First up is to enable the TTS functionality by defining it in your configuration.yaml file. I’ve chosen to use Google TTS/Say, but there’s also the possibility of using the Microsoft TTS engine. Here we will just follow the guidance, defining the platform, service and IP location of our Home Assistant implementation, plus configuring caching (where relevant).
This is what the YAML looks like:
Making It Work
Now that TTS is set up, it’s a case of creating a script and populating it with the media player you want to target, and the message to play. You also have the option of providing a meaningful name/alias, defining an icon and setting running mode (recommendation is single). In terms of caching, it’s wise to set this to false, as the content of the message is likely to change each time the script runs.
What makes this TTS script smart is the embedding of sensors within the TTS payload/message. Here, we’ve used weather sensors to give a feeling of weather it’s sunny, raining or otherwise — as well as the ambient temperature outside. The structure for this is {{states.(‘sensor.sensor_name’)}}. You can also use sensor attributes.
This is what it all looks like in YAML: