I have a Home Assistant instance running in a Docker container on the Raspberry PI. The configuration is exposed on the Docker volume so I can access the file and change it. I followed the instructions to get the Spotify integration running in the Assistant and quickly turn this into an alarm radio.
Since I already own a Spotify account, it was not difficult to set this up:
- follow the links in the instructions and create an app on the developer side of Spotify
- edit the settings for the application and add a redirect URI and save
- copy the credentials for the configuration.yml of the Home Assistant
- edit the configuration.yml per the instructions and restart the Home Assistant server
- go to Home Assistant integrations section and add Spotify integration
Make a note of the integration name. You'll need it later. It's "Spotify MyUsername" on my end.
It pretty much gets added to the Home Assistant dashboard automatically. I went a step further and added an automation for this. My speaker system is connected to the Home Assistant from before so this turned out to be a perfect opportunity to go down this route. I wanted to have the "Liked Songs" as a playlist to run, but Spotify is not making it a playlist. Here's the entrance to the rabbit hole if you want to see how the "Liked Songs" was requested to be a playlist. For now, I opened it in a dedicated application on the computer, selected all songs with Ctrl+A and added them to a new custom playlist that I can work with.
In the automations section of the Home Assistant I did the following:
- added an automation and started with an empty automation
- added the name for the automation (I used "Spotify Alarm") and left the other options as they were
- for the trigger I used "Time" type and a fixed time, which can be whenever you want the automation to run (08:00 for example)
- conditions I didn't touch
- the next was the action subsection where I added several, starting with turning on the speakers, which means I set this action's type to "Call service", the service to "media_player.turn_on" and my speaker-set and the Spotify player as the targets
- there's an "add action" button bellow that lets you add more actions and my next one was "Delay" of 10 seconds as a quick and dirty way to give the speakers some time to turn on
- added new action: "Call service", "media_player.volume_set" as the service, with my speakers as the target and the volume percentage at 0.2 (this is 20% of the maximum volume of the speaker set)
- added new action: "Call service", "media_player.play_media" under service, but this time the target is the Spotify player, "Content type" is set to "playlist" and "Content ID" is the URL to the custom playlist
- added new action: "Call service", "media_player.shuffle_set" under service, the Spotify player as the target, and shuffling toggled
- added new action: "Call service", "media_player.media_next_track" under service, the Spotify player as the target
- added new action: "Call service", "media_player.select_source" under service, the speakers as the target and as the source I put the name of the device ("Spotify MyUsername")
Save and exit the automation. Run it to try if it works. There might be some tweaking involved from your end for the action "Delay" if it takes a long time to power on the system. I'm wondering if "Wait" would be appropriate. There's also a question of the Spotify integration with the speaker system. I didn't figure out where the source will end up, but I'm not complaining. It works.
I perceive home automation as a hobby at best. I'm still poking around that. The results of tinkering can be seen here. I'll probably need to publish the automation scripts in some public repo eventually.