4 ways I use randomization in my Home Assistant setup

Configurare noua (How To)

Situatie

Solutie

Rotating through voices for announcements

Every day is a surprise

Every morning, Home Assistant generates a morning briefing This pulls in information from connected calendars, weather information, and even scrapes the website where my kids choose their school lunches. All the information is gathered, and an LLM converts it into text for a spoken announcement.

The spoken announcement is generated using the Qwen3-TTS text-to-speech model. As well as its own native voices, you can also use it to clone voices, and I’ve done this for the voices of my wife and me.

Each morning, the voice in which the announcement is spoken is selected at random. It means we never know which voice we’re going to be getting each morning, which makes the announcements much more fun. My kids have even taken to trying to guess in advance.

The morning briefing is triggered when someone first walks into the kitchen in the morning. A motion sensor detects motion, and then the automation waits for two minutes to ensure that everyone has made it to the kitchen. The randomly selected announcement is then played through the smart speaker.

Selecting a random phrase for repeated announcements

The same phrase soon gets dull

A template in Home Assistant showing the Jinja random filter.

I use the same motion sensor in the kitchen for another automation. Whenever motion is detected during the day, if there hasn’t been any motion in the previous ten minutes, another announcement will play.

The announcement is a reminder to put something away or into the dishwasher while you’re in the kitchen. It works really well as a quick reminder to tidy something up while you’re there, and helps to keep the kitchen clean without so much effort.

Since the text-to-speech model isn’t very fast on my relatively weak hardware, I pre-generated all of the announcements, using the various voices in Qwen3-TTS. Each message is slightly different, so the announcements don’t get too monotonous and easy to ignore.

I use a script to play the announcement. The script includes a template in which I list the names of all the audio files under a variable called clips, and then use chosen: "{{ clips | random }}" to set chosen to one of the clips at random. The smart speaker then plays the audio with the chosen file name.

Testing automations with the Random integration

No need to wait for real sensors

One problem when creating automations in Home Assistant that are triggered by specific states of sensors is that they can be hard to test. If you’re creating an automation that’s triggered when the humidity levels in your bathroom rise and fall, for example, you don’t want to have to keep running the shower and then waiting for the humidity to drop to test if your automation works.

You can use a Random sensor helper that generates a random value between the maximum and minimum values you set. The value will change each time the sensor is polled, so you can set up a small automation that uses the update_entity action to update the sensor every few seconds or every minute.

You can then use this sensor in place of your humidity sensor to test what happens when the value rises above your threshold and when it drops below it. It’s a much quicker way than waiting for the humidity in your bathroom to drop.

Presence simulation

Turning lights on and off within a random window

When you’re away from home, it can be pretty obvious. Your lights never turn on during the evening or stay on the entire time that you’re away. If anyone is thinking about breaking into your home, it’s a clear signal that there’s no one currently in the house.

For a long time, I used randomization to turn my lights on and off within set hours whenever we went away for any period of time, to make it appear like people were at home. It worked reasonably well, with some lights coming on in the evening and turning off later that same evening, and others remaining off the entire time.

Eventually, I switched to using the Presence simluation integration, which mimics your behavior even more accurately by using the state history of devices such as your lights and media players. While the random method was good, this is even more convincing.

Tip solutie

Permanent

Voteaza

(3 din 6 persoane apreciaza acest articol)

Despre Autor

Leave A Comment?