Youtube songs play with kodi

I have input_boolean in Home Assistant to play Youtube songs with Kodi. Take this steps:

  1. Open Kodi
    Settings
    Add-ons
    Kodi add-on repository
    Video Add-ons
    YouTube
    Install

  2. Open Youtube add-on and choose sign in.

  3. Go to www.youtube.com/activeate to active your youtube plugin by typing the code.

  4. Search a youtube movie you like and copy the video id:

  5. This is a example from my code:

Mediaplayer.yaml:
platform: kodi
host: http://192.168.2.12
port: 8080
name: kodi
user: kodi
password: ******
turn_off_action: hibernate

input_boolean.yaml:
enable_playlisthillsong:
name: Playlist Hillsong
initial: off

automation hillsong start.yaml
alias: Playlist Hillsong
trigger:
platform: state
entity_id: input_boolean.enable_playlisthillsong
to: ‘on’
action:
service: media_player.play_media
data:
entity_id: media_player.kodi
media_content_id: “plugin://plugin.video.youtube/?path=/root/video&action=play_video&videoid=Xud-J6IQmLI”
media_content_type: “video”

There are two rules for play video’s and playlist:
Video:
plugin://plugin.video.youtube/?path=/root/video&action=play_video&videoid=$VIDEOID
Playlist
plugin://plugin.video.youtube/?path=/root/video&action=play_all&playlist=$PLAYLISTID

For playlist i have it not working yet, but maybe you have a sollution for this?
Playlist are loading say kodi, finish, but kodi don’t start playing.

6 Likes

Hi @rmdejonge,
no promise but you could try to create a .strm file, throw in the yt playlist url then call play on that file?
See http://kodi.wiki/view/Add-on:YouTube section 2.1
I can’t really test this as I have random connectivity at the moment in the outback.

Thanks for the tip about .strm files, i will try it and let you know

Did you get it working?

BTW nice to see you’re from Holland and like GNR and Hillsong :).

Also have a look and maybe participate in our Tweakers topic: https://gathering.tweakers.net/forum/list_messages/1652294/last

Heeey Puckstar,

no, it it not working yet…
A singel song, no problem. .PLS or .M3U no problem.
But, youtube playlist is the problem, it can get it working.

p.s. Nice music he :wink:

Hey @rmdejonge,

I sent a playlist url like so :

curl -X POST -H "Content-Type: application/json" -d '{"entity_id":"media_player.salon", "media_content_id":"plugin://plugin.video.youtube/play/?playlist_id=PLBGl1tVyiWQSVwxne3yOH79uaSqgbnCqL", "media_content_type":"video"}' 'http://192.168.1.3:8123/api/services/media_player/play_media'

and realized that the problem lays on the youtube addon end.

Seems like a relatively long standing one as stated in this fairly recent post

I’m guessing that the media_content_id: “plugin://plugin.video.youtube/?path=/root/video&action=play_video&videoid=$VIDEOID” is just for kodi, and not Chromecast, right? Or is that a plugin for HASS?
I’ve been trying to figure out how to pass YouTube URLs to a Chromecast for a while now!

@rmdejonge:
Daily quotas exceeded and Invalid credentials errors apart, I successfully played yt playlists using jsonrpc directly on the kodi/jarvis/osmc host with the following data param [{"jsonrpc": "2.0", "method": "Playlist.Clear", "params": {"playlistid": 1}, "id": 1}, {"jsonrpc": "2.0", "method": "Player.Open", "params": {"item": {"file": "plugin://plugin.video.youtube/play/?playlist_id=SOME_YT_PLAYLIST_ID"}}, "id": 2}, {"jsonrpc": "2.0", "method": "Player.Open", "params": {"item": {"playlistid": 1, "position": 0}}, "id": 3}]

Yes, it is a youtube plugin for kodi. I am trying to make it working to play a youtube playlist in kodi. thanks for feedback and tips.

This is a very very helpful post. I was looking for a way to run a media stored in my synology/or yourube stream via Chromecast from hass. But unless, I run something like a python SimpleHTTPServer in either Synology or my RPi (running hass) it was not possible… I then tried to run Plex in my synology but still couldn’t get a media_content_id which could play the media from Plex source via chromecast…

Then I came to this post and finally decided to run kodi to test. Well, this worked so nicely that I bought another Pi dedicated for kodi :slight_smile:

Few months back when I started my research about smart home products, hubs, I came across hass web site but couldn’t get to a point for buying/investing for any smart home products. But for some unknown reason, I installed hass in my computer just for testing/fun and then I didn’t have a going back.

After that, now I have two pi running kodi/hass , full of smart lights occupying the house , few smart switches , motion sensors , cameras ,etc. Now the research is pretty easy, I don’t search for a product anymore, rather whatever hass supports, that should be my first preference :smile: anyway. If its not supported, its not in my list…

I am learning everyday from home assistant community some new and cool stuffs. Thank you guys… You people are awesome.

Nice to hear Tarikul that this topic helpt you.

After a lot of trying, I found a working solution for sending a complete Youtube playlist to Kodi and let it auto play all the items in the list. See the code below. You’ll need to have the Youtube addon installed in Kodi and need to activate it with your Youtube account. In case you’ll prefer a random playlist order, you can change order=default to order=shuffle in the code below.

- service: media_player.play_media
  entity_id: media_player.stereo_living_room
  data_template:
    media_content_id: >
      {% if is_state('input_select.radio', 'youtube [living room]') %}
        plugin://plugin.video.youtube/play/?playlist_id=ENTERYOURPLAYLISTIDHERE&order=default&play=1&repeat=all
      {% else %}
      {% endif %}
  media_content_type: 'video'
5 Likes

Wauw! This sounds good @HAppy! Thanks for sharing, i will try it.

You’re welcome @rmdejonge! Good luck with the implementation in your code :slight_smile:

I have used your code and it works for me with no problems. Thank you for that!
However, I am trying to make it simpler for my wife to use it. Instead of having preloaded scripts for every playlist or song, I am trying to use input.text for that purpose. So the only thing I have to do is to copy the last part of the link e.g. Xud-J6IQmLI and send it to Kodi.

Here is what I have so far:

  - data:
      entity_id: media_player.tv
      media_content_id: plugin://plugin.video.youtube/play/?video_id={{states.input_text.youtubelink.state}}
      media_content_type: video
    service: media_player.play_media

So far I cant make the formatting work. I am absolutely sure it is about formatting. Something to do with the quotes maybe? Anyone wants to help a fellow husband?

Here is how it looks like on the front end
3

Use data_template instead of data. I think you may have to use quotes around the whole template. Let us know if it works.

1 Like

We have a hit!
Thank you very much!
Now I can just strip ANY url I want and keep the last part and just paste it on the frontend. I just hit execute and the video plays!
Thank you very much again.

ytplayontv:
  alias: Play Youtube Link on TV
  sequence:
  - data_template:
      entity_id: media_player.tv
      media_content_id: plugin://plugin.video.youtube/play/?video_id={{states.input_text.youtubelink.state}}
      media_content_type: video
    service: media_player.play_media
1 Like

You might want to try this to add youtube search. I say this to Alexa (or put in an input text) to search youtube and play the top search list.

Alexa, tell Sam to play rolling stones, paint it black

can some one putt the full working config ?

Hi there. Sorry to bump an old topic. Was just wondering what kind of card you were using to get this on the frontend. Thanks!

Also, when playing playlists, it loads the full playlist within Kodi, but only plays the first video weirdly