Page 1 of 1

lg webos via Python

Posted: Thu May 14, 2020 5:22 pm
by V_J

I found this python library ( ) to communicate with an LG TV. I manage to get some things done in scripts, but am not sure how to start writing a plugin...

In "C:\Program Files (x86)\EventGhost\lib27\site-packages", I added the folders pywebostv and ws4py with respectively the files in and

Then, following the instructions on , I managed to get the connection to the TV using this script:

Code: Select all

from pywebostv.discovery import *    # Because I'm lazy, don't do this.
from pywebostv.connection import *
from pywebostv.controls import *

# The 'store' gets populated during the registration process. If it is empty, a registration prompt
# will show up on the TV. You can pass any dictionary-like interface instead -- that when values are
# set, will persist to a DB, a config file or something similar.
store = {}

# Scans the current network to discover TV. Avoid [0] in real code. If you already know the IP,
# you could skip the slow scan and # instead simply say:
#    client = WebOSClient("<IP Address of TV>")
client =[0]
for status in client.register(store):
    if status == WebOSClient.PROMPTED:
        print("Please accept the connect on the TV!")
    elif status == WebOSClient.REGISTERED:
        print("Registration successful!")
(one change: I have to put the IP address of the TV, the discover function throws an error after some time)

After this script, I can e.g. query the volume with "media.get_volume() ".

The issues I have
  • The connection is not persistent: I need to find a way to store "client", otherwise the TV always pops up the pairing question. How do I store it between different executions of EventGhost?
  • How do I start structuring this into a plugin? (I've never written one, just dabbled a bit in existing ones)

Re: lg webos via Python

Posted: Thu May 14, 2020 8:27 pm
by Sem;colon
Hi Jörg,

Did you know there is already a plugin for LG TVs?
I remember that I've seen that, unfortunately I couldn't use it as my TV is too old (no smart tv yet)
Perhaps the work is already done ;)

Re: lg webos via Python

Posted: Fri May 15, 2020 7:27 am
by V_J
Yes, there are several... There is this one ( , which turned into the LG-2012IP plugin ( viewtopic.php?f=10&t=6144 ), but I cannot get it to accept the TV. I suspect that the authentication has changed, as the documentation mentions getting the key from the settings menu in the TV, but in mine (2017 model) there has to be a request sent to the TV, which prompts an accept dialog that has to be confirmed on the TV side.

The code I mentioned above works for my TV: when put in a single Python script in Eventghost, first the TV pops ups the accept dialog, and next I can call some media controller (to e.g. adjust volume or even request it).

All the pieces therefor seem present to make this code work: the connection, the actions and the events... I feel it is a matter of puzzling it together to get a plugin...

Re: lg webos via Python

Posted: Fri May 15, 2020 10:00 am
by Sem;colon
Hi Jörg,
In that case, I'd recommend you take a looks at the code from the old plugin to learn from it. That's how I created my first plugin as well ;)

Re: lg webos via Python

Posted: Fri May 15, 2020 5:04 pm
by V_J
Yep... Would that be before or after adding the O-Mega interface.... :lol:

Now just finalizing the interfacing in Loxone and with the Squeezebox and amplifier.
Next software functions (which is easier), and then the TV... :)

Re: lg webos via Python

Posted: Fri May 15, 2020 8:31 pm
by Sem;colon
Haha, after that, of course! :lol: