Play youtube on smart TV

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
1 Like

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 delayed for 8’’ before I sent the ENTER command.
Hope that helps!

2 Likes

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

Did you make any progress?

Hello,
thank for the messge. not yet. i had to postpone this, because i had other major issues. but i will get back to this , this week! and will let you know for sure. but the delay of 20 seconds didnt work.

Please share the code with us

alias: Play welcome Video Youtube
sequence:
  - service: webostv.command
    data:
      entity_id: media_player.lg_webos_smart_tv_3
      command: system.launcher/launch
      payload:
        id: youtube.leanback.v4
        contentId: n_5i_nzS1z0
    entity_id: media_player.lg_webos_smart_tv_3
  - delay:
      hours: 0
      minutes: 0
      seconds: 10
      milliseconds: 0
  - service: webostv.button
    data:
      entity_id: media_player.lg_webos_smart_tv_3
      button: ENTER
    entity_id: media_player.lg_webos_smart_tv_3
mode: single
icon: 'hass:youtube'

so it still stoped at do you want to play this video