Synch lights to Spotify

Hi,
I’m looking for a blueprint, or other method, to have my lights either change randomly to the music I play on Spotify, or that a scene is selected when I play a certain genre or playlist.
I noticed some conversations about it, but I didn’t find a clear solution yet.

Any advise or tips?

Thanks!

Spotify Integration creates a media_player entity. The entity’s state is important to figure out, if something is playing or not. The attributes contain futher informations, like

  • media_content_id: (spotify track id)
  • media_content_type: music
  • media_title
  • media_artist
  • media_album_name
  • media_track (not sure, if track in playlist or on album)
  • media_playlist

So, in your automation blueprint you may use the state change to: playing as trigger, or an change in attribute media_title.

I don’t see any information on the genre, though.

Yeah, I noticed these. Thanks, I’ll tinker with this.

I’m using node red, but am doing something very similar with lights.

use case for me is when i come home after work around dinner (after 6pm) and i open my front door, that open switch triggers a certiin “dinner” playlist i have set in spotify, turns on dining light and RGB lights to a certin color (cool white) it also adjusts my media players volume…in this case i’m using logitech media server, but whatever your using would be fine…picture of the flow below to give a visual

1 Like

I don’t have a blueprint but I use the color extractor integration to switch the lights based on album art:

service: color_extractor.turn_on
data:
  color_extract_url: '{{ states.media_player.home_mini.attributes.entity_picture }}'
  entity_id: light.yeelight_color_0x0000000005e768aa
  brightness_pct: 50
  transition: 3
3 Likes

Other method here that I have used for a very long time.
Purchase ilightshow app on google play I think it was less than $7
I start spotify on my phone then start I light show and go to another device and have it take over play so whats playing on spotify but on a better sound system all while my phone still passes along now playing data to I light show.
I have only tested with hue bulbs but I know support for other bulbs has been added. and with their spotify linking they sync different lights to change with the beat its like your own personal rave better than any other app I tried

I don’t know if this will help anyone but I made a working python script that links Spotify to a TP-Link Kasa SmartBulb and change color to the music data from Spotify’s API.

I just started my adventure into HA today as now I’m up more smart devices and discovered my daughters really enjoy changing the colors and talking to Alexa. I’m personally going to be working on developing a new method to use what I made to work with any brand device hence my journey in HA.

I am am an ameteur though and this was my first big project so if there’s any other dev’s here that have suggestions to improve what I have and/or have an idea that could help integrate these other brands please shoot me a message. (I bought some cheap Tuya bulbs without knowing about their cloud service lock thinking I’d save some money for light entertainment for the kids)

Link for Python Script

check this appdaemon available on HACS

Hi @turnupthebassto11,

Does your script sync/change the light colours according to the tune of the song or it just changes once per song ?

Ok so I got this to work by:

  • Buying the app iLightShow for my phone (10$, one time)
  • Setting up an emulated hue bridge on HA
  • BOOM

I did this recently too. iLightShow is what I missed most from when I had all my bulbs on the Hue hub (now z2m). I need to run in Legacy mode for any decent performance, but that’s OK. The effects don’t need to be perfect, really just looking for dynamic ambient lighting.

I would still like an option that’s native to Home Assistant to automate activation…or at least not need to use my phone. Excited to check out the AppDaemon option posted earlier.

It downloads the songs meta-data and changes colors to the beat as defined by the JSON fille’s timestamps of the beat. It actually dances to the beat of the song. It mih need a re-design tthouh because it sends a of requests to check current timesamp position… but it does work.

I have a program called “Lyric Fever” for macOS that shows lyrics for the current playing spotify song. Now, with the private API I call, I also get spotify’s lyric color background. I use this color for my app’s karaoke window mode.

Now, an app called HomeBot exists on macOS on the App Store that lets you modify lights on Apple Home (Homekit devices) and their properties.

So, I experimented today to call the HomeBot shortcut whenever my app Lyric Fever loads the color+lyrics for a new song, and update my light’s hues to the current song. And it works pretty well! I can probably package this into a separate mac app, but if only spotify has an api call to get the color for the song… it seems quite wasteful to call their lyric api just for the color data… and it doesn’t exist for songs without lyrics (currently I generate a color by averaging the album art as a backup)

@aviwad
The SpotifyPlus Integration might be able to help with this. It has the Get Track Audio Features service that returns information about a tracks’ audio features from the Spotify Web API.

I don’t know if it would help you for colors or not, but it could provide you with other details that might affect lighting control: tempo, danceability, liveness, loudness, time_signature, etc.

Example:

service: spotifyplus.get_track_audio_features
data:
  entity_id: media_player.spotifyplus_john_s
  track_id: 7ouMYWpwJ422jRcDASZB7P

and generates the following output, which can be consumed by a script / automation:

user_profile:
  country: US
  display_name: John Smith
  email: [email protected]
  id: 3758dfdsfjk435hjk6k79lm0n3c4
  product: premium
  type: user
  uri: spotify:user:3758dfdsfjk435hjk6k79lm0n3c4
result:
  acousticness: 0.000273
  analysis_url: https://api.spotify.com/v1/audio-analysis/7ouMYWpwJ422jRcDASZB7P
  danceability: 0.366
  duration_ms: 366213
  energy: 0.963
  id: 7ouMYWpwJ422jRcDASZB7P
  instrumentalness: 0.0122
  key: 11
  liveness: 0.115
  loudness: -5.301
  mode: 0
  speechiness: 0.142
  tempo: 137.114
  time_signature: 4
  track_href: https://api.spotify.com/v1/tracks/7ouMYWpwJ422jRcDASZB7P
  type: audio_features
  uri: spotify:track:7ouMYWpwJ422jRcDASZB7P
  valence: 0.211

Hope it helps!

@aviwad
I added a new Get Image Vibrant Colors service to the SpotifyPlus Integration that extract vibrant color information from an image url, or the currently playing image of a Spotify track.

It may help you to determine the RGB color codes that drive your Hue lights based on what is currently playing.

Example - omit the image_source argument to retrieve color info for the currently playing Spotify track:

action: spotifyplus.get_image_vibrant_colors
data:
  entity_id: media_player.spotifyplus_john_s
  image_source: https://i.scdn.co/image/ab67616d0000b2733deaee5f76ab2da15dd8db86

and generates the following output, which can be consumed by a script / automation:

user_profile:
  country: US
  display_name: John Smith
  email: [email protected]
  id: 3758dfdsfjk435hjk6k79lm0n3c4
  product: premium
  type: user
  uri: spotify:user:3758dfdsfjk435hjk6k79lm0n3c4
result:
  dark_muted: "#762524"
  dark_vibrant: "#7d2726"
  light_muted: "#937b07"
  light_vibrant: "#f8de5e"
  muted: "#937a07"
  vibrant: "#f6d12a"

Hope it helps!