LGWebOS Binding - sendButton() question

Hi @sprehn

I’m trying to implement a remote control widget for HABPanel to simulate (some of) the functionality of the physical remote. This is mainly to allow navigation and selection within web applications (e.g. Netflix, Amazon, etc.)

My configuration:
openhabian 2.5.0.SNAPSHOT (build 1760)
TV model#: UJ657A
WebOS: 3.8.0.61206

So, I created a dummy “button” item and rules to invoke the sendButton() action. The UP, DOWN, LEFT, RIGHT and HOME buttons all work as expected but OK, ENTER, DELETE and BACK don’t seem to have any effect.

After enabling debug logging, I’m seeing that the OK button is sent as a mouse click instead of a button:

2019-11-20 05:33:53.429 [ome.event.ItemCommandEvent] - Item 'LG_TV0_Button' received command OK
2019-11-20 05:33:53.435 [vent.ItemStateChangedEvent] - LG_TV0_Button changed from LEFT to OK
2019-11-20 05:33:53.446 [DEBUG] [nternal.handler.LGWebOSTVMouseSocket] - Connecting to: ws://192.168.10.124:3000/resources/d2a586b1363ebbab58156f34e4c4e917f463aba9/netinput.pointer.sock
2019-11-20 05:33:53.459 [DEBUG] [nternal.handler.LGWebOSTVMouseSocket] - WebSocket Connected to: /192.168.10.124
2019-11-20 05:33:53.461 [DEBUG] [nternal.handler.LGWebOSTVMouseSocket] - Message [out]: type:click

I had kind of assumed that the sendButton() action was a (possibly partial?) implementation of an IR Remote control command set. Is that not the case?

Ideally, I would like to extend the button action and implement the full IR Remote functionality - is this even possible and, if so, is there any documentation available from LG dev that you could point me to?

Thanks in advance!
Bob

Hi,

following buttons indeed use the mouse api

  • HOME
  • BACK
  • UP
  • DOWN
  • LEFT
  • RIGHT

while OK, ENTER, DELTE, BACK use the keyboard api.

to be honest, have not used this at all myself.

Any help in debugging or enhancing this binding is welcome. So feel free to join.

there is unfortunately no documentation from LG whatsoever. I am reverse engineering their lgconnect library which is not maintained since multiple years.

Kind Regards
Sebastian

Thanks Sebastian! This binding is working amazingly well for me, which is a testament to your reverse engineering-fu :slight_smile:

I haven’t done any openHAB development, although I have lots of experience with eclipse projects. Is there anything I should watch out for when setting up my openHAB dev environment? Do I need to import the entire openhab stack or can I just work with the lgwebos binding?

Cheers,
Bob

There is a guide to set up the Eclipse IDE

you then need a fork of https://github.com/openhab/openhab2-addons

and off you go :slight_smile:

I’ve got the lgwebos binding building and ready to test. I would like to insert this temporarily into my working openhabian setup, but I’m a little hesitant. Is it safe to just drop the jar into the addons folder? Do I need to disable the original, distribution binding somehow first? Will I be able to restore my previous working environment after testing by simply removing the addons jar?

Thanks for your help.

yes. just drop it into addons folder

Well here’s an interesting fact: the button that’s labeled “OK” on my remote control is actually sending the string “ENTER” as the button name. Found this out by just trying different button name strings (in the sendButton(OK) action) until I ran into something that works :slight_smile:

Next I’ll try to figure out what all the other remote control buttons are called. If I get this to work, I’ll expand the LGWebOSActions.Button enum to include all the other button names. Stay tuned…

EDIT:
I figured the best way to discover button names was to create a channel, called “IRCode”, that accepts a button name string (I just patterned it after the Toast code). But I’m not seeing the new channel in the LGWebOS “Thing” in PaperUI. Do I need to uninstall the LGWebOS binding and reinstall it?

