Controlling music play on Kodi media player

I’ve always appreciated how friends can tell their big tech smart speakers to play some artist-or-song and the speaker would play the requested material, sourced from their music streaming service. But my goal has always been to integrate voice with our media player to play from our in-house digital music collection over our home A/V system.

I had long pinned my hopes on MyCroft, which went unrealized when MyCroft imploded early in 2023. But then became so excited as Year of the Voice progressed!

And it actually works pretty marvelously on our Wyoming satellite speaker. I can now request Nabu to “play some Rolling Stones” or “play upbeat tunes” or “play Everybody Wants to Rule the World”, and our home A/V system+Kodi will do it!

Here’s what I did to make it work:

  1. wrote an on-demand process to extract the metadata from our digital music files, to produce a flat file
  2. wrote a second on-demand process that consumes the flat file to populate a custom search index
  3. created a web service on our webserver that accepts keywords, then searches the index to find the best matching playlist or song file, and instructs the media player to play it, via the Kodi API
  4. wrote a short shell script in Home Assistant that forwards keyword requests to the webservice
  5. established a Home Assistant conversation automation triggered from the word “play” that passes the spoken text to the shell script service - which I feared might be the difficult part, but was wonderfully easy

I’ve also conversation automation(s) to do play/pause/next/previous/stop/shuffle/repeat. I have it work through the Logitech Harmony integration, but it would be pretty easy to direct these at the Kodi through the API.

I must admit I’ve never looked into Home Assistant’s built-in media player, mostly as I’ve assumed it wouldn’t work with the Kodi system. And so I can’t currently request “play the album with the rainbow cover”, though that is really cool.

Are you able to share what you did from a coding standpoint? I actually created this exact thing for kodi and mycroft. I am comfortable with python so the mycroft skill was a good challenge for me. I am definitely interested in migrating this work to HA year of the voice.

Yes, I could share it. However, I suspect there’s a number of issues that might be real barriers to it being of use to others. While the Home Assistant components are straightforward, the extraction, indexing and search webservice might need to be fairly custom to each user’s music library, as well as the diversity of their HA, music library & media player deployments…though I’ve been pondering ways it might be genericized.

Unfortunately, I’ve not made the opportunity to sufficiently learn Python, so currently the extraction, indexing and search webservice are all coded in Perl.

I’m happy to discuss it in more detail with anyone interested.

Currently, there seems to be no feedback mechanism that enables Assist to report issues – “song not found”, “media player not on”, or even “now playing such and such” – I look forward to that ability coming to Assist in the future. Custom Assist responses for automations have been added in Home Assistant 2024.2!!!

Have you looked at Music Assistant and using that? I think that would make it easier.

I don’t think Music Assistant supports Kodi yet. It does support Jellyfin and Plex, though.

I would vote for play music (artist/album/track) at music assistant feature handsdown.