LGWebOS Binding (for LG WebOS TVs)

Hi,
I am looking for Beta tester for a new binding to connect modern WebOS based LG Smart TVs :


A jar bundle of a snapshot build is linked at the very top of the preliminary documentation.

Also, if anyone wants to contribute to the code, let me know…

Kind Regards
Sebastian

3 Likes

The binding polls each thermostat that is configured in your items

I assume that is a copy-paste error, unless you use your TV to controll your heating :smile:

I wonder whether we can redruce the size, 12MB for a binding is quite large. I checked the jar files and there are 10MB of resources, mainly images, contained in here. Is the Android library really needed? Maybe we can get rid of all these dependencies and slim down the ConnectSDK to work without it (the Apache license should permit that?).

Anyway, I’ll test the binding as soon as I find some time.

I have some rather bad news, I couldn’t test the binding. I copied the jar-file to the addons directory at the time I wrote the previous post, and I wanted to test the binding last night. Unfortunately, my openhab was not responding any longer because I get the following error: “Java heap space”.

So I assume that there is a memory leak somewhere in your binding startup code (I did not yet add any items! I just dropped the jar-file into the addons folder).

Please, don’t give up! I’m not a programmer, but I can do my best in testing - I have two LG smart TVs of both 2014 and 2015 years running webOS 2

Thx, copy & past error in wiki page is fixed :smile:

Regarding connect sdk and Android… Connect SDK does not provide a pure Java version and unfortunately Android API is heavily integrated. I did make an attempt but eventually arrived at the conclusion that if all necessary changes to the connect sdk files were applied to remove the API dependency all together we’d effectively loose the ability to upgrade to next connect sdk versions, once the provide one upstream.
So instead I chose a wrapper approach:

  • make as little changes as possible to connect sdk (which we can reapply to next connect sdk version via patches)
  • make connect sdk think it is running on android

I am very happy you spotted the image resources. That should help to reduce the filesize a great deal. Will look into it.

Well cannot reproduce the heap issue and also did not spot any abnormality using Visual VM while debugging another issue (see below). Maybe this is related to the large jar file size and smaller memory configuration on your system?

While running the plugin in my home I noticed a “performance leak”, which occurs when disconnecting the TV. Everytime I turned off the TV CPU load would rise. Was able to trace it to this issue: One of the websocket threads runs in an endless loop, described here https://github.com/TooTallNate/Java-WebSocket/issues/171

I made a new version tonight upgrading the websocket lib to a snapshot release, in which this issue is fixed. New version can be found here:

Will now look into the issue with jar file size.

we won’t :smile:

Here is the new version:

size reduced from 13.5 MB to 1.54 MB by removing dependency to large android jar

Thanks for removing the resources that are not needed *thumbsup*!

Concerning the memory leak, my openhab instance is running on a RasPi 2, without any specific memory settings.

I had a quick look at your sources and I would like to discuss one of your design decisions: in your bundle activator, you are starting a discovery service to check for existing TVs in the local network. This produces traffic and all the discovery and communication takes processing time and memory (this probably produced the memory leak I experienced).

  • What if there are plenty of TVs in my network and I want to use the binding only for one/some of them?

I would really appreciate a configuration via the openhab config file. Then we can explicitly specify which TV should be connected to openhab. Or maybe this is not even needed because the TV is referred by its IP/DNS name?! Would it be possible to call the DiscoveryManager first when there are items for the connectsdk-binding? Then all the bridges in class ConnectSDKBinding are lazily subscribed to the requested TV device? And by filtering for item configurations, the bridges are only subscribed to the requested and not to all TVs…

In openhab 2 / Eclipse Smarthome, there is an explicit concept for device discovery. I think your discovery mechanism would fit perfectly into that context. But in openhab 1.x, it could create unwanted side effects.

Hi, guys. I spent few minutes today for testing the binding - TV responced immidiately after adding the binding - it asked for allowing / not allowing external connection. Then Openhab welcome message appeared, but I couldn’t control TV from Openhab (tested VolumeControl, PowerControl and ToastControl). Tested on 42LB671V and 32LF653V.

Here are some photos and log errors:


