Hass.io play media on Kodi

Hm, I thought it sounded a bit odd that I would ned a CEC addon to control Kodi from hass.io. My kitchen Kodi is not connected to a TV, but an official 7" Raspberry Pi screen.

I tried the play_media service with the JSON arguments above, and I get the same spinning wheel as with my script.

Now, this is really weird. I found out that the channel I am calling does not correspond with the channel shown in media_player.kodi_kok. By trial and error I have now found the channels I am subsribing to.

Confusing to say the least!

Sorry for the misunderstanding. The CEC protocol is to control TVs. I thought you had 2 problems: to turn on the TV, and to play some media. Now I see your problem is only with the OpenElec PVR channels…

Well, the JSON RPC API for Kodi could be a little complex… but it has good docs. It’s not really a problem of HA or hassio. You could play with the Kodi API from within a Jupyter notebook, or an ipython console, or with some CURL commands in the CLI, before using it from Home Assistant, your life would be easier

Thanks for helping out!

I actually managed to play PVR when I finally called the right channels. I am using two Kodi machines as stated above and the channels are unfortunately not the same for both of them. Also, I have not been able to play a specific album or artist from my mp3 music collection on my Linux server (with Samba share).

If you have any tips or examples on how to get HA to play these in Kodi, it would be very helpful. Also, is there a way to extract which channels correspond to which media_content_id? I also have Radio enabled in Kodi.

Thanks,
Tomas

You’re welcome.
If you have these mp3 albums added to your Kodi media library, you only need to know their identifiers to play them. As I said, The Kodi API is a complex, but most complete one. It requires to play a lot with it to get things done.

Like with the PVR channel ids, there are API commands to query the Kodi DB in order to obtain the necessary info to do what you want.
Also, to play internet video or audio streams, take a look to the media_extractor component in Home Assistant.

Well, in the link to my TV control yaml config you can see some. But if you’re doing complex orders, you’ll need a powerful tool to make the automations. I use the awesome appdaemon to do that.

As an example, I have an input_select and some scripts to dynamically populate it: for loading and then selecting items from the ‘recent TV shows’ and ‘recent movies’ playlists (and for the PVR channels). To receive the API call results and populate the input_select, I have this appdaemon app.

Another complex example is in my telegram_bot handler, which does a lot of things. One of these things is pasting a video link in my Telegram bot chat, to order HA to play it in Kodi → hass_appdaemon_apps/conf/apps/bot_event_listener.py at master · azogue/hass_appdaemon_apps · GitHub

If you need help with the Kodi API, there are very good forums where to ask, and as I said, the docs are good.
Good luck!

1 Like

Thanks @azogue, quite advanced stuff and so far a little bit over my head, although I am trying to learn :slight_smile:

What I am after to begin with is this:

  1. Let HA tell Kodi to play TV or radio at the press of a button or switch or e.g. a certain channel on the kitchen tv every workday morning
  2. Let HA tell Kodi to play a predefined playlist of mp3’s, such as e.g. “Dinner music” or random songs from a music genre with a button press or switch
  3. Same as 2), but get music from Spotify or Tidal through Kodi addons
    However, I guess I still need to learn how to extract the content_id from Kodi. I tried to call Kodi with the parameters album_id and artist_id, but couldn’t get it to find anything in my Kodi music db.

Later on I will probably like to do some of the advanced stuff with input_select etc., but to begin with pretty basic stuff.

Also, I am running a Logitech Media Server on my Ubuntu Server in order to try and accomplish multi-room functionality with Squeezelite or Squeezebox and Kodi. I have also seen examples using HA to play a random playlist from LMS.

I will look at the documentation you suggest, but as many of us unwilling to “reinvent the wheel” I was also looking for some basic examples that I could apply to my setup.

Thanks for the help!

@tomoqv do you still working on this? Any progress?
I’m doing a Kodi remote and this is what I got so far:

  • Remote control functions: Up, Down, Left, Right Select, Back, Home, Play/Pause, Slider volume
  • Party Mode (play all songs in random order)
  • Play RainyMood (music addon for white noise)

Wishlist/WIP:

  • Play a specified genre/artirst
  • Play the last unseed episode of a specified tv show

Looks very interesting. Your screenshot doesn’t look like the usual HA interface, how did you set it up?

I haven’t come very far at my end yet. Will definitely try some of your stuff!

I have my config in https://github.com/maattdiy/home-assistant-config#home-assistant-configuration
For the buttons I use the Custom UI Tiles
Do you have a repo?

I want to fire a JSON RPC API command thrue a script with HA to a kodi box, but I can’t find a proper example of a code. With an example from mviezzer I have a party mode working, now I like to stream a radio station with the Kodi Addon “Radio.de”.

Is there anyone who can post a few script examples for Kodi (addons)?

There is a nice Kodi add-on for MQTT … this provides the Kodi status (on, off ,pause, screensaver, movie title, progress, etc) … it works much more easy!

That’s sounds great. I found the addon. Do you an example how it works, I want to automate a radio stream addon.

I have migrated all my automation to node-red … but it is all MQTT message management.

I have 5 Kodi running and configured the Kodi-MQTT-Addon with /Kodi/1 to /Kodi/5 … than you will have all the JSON parameters available.

I used a MQTT monitor to analyse all the messages coming out of Kodi (its a lot) … and choose the one i needed.

Good luck

I’m very curious how you setup the .yaml
I have 3 Kodi/SPMC devices. So far I have following script working:

# Play Partymode
kodi_play_something:
  alias: Kodi Play Something
  sequence:
    - service: media_player.kodi_call_method
      data:
        entity_id: media_player.kodi_w
        method: Player.Open
        item:
          partymode: music

Do you want to share you’re script code? I’m a bit of a rookie regarding the JSON parameters… Thanks anyway!

1 Like

Sorry , I have moved my automation to Node-red and have no YAML available

Hi. Did you figure out how the config looks like?
I have installed kodi2mqtt addon and connected it to my hassio broker, but I’m strugling with adding it to my config.

No I’m sorry, can’t help you. I can’t find enough informatie of the format of the commands.

FYI everyone - we’ve updated the code to support latest appdaemon and kodi.

1 Like

Can anybody tell how I can play specific spotify playlist on kodi?
I found that probably i can call to the plugin, but can’t figure out how to do it from call method.
here’s what i got from kodi debug and i want to invoke:
plugin://plugin.audio.spotify/?action=play_playlist&ownerid=spotify&playlistid=37i9TECEVXcSwR3jlLXHm8

In case, some month later. :wink:

script:
  kodi_play_radio_abricot:
    sequence:
      - service: media_player.play_media
        target:
          entity_id: media_player.abricot_kodi
        data:
          media_content_type: music
          media_content_id: >
            plugin://plugin.audio.radio_de/station/example.com