Smart Playlists in xbmc/kodi

Hi All. I have a very extensive media collection on my network and I use kodi as my media player of choice. I have some smart playlists setup, one in particular for my version of TV. It picks random episodes from random shows that haven’t been watched in atleast X amount of time. This is my go to for my media viewing experience.

However, I am looking to automate this a little more. I get up early in the morning before everyone else does. I would like when I get up that my playlist just starts. Or when i am in my office it auto starts.

The problem is I do not know how to either play a smart playlist using the xbmc binding, or how to add the smart playlist to the current playlist, then send a play command.

Anyone else done this?

Hi Jason,

I’m not sure whether you can do it with the xbmc binding, but you can use the http binding to send json commands to kodi.

I use the following json commands to first delete the current playlist, then load a smart playlist and finaly start playing it:

{"jsonrpc":"2.0","id":1,"method":"Playlist.Clear","params":{"playlistid":0}}
{"jsonrpc": "2.0",  "method": "Playlist.Add","params":{"playlistid":0,"item":{"directory": "special://profile/playlists/music/NameOfSmartPlaylist.xsp", "media": "music"}},"id":1}
{"jsonrpc": "2.0", "method": "Player.Open", "params": { "item": { "playlistid": 0, "position": 0 } }, "id": 1}

However, I could not use those commands directly in openhab, I had to encode them before (for this I used http://www.freeformatter.com/url-encoder.html)

In Openhab, I then added the following lines in a rule:

// Delete old playlist   
var String json = "%7B%22jsonrpc%22%3A%222.0%22%2C%22id%22%3A1%2C%22method%22%3A%22Playlist.Clear%22%2C%22params%22%3A%7B%22playlistid%22%3A0%7D%7D"
sendHttpGetRequest("http://192.168.178.26/jsonrpc?request=" + json)        

// Load Playlist
var String s_KodiPlaylist = new String("NameOfSmartPlaylist")
json = "%7B%22jsonrpc%22%3A+%222.0%22%2C++%22method%22%3A+%22Playlist.Add%22%2C%22params%22%3A%7B%22playlistid%22%3A0%2C%22item%22%3A%7B%22directory%22%3A+%22special%3A%2F%2Fprofile%2Fplaylists%2Fmusic%2F" + s_KodiPlaylist + ".xsp%22%2C+%22media%22%3A+%22music%22%7D%7D%2C%22id%22%3A1%7D"
sendHttpGetRequest("http://192.168.178.26/jsonrpc?request=" + json) 


// Start Playlist
json = "%7B%22jsonrpc%22%3A+%222.0%22%2C+%22method%22%3A+%22Player.Open%22%2C+%22params%22%3A+%7B+%22item%22%3A+%7B+%22playlistid%22%3A+0%2C+%22position%22%3A+0+%7D+%7D%2C+%22id%22%3A+1%7D"
sendHttpGetRequest("http://192.168.178.26/jsonrpc?request=" + json)

For me, it works fine.

3 Likes