Play youtube on smart TV

Hi,

ANy suggestions on how to play videos on a smart TV?
Media player all setup and working with a LG using component webostv and media_extractor.
No problems in changing the TV source to youtube, but can’t seem to get it to play a youtube
Here’s the script:
video_intro:
alias: “first_video”
sequence:

No errors reported, just doesn’t play.
Any suggestions?
Thanks,

Rob.
`

try ‘music’ as media type

A media type. Must be one of music , tvshow , video , episode , channel or playlist . For example, to play music you would set media_content_type to music .

That is not a home assistant script. Home assistant scripts are written in yaml, which does not have bullet points.

Or perhaps you didn’t read the instructions at the top of the page?

Actually it was a poor attempt on my behalf of to cut n paste code so humbly appologies!

Here’s the correct format:

video_intro:
  alias: “first_video”
  sequence:
    - service: media_extractor.play_media
      entity_id: media_player.living_room_tv
      data:
        media_content_id: "https://www.youtube.com/watch?v=bmGsQkLb4yg"
        media_content_type: video/youtube

Which was derived from the following topic:

But I can’t seem to get the same going. Like mentioned no errors reported. Other Media player scripts do work ie can script powering off/on and selecting the youtube channel. Just can’t get it to play any media. Tried the “music” option (thanks for that) but that didn’t work either.

Rob.

Hey guys, any update on this point?
Also stuck on with this.
Need to share youtube video on my LG TV and can’t do it.

I’m also interested in getting this working!

Anyone found anything about that?

The below works for me, It works on my Sony but I cannot get it working on my LG yet. Entity_id is moved within the data block
configuration.yaml

media_extractor:

Scripts.yaml

nature:
  alias: Nature
  sequence:
    - service: media_extractor.play_media
      data:
        entity_id: media_player.gameroom_tv
        media_content_id: "https://www.youtube.com/watch?v=rgZfmWXTqas&t=4834s"
        media_content_type: video/youtube

Thanks. If you do find the way please post the solution

In the webostv component docs, it mentioned pylgtv, so I went looking there and seems like this is definitely possible, so I tried out the following successfully

from pylgtv import WebOsClient

client = WebOsClient('1.2.3.4')

apps = client.get_apps() # At this point your TV will prompt you to authorized pairing app
youtube_app = [ app for app in apps if app['title'] == 'YouTube' ][0]
youtube_id = youtube_app['id'] # Mine returned "youtube.leanback.v4"

client.launch_app_with_content_id("youtube.leanback.v4", "dQw4w9WgXcQ") # It works!

The tricky part was determining the youtube id, which was “youtube.leanback.v4”. I imagine it will only change with a major youtube app update.

I tried to do this with webos.command service in home-assistant… but that didn’t work. Looking at the code, it seems just two days ago, https://github.com/home-assistant/core/commit/6f4829c390cf38ed6c727df1c2267ea4cc353af4 which should enable this! I’m thinking this change will be included in 1.111.0

If a brave soul wants to deploy the dev builds and try it out, I imagine this should should work

service: webostv.command
data:
    entity_id: media_player.foobar
    command: "system.launcher/launch"
    target:
      id: "youtube.leanback.v4"
      contentId: "dQw4w9WgXcQ"

Alrighty, I was successfully able to do it on homeassistant/home-assistant:0.111.0.dev20200530

service: webostv.command
data:
  entity_id: media_player.jtv
  command: "system.launcher/launch"
  payload:
    id: "youtube.leanback.v4"
    contentId: "dQw4w9WgXcQ"
1 Like

That’s good news!
However to be honest I didn’t understand how you extract the id: "youtube.leanback.v4" i(s it python script?) neither the second part of how to use the service: webostv.command
When you find some time please explain a bit

Certainly. First I was using the “Developer Tools > Services” in the home-assistant UI trying to invoke the possible services. I noticed that there were several services that started with webostv.* specifically the webostv.command and the documentation that was associated with it referred to a external python project called pylgtv. I installed pylgtv on my local machine and was playing around, calling get_apps returned a list of all the apps (and for each app there was a title, id, etc). I saw a function there called launch_app_with_content_id and I fed it app='youtube.leanback.v4', contentId='dQw4w9WgXcQ'. Looking at the function, it was also using EP_LAUNCH = "system.launcher/launch"

Given this info, I tried to see how I can feed it in to home-assistant’s webostv service. Noticed the last commit which was by @PotatoDrug which enabled passing the command + payload (and I took a guess that payload is where I would cram id/contentId)

1 Like

Thanks for the details. I hope that it will be doable with the 0.111 release. When you know how we can call to play a particular playlist from youtube please leave here an example.
I am also wondering if with this way we could call a particular movie from Netflix for example. I think it could.

The following code worked for my LG TV (55’’ with webOS).

entity_id: media_player.sofita_tv
command: system.launcher/launch
payload:
  id: "youtube.leanback.v4"
  contentId: "nEi2Udjc0lQ"

where contentId is the youtube video url.
It does work!

The only disappointment was that TV asks you if you want to play the video as it was called outside youtube app.

Disappointment indeed as I was planning to create some NFC tags for my son (he is 3 years old) to play his favorite cartoon without parental control :slight_smile:

If anyone has found a way to bypass this window on TV it will be ACE!
Looked into youtube settings on our TV but there is no such an option.

Anyhelp would be much appreciated.

I found a way to bypass the popup box on TV.
Created a script, added some delay and then press ENTER (via service webosTV.button)
It works so smoothly :slight_smile:

video1:
  alias: video1
  sequence:
  - service: webostv.command
    data:
      entity_id: media_player.sofita_tv
      command: system.launcher/launch
      payload:
        id: youtube.leanback.v4
        contentId: nEi2Udjc0lQ
    entity_id: media_player.sofita_tv
  - delay: 00:00:08
  - service: webostv.button
    data:
      entity_id: media_player.sofita_tv
      button: ENTER
    entity_id: media_player.sofita_tv
  mode: single
2 Likes

just what ive been looking for! thank you, but i still ahve to click the play this video… any idea why?

Raise the delay value a little bit.
I end up with the following and it works :smile:

video4:
  alias: video4
  sequence:
  - service: webostv.command
    data:
      entity_id: media_player.sofita_tv
      command: system.launcher/launch
      payload:
        id: youtube.leanback.v4
        contentId: EsdyiNQgmIE
    entity_id: media_player.sofita_tv
  - delay: 00:00:08
  - service: webostv.button
    data:
      entity_id: media_player.sofita_tv
      button: ENTER
    entity_id: media_player.sofita_tv
  mode: single

Please notice the delay after the video is triggered

- delay: 00:00:08

I delay for 8’’ before I send the ENTER command.
Hope that helps!

1 Like

im going to try like 20 seconds! maybe thats the issue. mine takes longer to load up

Did you make any progress?