In a previous post were I decribed how to control Spotify from Homeseer, I’d like to see the current playing track data from Spotify as well. The goal here is don’t want to get stuck to retrieve track info from a certain device (because that is possible via Tasker (at least for track and artist), but from a song that is currently playing on my Spotify account.

Again, the Spotify API doesn’t help me with this I would like to have the track-id from the current playing track, but how can I retrieve this? I experimented with “Last.FM”, were you can connect your Spotify account to and via the API from Last.FM you can have your artist, album, track name and cover. Because my programming skills to retrieve xml/json with vb.NET are not a the correct level, I wrote a PHP script that put the API results in a local MySQL database. Via another script I read the MySQL record into the Homeseer devices….After testing I can say that last.FM is not always able to retrieve to most recent information from Spotify…

When I almost stopped my search to a proper tool to get what I want, I found “Snip” on Github. Snip is a small tool than run in the background (from my Windows server were a Spotify client is running) and grab the track data from a client (Spotify, iTunes, Winamp, foobar2000 or VLC) that is connected to it. In my case the Spotify client on this server will not be used to control the music, it’s just running in the background and see what’s happening in Spotify.

In the settings from Snip you can define if the track info will be written to 1 txt file, or in my case, I set the track, album and artist to seperate txt files:


With a vb.NET script I grab the info from the different txt files and set them to the devicestring of the virtual devices in Homeseer. The (cover)artwork could be directly presented on a website.

Imports System.IO
Sub Main(ByVal Parms As String)
Dim Debug = 0 ‘ 0/1 
‘ dv 1324 = artist
‘ dv 1325 = track
‘ dv 1326 = album
‘ dv 1327 = cover
‘ Retrieve Artist from SNIP
Dim TextFile1 As New StreamReader(“C:\Program Files (x86)\Homeseer HS3\html\Snip\Snip_Artist.txt”)
‘Dim cover as string = “D:\Snip\Snip_Artwork.jpg”
Dim artist as String
artist = TextFile1.ReadLine()
If (artist <> Nothing) Then
If Debug > 0 Then hs.writelog(“SNIP-Artist”, “txt: ” & artist)
hs.setdevicestring(1324, artist, true) ‘ write content from txt to device. 
If Debug > 0 Then hs.writelog(“SNIP-Artist”, “txt file is empty”)
End If
‘ Retrieve Track from SNIP
Dim TextFile2 As New StreamReader(“C:\Program Files (x86)\Homeseer HS3\html\Snip\Snip_Track.txt”)
Dim track as String
track = TextFile2.ReadLine()
If (artist <> Nothing) Then
If Debug > 0 Then hs.writelog(“SNIP-track”, “txt: ” & track)
‘track = track.Remove(0, 1) ‘ Remove first character
‘track = track.Remove(track.Length – 1) ‘ Remove last character
hs.setdevicestring(1325, track, true) ‘ write content from txt to device.
If Debug > 0 Then hs.writelog(“SNIP-track”, “txt file is empty”)
End If
‘ Retrieve Album from SNIP
Dim TextFile3 As New StreamReader(“C:\Program Files (x86)\Homeseer HS3\html\Snip\Snip_Album.txt”)
Dim album as String
album = TextFile3.ReadLine()
If (album <> Nothing) Then
If Debug > 0 Then hs.writelog(“SNIP-album”, “txt: ” & album)
hs.setdevicestring(1326, album, true) ‘ write content from txt to device.
If Debug > 0 Then hs.writelog(“SNIP-album”, “txt file is empty”)
End If
Dim cover = “<img src=’http://<homeseer-ip>/Snip/Snip_Artwork.jpg” & “‘ width=’200′ height=’200’>”
hs.setdevicestring(1327, cover, True)
End Sub

Snip does the trick every time, without any delay. I run my Homeseer script every 2 seconds, but only if the Spotify device P4 is not equal to “STOP”.