Youtube Music - Media Browser

Why the extra sensor is always ‘off’ after turning on the media player? How to have it automatically ‘on’ when playing some music?

hey man, sorry have not been online for a while. This was actually just a coincidence as my media background has a red gradient, and theme color at that time was the orange.

You did make me think though, you could potentially grab the media artwork and use it as a background or as a picture element that sits behind the cards and then do some heavy CSS gradient and blur manipulation to try and simulate the efect.

Im not a dev by anymeans, but i think you would need some form of JavaScript to get the primary color of the image to use with the control colors.

Am I supposed to see playlists in home assistant media browser after installing and configuring this? If I cant see that, what could be wrong?

yes, you should see your playlists / library etc in the media section.

I have no idea whats wrong with your setup. did you select the correct mediaplayer?
JKW

Just want to drop a comment to say thank you @JKW for all the dedication and hours getting this addon where it is today.

I am new to home assistant and I am enjoying setting it up and automating my house.

I integrated the ytube media player and things are working flawlessly, by simply adding the ytube media player as a card.
but my end goal is to have a YouTube music tab in the dashboard where the family can use a tablet set as a kiosk to search and play music, however, I just noticed, a few comments ago, you’ve mentioned that search is hard to display in the UI.
Would this be ever possible? What is the closest I can do to streamline the search? Would appreciate an example yaml around the search.
Thanks!

1 Like

I figured out how to get the input search box and to call the search service.
Here is what you need to get it to work:

Add this to your config or use the helpers option Input Text - Home Assistant

input_text:
  ytube_music_player_search:
    name: YouTube Music Search
    icon: mdi:magnify
    initial: coldplay

from my understanding, lovelace does not support templating, so we need ton install https://github.com/gadgetchnnel/lovelace-card-templater

Finally add this to your dashboard

  - title: YT tes
    path: yt-tes
    badges: []
    cards:
      - type: vertical-stack
        cards:
          - type: entities
            entities:
              - entity: input_text.ytube_music_player_search
            show_header_toggle: false
          - type: custom:card-templater
            entities:
              - input_text.ytube_music_player_search
            show_header_toggle: false
            card:
              type: button
              tap_action:
                action: call-service
                service: ytube_music_player.search
                service_data:
                  entity_id: media_player.ytube_music_player
                  query_template: '{{ states(''input_text.ytube_music_player_search'') }}'
                target: {}
              show_name: false
              show_icon: true
              icon: mdi:magnify
              icon_height: 50px

It took me lots of trial and errors to get this to work, but now that the search works, would be great if we can integrate it with @JKW 's https://github.com/KoljaWindeler/ytube_music_player/blob/f68d2eb9e817bd983a1ec0934e189d0b376608ef/package/markdown.yaml and display the result on the same page… more work to be done, but if someone familiar with the UI can get this done pretty quickly

Edit:
You’ll notice that you need to hit enter or click on the search icon twice for the search to be updated with the keyword you have entered, that’s because the input text does not register unless you move focus out of the card. As a workaround, using a script would the job and does not require installing/using lovelace-card-templater

Here is the script you need and the UI code
Script:

test:
  alias: Search Youtube Music
  sequence:
  - service: ytube_music_player.search
    data:
      entity_id: media_player.ytube_music_player
      query: '{{ states(''input_text.ytube_music_player_search'') }}'
  mode: single
  icon: mdi:account-plus

UI:

      - type: vertical-stack
        cards:
          - type: entities
            entities:
              - entity: input_text.ytube_music_player_search
            show_header_toggle: false
          - type: button
            tap_action:
              action: call-service
              service: script.test
            show_name: false
            show_icon: true
            icon: mdi:magnify
            icon_height: 50px

This solution is more robust

6 Likes

Very nice. I saw that the media browser supports direct link now.
So the results can be displayed by showing an iframe to

http://hassio:8123/media-browser/media_player.ytube_music_player/search%2C

… Haven’t tried it but would work.
Could you post a screenshot of your solution?
Thanks, jkw

There is really not much to show, but I just enabled the extra sensors you have added and I can see the search results getting updated in the search attribute!!! so we you incorporate this data in your https://github.com/KoljaWindeler/ytube_music_player/blob/f68d2eb9e817bd983a1ec0934e189d0b376608ef/package/markdown.yaml and display it!!! I guess?

Screen Shot 2022-02-27 at 1.49.43 AM|690x154

