Playing around with LG Oled TV Api

I recently replaced my old plasma TV with a brand new LG Oled 55 C9. I am not an expert regarding TVs but after reading a lot of posts and reviews and got to the soloution that this TV was the best for my budget. I won’t  go into stuff like picture quality as you will find better info reagrding this on other sites. However I wanted to integrate the TV with Home Assistant and Node Red. First I asked myself why, but I would not really find any good reason to do this and also there were no automatisations either that I really needed. So what I did was just to experiment and see what I could do and maybe I will end up later with some good useful ideas.

So let get started. I have been using:

Home Assistant with the LG webOS Smart TV platform

The plug-ins SVT Play and TV 4 Play (Swedish channels by Lindell) installed via HACS.

Node Red with the node node-red-contrib-lgtv

And the node node-red-node-wol

Start by adding this below to your configuration.yaml. The wake on lan is needed in order for you to turn on your TV. You might also have to change some powersaving settings on your TV described in the official documentation. This is also why we will need the mac address here. restart Home Assistant. Follow the notification to finish the pairing and accept the pairing pop up code on your TV.  You can wait to add the sources list below until you have checked the state of the TV further down in this tutorial.

     service: wake_on_lan.send_magic_packet
       mac: "XX:XX:XX:XX:XX"
      - livetv
      - youtube
      - HDMI 3
      - SVT Play
      - netflix

Also add the following as well and restart again. This will enable the components for SVT and TV4.


Now it is time to do some testing and see what you can do in Home Assistant. Later on we will try some things in Node Red as well. Most of my automatisations are in Node Red. First lets somewhat services we can use in Home Assistant. We will also first check the state of the TV.

Below you can see that the TV is on. You will also see the sources list. This is what you should add as sources in the configuration.yaml. You will aslo see other info like sound output etc.

You can switch off your TV now with the remote controll. The state should switch to off. But now we can try to switch it on via Home Assistant. Go to services under the developer tab and choose media_player.turn on. Your TV should appear as an entity now. Press call service. The TV should now be turned on. Magic!

The next thing we will try is to switch source. You were able to list the sources in the state of the TV. So try things like Netflix, HDMI 3 etc. Press call service.

Ok, Next step is to switch channel. Choose the service below. You might have to modify what channel you want to switch to.

There are many other things you may want to try as well. Pressing buttons, changing volume or create a notification on the TV. You will find this info on the Home Assistant site for LG TV.

Next we will try the integration SVT Play. You will have 3 types of services. I recommend you to read the official integration manual as well.

svt_play.play_channel, svt_play.play_latest and svt_play.play_suggested

We will use svt_play.play_latest. Type in any program you want here. When you press call service rapport will play on my Chromecast on HDMI3 as this is where the device is connected.

Note that I am also using a Chromecast connected to HDMI 3. The LG TV has one app for SVT Play but you wont be able to execute some commands like svt_play.play_suggested to the entity media_player.lg_webos_smart_tv.

Now we will create a script to do many things. If you were watching Netflix and pressed the rapport service the TV may not switch to HDMI 3. So we will fix this below. I have put the section below in scripts.yaml. And I created a simple card in Lovelace to test the scripts. The script will:

Turn on the TV

Select HDMI3

Play Rapport from SVT Play

Select the optical sound output

  alias: Rapport2
    - service: media_player.turn_on
        entity_id: media_player.lg_webos_smart_tv
    - service: media_player.select_source
        entity_id: media_player.lg_webos_smart_tv
        source: HDMI 3
    - service: svt_play.play_suggested
        entity_id: media_player.chromecast2460
        program_name: rapport
    - service: webostv.select_sound_output   
        sound_output: external_optical

Node Red

You could just as well create some automatisations in Node Red. I will show two simple examples. The nodes are call services nodes (Home Assistant). There is an LG TV Node as well that you might want to try.

The first one and the image below switches input to HDMI3.

This one below plays Bamse via SVT Play service


This was just some examples and to be honest they do not really provide any good at all. But maybe you will find it useful anyway.