I couple of years ago I was really excited when node-red came out. Having just returned from a year working at National Instruments mastering LabVIEW, a graphical data-flow based language seemed like a great fit for Internet of Things (IoT) programming!

Some time later, I was playing with LED strip in the living room of my house. The strip was connected to an arduino built into the top of a HP Microserver that I bought previously. The server itself was modified to include a 128x32 monochrome OLED display and an RGB led driving the HP logo (an Adafruit Flora Neopixel). The image below shows the server with the case opened in my new house (no external strip yet - soon to be added).


The next image shows the Arduino close up - the model itself is a Seeduino Stalker v3 which I got in a sale for under ten pounds a few years ago. The grove connector works really well for the front panel LED. The multicore cable is the umbilical to the OLED screen. Top left a molex connector can just be seen, which connects the blue led strip behind the grille of the server front door. Please excuse the dust!


The media server itself runs MPD and mopidy, with spotify and soundcloud plugins. This allows anyone with a browser (or app) in the house to add music from those sources to the playlist. In the near future I intend to extend playback into the kitchen and conservatory with an Icecast stream to a Raspberry Pi or two.

In my last two houses, we had WS2811 LED strip mounted inside some bookcases either side of the television, and some more strip running behind that. We intended to mount strip around the room to downlight the walls, but never got around to it! The Arduino was running a small bit of code which pushed a green/blue chase around the strip, but it would have been nicer if it responded to music playing. Cue the node-red mopidy node!

Node-red nodes are easy to write yourself as you just need a html file declaring the menu structure for the configuration settings and a javascript file containing the actual logic. Having already written node-red-contrib-epics, a node for connecting to a popular distributed control system used in particle accelerators, I decided to write a mopidy node. This was only a basic node, however, and allowed the user to see the high level messages running over websockets between mopidy and MPD. This allowed node-red to be notified of the playback state changing and any track info related to the currently playing song. There was also an output node, which allowed the user to issue various commands to mopidy. The node worked (albeit with little error handling) and was pushed to NPM as v0.9. Woop!

Cut to last week, and Emil Oberg got in touch to ask if he could take the package name I used for his much more developed version of a mopidy node. I was very happy to oblige after testing his node both worked and was easy to use for current users of my simple node, and now he is in charge of the node-red-contrib-mopidy repository.

I was really happy that the node I had started inspired Emil to rewrite it and do a much better job than I had. I guess that’s one of the warm fuzzy feelings that you can get from free open source software!

As for the my media server, I am now running with Emil’s node and it’s going very smoothly. When idle, the server displays this on the screen and the LED is red. When a track plays, the text scrolls ‘Playing’ and the LED fades to green then back and forth from green to blue. If playback pauses or stops, the screen changes back to ‘Idle’ and the LED fades to red via green or blue, whichever is faster. Below are some photos to illustrate.

IMG_20151123_010217.jpg IMG_20151123_010346.jpg

The node-red flow is very simple:

  1. Listen for mopidy events.
  2. On an event, trigger switch output 1 if msg.payload.new_state contains ‘playing’. If it contains ‘puased’ or ‘stopped’ then trigger outputs 2 or 3, respectively.
  3. If the track is now playing, then request for the track info and strip just the track name and set that as msg.payload. Else, set msg.paylod to ‘n’.
  4. Write msg.payload to the Arduino over USB serial.


In the Arduino code, apart from some animation code for the OLED, there is little more than waiting for serial bytes and chasing an LED colour. The screen was going to display the current track name but I am having issues with the graphics library and as the size is so small, I will probably leave it as just saying ‘playing’.

When I get the external strip installed I shall try and add a music API request to find out the genre and speed of the track so as to tailor the chase for the right mood.

Thanks for reading!

Gravatar Profile Picture

Laurence Stant

PhD Student, Maker, Coder.