EDIT:
I just noticed that in the markdown sample you have , the tracks are not selectable, it’s just a view .
I wonder if some frontend engineer on this thread can come up with a good UI design and incorporate service calls with the list of tracks etc…
Otherwise I will take a stab at it tonight

I don´t understand. Why there isn´t a youtube integration???

because both media_extractor and cast support playing YouTube already, was there something specific you were looking for?

1 Like

Thanks for the reply. I want home assistant to play, for example, the soft 80 station from youtube in a google home speaker. I can say “OK GOOGLE play soft 80s” but I want home HA to do it through an automation.

1 Like

I´m lauging at muself. Jajajajaja. THANKS

if you have audio only devices you will need to use media_extractor use the full YouTube url for the video/playlist your looking for, and choose music as the type Media Extractor - Home Assistant

I know it’s been a bit but how did you go about fixing your random playing script? I’m trying to figure out how to make My Likes playlist play randomly but it only shuffles the first 20 songs and that’s all it’ll play…Ignore my question I figured it out!! Under advanced configuration for the YTMusic player it was set to only load 25 songs. And it kept loading the same 25 and shuffling those. I am not sure how to have it select a different 25 and then shuffle those. But I increased that number to 1000 and it works ok now

2 Likes

I tried the code from @danil and it works fine so far (thanks for that). Displaying the search results in an iFrame also works, but is not really practical. The iFrame has to be reloaded to show the new results. Haven’t found a way to implement that yet. We would have to find a better way here.

Not working with Sonos?

  • Error executing service: <ServiceCall media_player.play_media (c:d6e93b09fc5f90a979a4e3698feba9fd): entity_id=[‘media_player.living_room_2’], extra=metadata=metadataType=3, title=Family Affair, artist=Mary J. Blige, images=[{‘url’: ‘https://lh3.googleusercontent.com/389OiIelieOXKeeUVs1dXGLlvgi8CjDkdKw-QRBwMNOTYZJ5X8sdDmoh2_Pukfrd7xGvx3u4Ai9Z7lm3=w120-h120-s-l90-rj’}], media_type=music, media_id=https://rr5—sn-8xgp1vo-xfgl.googlevideo.com/videoplayback?expire=1647834306&ei=YqA3YuUpx4nzBNGDhYAG&ip=108.54.180.73&id=o-AB1ekCalLgwk89VVlgbVdxyJ_rOwVPEzE2e5_xxMqAeI&itag=141&source=youtube&requiressl=yes&mh=0Q&mm=31%2C29&mn=sn-8xgp1vo-xfgl%2Csn-ab5sznze&ms=au%2Crdu&mv=m&mvi=5&pcm2cms=yes&pl=18&ctier=A&pfa=5&gcr=us&initcwndbps=1491250&hightc=yes&vprv=1&mime=audio%2Fmp4&ns=nYJLGWjT7r6S1ICiUqC6m2cG&gir=yes&clen=8560045&dur=265.866&lmt=1586608788927113&mt=1647812208&fvip=5&keepalive=yes&fexp=24001373%2C24007246&c=WEB_REMIX&txp=5531432&n=FKHFJDkcOSrD1UhU&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cctier%2Cpfa%2Cgcr%2Chightc%2Cvprv%2Cmime%2Cns%2Cgir%2Cclen%2Cdur%2Clmt&lsparams=mh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpcm2cms%2Cpl%2Cinitcwndbps&lsig=AG3C_xAwRQIgVJL27vCwaLy71zfRZb2ttNiX8T90jG-z-9Ib8Hm_QDcCIQCD0FFZFsNlzjbfRDd2yNbquXTs2H13n9sdxV5qOiuzJA%3D%3D&sig=AOq0QJ8wRQIgJV9S0isE1YGr6WlddoUuFetvmTde8-Z_rLXb0icQWMgCIQCuRLea6Jsy3rACaV4ttbC46Rr1UQxMOjjr3eegrYXVwQ==>

Nope, Sonos doesn’t support streaming by url

Have You ever had a problem when playing, that every, except the first one, tune has no sound? There is a song picture, I can see the progress bar moving, but no sound. Until I click Next Track then sound comes back. For that one song. Every next one is again without a sound.

I was able to install ytube_music_player and it works if I access it by it’s entity. But it’s hardcoded to the selected media player from the setup and it’s not showing up under Media. Any suggestions on what I need to do? Thanks!