Holiday Lights – Song-based Lighting

One of the features I wanted to implement in this project, was to have the Christmas tree change colors and animations based on the title of the song that is being played at that moment.

The idea is to stream from an internet radio station, parse the song title and find certain keywords. Depending on the keyword, a combination of colors and animations would be applied.


The play the music, I’m using the Raspberry Pi on which I’m running openHAB. Using MPD and MPC it is possible to play an internet radio stream and depending on the channel, obtain the title and performer.

Installing MPD (Music Player Daemon) and MPC (Music Player Controller) is easy:

Once it is installed, it is possible to add an internet radio station to the playlist.

The next thing to do, is to start playing the item in the playlist:

Once the item is playing, the status can be queried. This should provide information on the song as well. This specific command will be useful to parse the song title from.

OK, with this, the music is taken care of, and the song information is available for further processing … let’s do that now!


To process the song title, I’m using a Python script, called from openHAB using the “exec” binding.

The script takes care of parsing the song title from the “mpc status” command’s output. This is the script:

Executing the script manually returns the following:

To do the same, but from openHAB, an entry is added to the items and the sitemap to call the script and bind to its output.



The result in the openHAB GUI:
Screen Shot 2015-01-21 at 19.40.27

Checking the openHAB logs, the song titles are properly updated with every new song:


With the song title parsed, it’s time to do something with it and have some pretty colors light up

An openHAB rule is in charge of identifying keywords and changing the colors based on those keywords. The rule could look like this, but can be customised at will:

I gradually added more keywords and matching colors as songs played and I discovered more song titles.
The song titles are logged, and when there is no match, this is also reported. This allows me to check back later and add keywords for those songs as well.

In the logging above, you’ll see some titles return a matching keyword and others don’t. There is also the occasional radio channel name appearing instead of the song title. This is filtered out and skipped.

The tree happily reacts to the changes in keywords and changes colors automatically:
DSCN3180 DSCN3182
DSCN3186 DSCN3188

I’ll be covering the actual build of the tree in my next and final post! Stay tuned!

© Frederick Vandenbosch, 2014-2019. Unauthorised use and/or duplication of this material without express and written permission from this blog’s author and owner is strictly prohibited. Excerpts and links may be used, provided that full and clear credit is given to Frederick Vandenbosch with appropriate and specific direction to the original content.