offset \ˈȯf-ˌset\ noun

a force or influence that makes an opposing force ineffective or less effective

Home Assistant Spotify Radio Alarm

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:

  1. follow the links in the instructions and create an app on the developer side of Spotify
  2. edit the settings for the application and add a redirect URI and save
  3. copy the credentials for the configuration.yml of the Home Assistant
  4. edit the configuration.yml per the instructions and restart the Home Assistant server
  5. 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:

  1. added an automation and started with an empty automation
  2. added the name for the automation (I used "Spotify Alarm") and left the other options as they were
  3. 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)
  4. conditions I didn't touch
  5. 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
  6. 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
  7. 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)
  8. 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
  9. added new action: "Call service", "media_player.shuffle_set" under service, the Spotify player as the target, and shuffling toggled
  10. added new action: "Call service", "media_player.media_next_track" under service, the Spotify player as the target
  11. 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")

/media/images/spotify_alarm_actions.png

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.