Current NodeRED Project: Playing a Random Song from a Spotify Playlist When Turning on the Shower
It all boils down to an automation that plays media using Spotify as the source when triggered. In this case, the trigger will be the state of our digital shower valve which is a simple on/off switch. The media player will be a PiCore Player (squeezebox) running on a Raspberry Pi3b, and the media source (i.e. the song played) will be a link to a Spotify track (URI).
As described, this is a very basic automation. But, we're going to complicate it.
We want to play a song from a specific Spotify playlist, randomly, and we don't want that song to repeat until all of the songs in the playlist have been played. Most of this will be accomplished inside of NodeRED with a bulk of the heavy lifting being done by a function node, and by an HTTP request node which will grab the information we want from Spotify.
Fortunately, I've figured out how to GET the playlist data from Spotify and store it in a Global Variable. Some of the challenges include figuring out how to overcome the 100 item limit that Spotify imposes on the API call results. If a playlist contains more than 100 items, the GET command can report the total number of available items, but it will only retrieve 100. There's an offset option for the call, but I need to figure out how to combine two calls into one large object to store in the global variables.