Trying to send notifications to an LG TV, need help with node.js

Hi all,

Hope you don’t mind a question from a utterly clueless douchebag…

I’m trying to get SmartThings to be able to send text notifications to my LG C7 TV so a message will pop up saying “motion on driveway” etc.

The TV runs WebOS and as such supports a pretty decent set of network instructions including sending what they call a “toast” which appears on screen exactly as I want.

I followed the instructions at https://github.com/Danovadia/lgtv-http-server (install node.js; install lgtv package etc) and tweaked the index.js file to point correctly at my TV’s IP address.

I can now run a node command in my terminal locally that will pop up a message on the TV.

I’m a bit stuck though on how I should go about integrating this into SmartThings and my google-fu is failing me. It seems like I need to set up some sort of Node.js server and run the command via REST but I have no experience of this.

I have a Mac Mini server that’s running all the time so I have something to run Node on, it’s just figuring out how to trigger a command to it from SmartThings that’s confusing me.

Any suggestions for the clueless newbie much appreciated. Trying to search for specific simple information on Node.js is like holding a shot glass up to the Niagara Falls…

You need to create an http server in nodejs that accepts requests at some random port of your choice. Include that lgtv package, extract the message from the http request (say you’re using a post with a field message=text_goes_here) and pass it over to the lgtv package. Then use a SmartApp to send a HubAction to that IP and port where the nodejs is running. You can use CoRE or webCoRE to do that if you don’t want to write a SmartApp for it. I can help you out with some teamviewer tomorrow morning.

1 Like

Did you end up getting this working? I’m considering an LG tv in the near future and I’d like to be able to do this.

You can use my fork of his branch

I cleaned a code a bit and added some improvements.

Checkout my code and run “node server.js”
After it run on port 5555 go to
Http://localhost:5555/description

And you will have a list of all API methods.

If you run it on Linux (raspberry pi) you also have there lg-tv.service" if you want run it on startup. Of course you need to modify it and instal. How to do it? Google it :wink:

When server runs fine for you through web browser you also have there a device handler for smartthings which you can (but don’t have to) modify to your needs if you want to call other API methods than what is already in handler. The handler simply calls http endpoint of you server so you have to set your IP adress and port in device settings, after you add it.

2 Likes

Go for it. I bought oled b7 and it is really good TV for both watching and home automations. Magic remote is also great.

I also considered Phillips with Android TV but thanks God I haven’t bought it.

Hey @ady624

Don’t write the server and handler from scratch but feel free to use my fork of code and modify if needed. Read comments above describing fast installation etc…

Thanks @btrial , I already have a raspberry pi running as a makeshift Alexa, so i’ll try to get it running on that, once i make a final decision on which TV, and get it bought…

@btrial, I’m trying to get this going on my Pi, and could use your help.

Firstly, there’s a bug in the original discovery code (which seems unused by your server.js, but I’d like to get going at some point):

if (message.indexOf("LG Smart TV")) {

should be

if (message.indexOf("LG Smart TV")>=0) {

On my network I have 2 other devices that respond to discovery probes, and without this fix, I would often get the wrong one being discovered as my LG TV.

I have the server.js running on my Pi, and I can use curl to interact with it. I can set the volume on, and retrieve the status from the TV. Hard part done, I would have thought!

So now, I just want to get the SmartThings DTH working. I’ve installed your DTH as code, and published. Now, I’m not sure what to do next. I’m new at this stuff, so I might have missed a step. I have a few other DTHs installed, and I think the corresponding devices simply showed up when I went to add a thing in the app. But I’m not seeing any new LG TV device.

I’m wondering if the problem might be that the server.js is listening for connections only on the localhost address - that is, it’s bound to 127.0.0.1:5555. Thus my SmartThings hub cannot talk to it.

I’m running lgtv-http-server on an android device using Termux. 1/4 of the requests seem to fail, and it randomly crashes. But always displays the same error of a negative result number when only positive are allowed. Is that something you know, and can recommend a fix?