Tying to play a smart Playlist on Kodi

I created a smart playlist in Kodi, that I want to start playing with Home Assistant, this is the script:

kodi_play_test:
    alias: Kodi Play Playlist
    sequence:
      - service: media_player.kodi_call_method
        data:
          entity_id: media_player.kodi
          method: Player.Open
          item:
            file: "special://profile/playlists/video/test.xs"

But its somehow not working, I get this error here:

TransportError trying to run API method media_player.kodi.Player.Open({'item': OrderedDict([('file', 'special://profile/playlists/video/test.xs')])})

Does anybody know why?

FWIW, I get the same error when trying to start a party mode playlist.

kodi_party_mode:
  alias: Kodi Play Something
  sequence:
    - service: media_player.kodi_living_room
      data:
        method: Player.Open
        item:
          partymode: music

I know this is almost a year on, but did you find a solution to this?

Man VoxCommando used to do this like a boss. I need to get that set back up. Nice to still see Kodi loyalists around.

Came across this. Not tried it but seems to address the requirements

I can’t explain why the above-listed code isn’t working. But I can give you an example of code that works and which will play any Kodi playlist that you have (including smart playlists). I’m using HA 2021.3.2 and the following works for me. It uses the kodi.call_method service. You just need the specify three service calls:

  - service: kodi.call_method
    data:
      entity_id: media_player.kodi
      method: Playlist.Clear
      playlistid: 0
  - service: kodi.call_method
    data:
      entity_id: media_player.kodi
      method: Playlist.Add
      playlistid: 0
      item:
        recursive: true
        directory: "special://profile/playlists/music/01_breakfast_music.xsp"
  - service: kodi.call_method
    data:
      entity_id: media_player.kodi
      method: Player.Open
      item:
        playlistid: 0
        position: 0

Hi, how you’re getting the playlistid? What does it represent? I can play with this but I’d love to be able to play it in random order:

sequence:
  - service: media_player.play_media
    target:
      entity_id: media_player.libreelec
    data:
      media_content_type: DIRECTORY
      media_content_id: special://profile/playlists/video/krtek.m3u
mode: single

For playlist_id, 0 = audio and 1 = video.

The example above is a playlist that plays in random order. You can play in random order by using party mode, but I use smart playlists instead. To do it with a smart playlist, you just create the smart playlist, using whatever rules you want (e.g., Artist, Genre, Rating, etc) and then you just set “Order By” to “Random.” Now, every time Kodi opens that playlist the songs will be in random order.

If you want to do smart playlist where you pick each song individually, then you need to use a file tagger like Picard. Basically, you just pick a tag that isn’t typically used for music (I use “Comment”) and then pick any word you want to signify a particular playlist. The example above is a breakfast music playlist, so let’s just say I use the word “Breakfast” to identify this playlist. In Kodi, create a smart playlist with the rule “Comment equal Breakfast,” and set Order by to Random. Then, for every song you want to add to this playlist, load it in Picard and you will see the existing tags at the bottom of the screen. Right click any existing tag name, and then select “Add New Tag.” Then, in the pop-up that appears, start to type “comment” and you will see a dropdown list. Select “comment” from that list. Then click on Edit Value and type in “Breakfast.” Then you click Save in the pop-up, and Save again in Picard to write the new tag to the file. After you are done adding the tags to the songs that you want in your playlist, update your music library. And you now have a new playlist that will play the selected songs in random order.

1 Like

That’s kinda crazy invovled process :pleading_face: Thanks!

There is a simpler method if you are not using the song ratings feature. All songs added have a default rating of zero stars, unless you assign a rating. If you don’t use this, you could create a smart playlist with the rule “Rating equals 1”, set Order by to Random, and then using the Kodi interface just select the songs you want and give then a rating of 1 start. You could create 10 smart playlists this way.

The issue here is that Smart playlists in Kodi are dependent on metadata. I’m not trying to play music but video that doesn’t have any real metadata, so I just can’t add it to a Smart playlist. My media live outside the Kodi library for specific reason, I only access it via the Kodi File browser. I cannot make Smart playlist with these files.