Music automation in a smart home or media streams in home assistant

Igor Mullin
2 min readAug 28, 2021

You’ve probably seen scenes in movies where people enter an apartment or a room and the light automatically turn on and pleasant music starts playing. Today we will repeat this automation.

This is a translation of my article in Zen. Also, do not forget to read us in other services: Instagram, telegram (RU, EN, DE). Medium, LiveJournal, YouTube.

Today we will create a simple automation in home assistant. When you enter the room, the music automatically turns on, as well as the background lighting. To implement the scene, such a backlight + a media device must be installed in the room. In my case, the backlight is implemented by Xiaomi mi light strip (Yeelight) and a “stereo pair” on Google nest mini speakers.

1. So, the first action is very simple. We create automation and get a name for it

2. Let’s select a trigger. This can be a sensor on the door or a motion sensor in the room

3. As an action: turn on the lamp and call the media_player.play_media service. In the parameters of this service, you need to set the address to the playlist and the media type. The last action is to select the targets. This can be a room or a specific device. I chose a stereo pair (which is one virtual device, but two physical devices…). Content ID is the address to the media stream or file. Content type set up as music.

We save the result. The main thing is to set the volume to the needed one in advance.

[upd.1] To guarantee the volume, I added the command “set the volume to 0.1” (10%) to the automation

[upd.2] Later, at the request of the family, I changed the activation trigger from the motion sensor to the door closing sensor.

And that’s all, subscribe, likes, repost… And we will soon be a small lottery ☺.

--

--

Igor Mullin

I´m a Hardware and Software Engineer and a PhD. In my professional activity I focus on such things like smart home systems and electric development.