UPDATE:
Found a bug and finished the new IRCode channel and dropped the new jar into addons, but I’m still not seeing the new channel. I’ve also created a new lgtv.items entry for this channel, like so:

String LG_TV0_IRCode "IRCode"                { channel="lgwebos:WebOSTV:e19b8745-a30c-4143-7cd9-8f6b275a0717:irCode"}

which is just a copy/paste of my existing “Toast” channel with the new channel ID.

I then tried installing a new OH2 snapshot on a different machine, added the new jar and items file, and voila! It works! Now my questions is why isn’t it working in my existing (production) installation. What am I missing? I’ve searched the entire drive for any leftover LG WebOS artifacts (sudo find / -name ‘*lgwebos*’) and find only the new jar.

I then tried adding the channel manually in /var/lib/openhab2/jsondb/org.eclipse.smarthome.core.thing.Thing.json which does force it to show up in PaperUI. When I then try to send a valid IR command (e.g. “RIGHT”) using this item, I get an error in the log:

2019-11-23 16:40:41.537 [DEBUG] [ebos.internal.handler.LGWebOSHandler] - handleCommand(lgwebos:WebOSTV:e19b8745-a30c-4143-7cd9-8f6b275a0717:irCode,RIGHT)
2019-11-23 16:40:41.539 [WARN ] [ebos.internal.handler.LGWebOSHandler] - Unable to handle command RIGHT. No handler found for channel lgwebos:WebOSTV:e19b8745-a30c-4143-7cd9-8f6b275a0717:irCode. This must not happen. Please report as a bug.

I don’t get it - the exact same jar that works in a new installation just refuses to work in my existing installation.

I don’t want to have to rebuild my entire setup if I can avoid it - any suggestions?

you may need to checkout what OH has loaded via the karaf console. bundle:list. and monitor the log while loading the new jar. there is probably an error somewhere.

Looking at the installed bundles, I see 3 for LG WebOS with different build timestamps:

235 │ Active │  80 │ 2.5.0.201911191713      │ openHAB Add-ons :: Bundles :: LG webOS Binding
264 │ Active │  80 │ 2.5.0.201909232135      │ openHAB Add-ons :: Bundles :: LG webOS Binding
265 │ Active │  80 │ 2.5.0.201911232059      │ openHAB Add-ons :: Bundles :: LG webOS Binding

So I uninstalled all but the most recent - no luck.

Then I stopped OH, and physically edited the jsondb files and removed all traces of LG WebOS that I could find, restarted and now I still have 2 LG WebOS bindings:

265 │ Resolved │  80 │ 2.5.0.201911232059      │ openHAB Add-ons :: Bundles :: LG webOS Binding
267 │ Resolved │  80 │ 2.5.0.201911230734      │ openHAB Add-ons :: Bundles :: LG webOS Binding

I can’t figure out where this older bundle jar is being loaded from. I’m guessing that karaf uses the first bundle it finds (which in this case is my most recent, working build) because now the IRCode channel is working.

OH configuration is hard :frowning:

Hi Sebastian,

I have created PR 6492, which adds a new IRCode channel. Please review and let me know if there are issues/concerns. Thanks!

hey, just saw it now… will have a look in the next days

ok, already reviewed. what could we name the channel without implying that these are codes sent via infra red? Aren’t they Buttons on the Remote Control. so rcButton ?

Sure, rcButton sounds good to me. I’ll make the necessary name changes some time in the next few days and resubmit this PR.

Just a suggestion - not sure if it will work, but try:

  • stop openhab
  • clear the cache (userdata/cache/org.osgi*?)
  • start openhab
  • wait until the log settles down
  • restart openhab again

Thanks Jim, already figured it out :slight_smile:

I just saw that the build artifacts are now labeled as version 3.0.0. Is it still OK to merge my changes into master, or should I create a feature branch?

I would say, update your PR and see if it can be merged without conflicts.

otherwise you have to rebase

it has conflict, I think you should rebase

OK, I’ve got a new PR 6635
Please review and let me know.