[INFO ] [b.c.internal.ConnectSDKBinding] - added: {“modelName”:“LG Smart TV”,“lastConnected”:9223372036854775807,“lastKnownIPAddress”:“192.168.0.30”,“modelNumber”:“42LB671V-ZF”,“id”:“3d25509d-e11f-4a33-81ca-6c720e01e6e2”,“services”:{“1eef01bd-461b-8656-0cc3-4c0f1da57322”:{“description”:{“filter”:“urn:lge-com:service:webos-second-screen:1”,“modelName”:“LG Smart TV”,“port”:1277,“ipAddress”:“192.168.0.30”,“modelNumber”:“42LB671V-ZF”,“serviceId”:“webOS TV”,“uuid”:“1eef01bd-461b-8656-0cc3-4c0f1da57322”,“version”:“4.0.3”,“friendlyName”:"[LG] webOS TV"},“class”:“WebOSTVService”,“config”:{“lastDetection”:1452018180,“UUID”:“1eef01bd-461b-8656-0cc3-4c0f1da57322”,“class”:“ServiceConfig”}}},“lastDetection”:1452018180,“friendlyName”:"[LG] webOS TV"}
[INFO ] [b.c.internal.ConnectSDKBinding] - Pairing required.
[INFO ] [b.c.internal.ConnectSDKBinding] - Device ready: {“modelName”:“LG Smart TV”,“lastConnected”:1452018199,“lastKnownIPAddress”:“192.168.0.30”,“modelNumber”:“42LB671V-ZF”,“id”:“3d25509d-e11f-4a33-81ca-6c720e01e6e2”,“services”:{“1eef01bd-461b-8656-0cc3-4c0f1da57322”:{“description”:{“filter”:“urn:lge-com:service:webos-second-screen:1”,“modelName”:“LG Smart TV”,“port”:1277,“ipAddress”:“192.168.0.30”,“modelNumber”:“42LB671V-ZF”,“serviceId”:“webOS TV”,“uuid”:“1eef01bd-461b-8656-0cc3-4c0f1da57322”,“version”:“4.0.3”,“friendlyName”:"[LG] webOS TV"},“class”:“WebOSTVService”,“config”:{“clientKey”:“f35a…”,“class”:“WebOSTVServiceConfig”}}},“lastDetection”:1452018180,“friendlyName”:"[LG] webOS TV"}
[ERROR] [b.c.i.bridges.TVControlProgram] - error: 0 null null
[ERROR] [.b.c.i.b.MediaControlPlayState] - error: 0 null null
[ERROR] [b.c.i.bridges.TVControlChannel] - error: 500 {“errorText”:“Invalid broadcastID error”,“returnValue”:false,“errorCode”:“BROADCAST_ERROR_0001”} Application error
[ERROR] [o.b.c.i.b.TVControlChannelName] - error: 500 {“errorText”:“Invalid broadcastID error”,“returnValue”:false,“errorCode”:“BROADCAST_ERROR_0001”} Application error
[WARN ] [.w.internal.servlet.CmdServlet] - Received command ‘TOGGLE’ for item ‘LG_TV0_VolumeUp’, but the item does not exist in the registry
[WARN ] [.w.internal.servlet.CmdServlet] - Received command ‘TOGGLE’ for item ‘LG_TV0_VolumeDown’, but the item does not exist in the registry

[INFO ] [b.c.internal.ConnectSDKBinding] - added: {“modelName”:“LG Smart TV”,“lastConnected”:9223372036854775807,“lastKnownIPAddress”:“192.168.0.31”,“modelNumber”:“32LF653V-ZC”,“id”:“0250b270-3d3f-4a7d-9efc-e4fcff99ea5e”,“services”:{“5898a6ba-7ee1-80c4-4cbc-68b25015d29d”:{“description”:{“filter”:“urn:lge-com:service:webos-second-screen:1”,“modelName”:“LG Smart TV”,“port”:1842,“ipAddress”:“192.168.0.31”,“modelNumber”:“32LF653V-ZC”,“serviceId”:“webOS TV”,“uuid”:“5898a6ba-7ee1-80c4-4cbc-68b25015d29d”,“version”:“4.1.0”,“friendlyName”:"[LG] webOS TV LF653V"},“class”:“WebOSTVService”,“config”:{“lastDetection”:1452018931,“UUID”:“5898a6ba-7ee1-80c4-4cbc-68b25015d29d”,“class”:“ServiceConfig”}}},“lastDetection”:1452018931,“friendlyName”:"[LG] webOS TV LF653V"}
[INFO ] [b.c.internal.ConnectSDKBinding] - Pairing required.
[INFO ] [b.c.internal.ConnectSDKBinding] - Device ready: {“modelName”:“LG Smart TV”,“lastConnected”:1452018983,“lastKnownIPAddress”:“192.168.0.31”,“modelNumber”:“32LF653V-ZC”,“id”:“0250b270-3d3f-4a7d-9efc-e4fcff99ea5e”,“services”:{“5898a6ba-7ee1-80c4-4cbc-68b25015d29d”:{“description”:{“filter”:“urn:lge-com:service:webos-second-screen:1”,“modelName”:“LG Smart TV”,“port”:1842,“ipAddress”:“192.168.0.31”,“modelNumber”:“32LF653V-ZC”,“serviceId”:“webOS TV”,“uuid”:“5898a6ba-7ee1-80c4-4cbc-68b25015d29d”,“version”:“4.1.0”,“friendlyName”:"[LG] webOS TV LF653V"},“class”:“WebOSTVService”,“config”:{“clientKey”:“6586…”,“serverCertificate”:“MIIDT…”,“class”:“WebOSTVServiceConfig”}}},“lastDetection”:1452018931,“friendlyName”:"[LG] webOS TV LF653V"}
[ERROR] [b.c.i.bridges.TVControlProgram] - error: 0 null null
[ERROR] [.b.c.i.b.MediaControlPlayState] - error: 0 null null
[INFO ] [b.c.internal.ConnectSDKBinding] - Device removed: {“modelName”:“LG Smart TV”,“lastConnected”:1452018983,“lastKnownIPAddress”:“192.168.0.31”,“modelNumber”:“32LF653V-ZC”,“id”:“0250b270-3d3f-4a7d-9efc-e4fcff99ea5e”,“services”:{},“lastDetection”:1452018931,“friendlyName”:"[LG] webOS TV LF653V"}
[ERROR] [.o.b.c.i.b.VolumeControlVolume] - error: 0 null connection lost

No memory leaks and extra load - maximum on the chart was fixed when openhab service was restarted:

Hi,

Ever since I deployed the fixed version on saturday night load is fine (maximum is 0.5, since)

For memory usage I don’t have the equivalent long term graph, but looking at Visual VM it looks like openhab is filling up 1/4th of my total mem - as I would have expected it. MaxHeapSize of the VM is at 4131389440 bytes (3.9GB)

Looking at which threads occupy memory:

I don’t see connect sdk binding threads unter the top 6, which make up 85% of the memory consumption. So should also be ok.

@paphko I agree, that this should plugin should not connect to any tv found on the network automatically (only if an item is bound to the ip). Will look into it, and see how this can be optimized.

@strelok1986: these 500 errors are interesting (500, probably an internal server error on the television). Two things come to mind:
a) do your tvs work with the lg provided apps for webos?
b) can you enable debug level logging for the plugin. Just add the following two loggers to your logback.xml:

<logger name="org.openhab.binding.connectsdk" level="DEBUG"/> <logger name="com.connectsdk" level="DEBUG"/>

@sprehn:
a) Yes, TVs work fine with many apps from LG store
b) done. See log in my google drive.

did you add also the items in items configuration file ?

check out the examples here
https://github.com/sprehn/openhab/wiki/Connect-SDK-Binding

Sebastian Prehn

@sprehn:
sure, I added items and edited sitemap, don’t worry about it)

The error Messages in your log file suggest that openhab cannot find the items declared in sitemap. Events do not reach the plugin yet

I declared items (by copypasting from wiki, changing just tv IP) like

Switch LG_TV0_VolumeDown “Volume Down” { connectsdk=“192.168.0.31:VolumeControl:down”, autoupdate=“false”}

and added them to sitemap like

Switch item=LG_TV0_VolumeDown

As I remember, there were no events dedicated to TV items in openhab events log. I guess, you are right, the system simply doesn’t see the items.

Just created a new version. ChangeLog:

  • connect to devices only if item configuration for it exists and performance enhancements
  • report PowerControl ON/OFF to bus correctly

did you make any progress?

FYI, made an update to the wiki page on how to power on the the tv via openhab: https://github.com/sprehn/openhab/wiki/Connect-SDK-Binding