I’m interested in having the SmartHub control some LG 65UH6030 televisions (a whole array of them). These are Internet connected via wired Ethernet and they are set to respond to WakeOnLan commands (so, “always listening”). I’m reasonably sure these devices can be completely controlled (on/off/various functions) via the web API, but I don’t know for sure.
Let’s start simple: has anyone been able to control webOS 3.0 LG devices yet? I’m happy to follow other people’s hacks.
quick way to work this out is to sniff the packets from the mobile app for the TV, assuming there is one. That’s what I did with my Celcus TV (cheapo UK brand). If you have an android phone download an app called packet capture, then run the mobile app and turn on the tv and do a few things. From this you’ll find the respective APIs and figure i out. The only catch is if there’s encryption enabled on the connection, but hopefully you should be able to figure it out.
I confess I’m really looking for a simple RESTful way to run just a few basic commands. I’m not trying to code an interactive app - I just want to issue “turn on; change to web browser app; navigate to page http://foo.bar.com” and then, in other instances, “turn off” (duh). I have 6 TVs right now and it’s trivial for me to individually record their Ethernet MAC addresses and/or do any individual figuring out of “pairing codes” (which seem to be a thing in LG tvs).
edit: The difference between issuing a random HTTP (GET or POST) and executing a python or NPM is significant. I can trivially cause GET or POST commands, but I cannot trivially execute more complex scripts (at least, as things stand now).
Agreed. It sure would be nice if someone made a ST device for WebOS LG TV that would cover at least the most basic functions and communications. I know SmartThings is Samsung, but given WebOS is open source and LG has an open API, it shouldn’t be all that difficult for someone in our awesome community of developers and would open up a whole new market of Smart TV devices to the SmartThings library.
I just ran across https://github.com/dan06/SmartThings-LG-Smart-TV which is damn close to what I’m looking for… has anyone tried it? Unfortunately this is specifically noted as “pre-2012 TVs” where I have 2016 model.
Well, my cursory examination of the question yields an npm package. I just verified it works. It’s Node, but I’m thinking I might build something to pass notifications from SmartThings through this.
Yeah, I’m aware of that package and I’m finally broken down enough to play with it today. There are two reasons I didn’t do this up front:
I was hoping there’s a native way to do this with my ST platform, thus not requiring any other devices on my LAN
I’m not a Node user, and I kinda didn’t want to be (I don’t want to have to play with a new platform just to do a single thing).
With all that said I just discovered I can run Node on my Synology DS15, which is the only other device always on that LAN and, separately, I’ve discovered a handful of useful packages for some other smart connected devices (notably my Daikin HVAC system, which is web connected using their adapter).
Net result? I’m playing with Node now
Also for the record I’m actually trying to control a set of TVs (six) so I’m going to have to hack around to “pair” with man at a time. I’m happy to start small though, complete control over one device is a great start!
Well, I’ve found some better packages, but I’m now a bit lost. I’ve determined that https://www.npmjs.com/package/lgtv2 is a newer version of the package you cited (unfortunately the original lgtv package is no longer supported) and, even better, there’s https://github.com/Danovadia/lgtv-http-server that seems to do exactly what I want.
Unfortunately I have no idea how to install and use https://github.com/Danovadia/lgtv-http-server … the instructions some cut-and-pasted from the source project, and even those instructions don’t make sense to me (I’ve installed and tried to run the example, but I literally don’t know how to tell if it’s pairing with my TV or not).
I’ll pursue getting the Github fork and Node packages installed on my Synology elsewhere (in relevant forums and whatnot), but I wanted to cross post the progress here just in case anyone else is interested (or wants to help solve the problems here, which is fine by me!).
Quick update: I have a solution now! In short: I had to “give in” and use Node to augment Smart Things.
Slightly more detail for now: I’m not quite done yet, so some of this may change, but in general:
I have a Synology device, so I used the GUI to install Node (note that I actually have Node and Apache both running, which doesn’t seem to be a problem at all!)
SSH into my Synology and using NPM I installed lgtv2, so literally npm install lgtv2
(Obviously) plug my LG TV in with wired Ethernet. (Slightly less obviously) I needed to enable WakeOnLan, which is done implicitly by disabling the power saving mode. This was tricky to find because it seems to be relatively recent that LG changed this workflow and the old docs all refer to an explicit WOL menu that’s no longer there.
Put this in a text file, I’ll call it tvcontrol.js. This is pure JavaScript meant to be executed by Node. Note that I’m using “static DCHP” so my TV’s IP address on my LAN doesn’t change. You’ll need to decide how you want to point at your TV - basically “put the correct LAN IP and ignore any readme instructions you find about lgsmarttv.lan or anything like that.” (those are in the other lgtv node package, “v1”, that I’m not using). var lgtv = require(“lgtv2”)({ url: ‘ws://192.168.1.2:3000’});
lgtv.on(‘connect’, function (err, res) {
lgtv.request(‘ssap://system.launcher/launch’, {id: ‘com.webos.app.browser’, target: ‘http://google.com/#q=smartthings+lgtv’});
lgtv.disconnect();
});
Execute the script with node tvcontrol.js . Note: The first time you do this the TV should ask you if it is ok to pair with the network remote, which you’ll need to manually approve with your existing television hardware remote (e.g. the IR one). Successful pairing should save a kind of keyfile locally that will be automatically detected by lgtv2 so you don’t need to re-pair in the future.
All the magic was in Step 4’s JavaScript. It was a bit hard to figure out how to hand the right request payload, but now that I’ve got it I’m all good. I’ve run some spot checks and this command forcefully opens the web browser to the URL in question no matter what else the TV was doing - exactly as I wanted!
In theory, yes. I power on my TVs using WOL packets generated from the Synology device (although I think ST can do WOL too, maybe??). I activate the web browser and tune to specific URLs using my integration, and that’s it. I believe you can launch Netflix, but I have not tried. I also believe you can control the Input function, but again, I haven’t tried.
Hi Lkjsaendlkje, I’ve followed your guide on a raspberry Pi as that’s what I have running some LED strips and got it control my LG b6v using your node script.
Question is how do I then get smart-things to run the script. Sorry new user here and I’ve just been cutting and pasting everyone else’s work to date.
It is a bit clunky, but using a raw HTTP GET request over to whatever device is running Node should work just fine (I just have a cronjob on my other device that executes what I want on a schedule, entirely outside my ST sphere of influence).
My solution to this problem ended up being a raspberry pi with thethingbox.io image on it. The main feature is node-red. There is a node already made up with most if not all the functionality of the npm package node-red-contrib-lgtv. I installed that and also setup the mqtt-smartthings-bridge on the same box. Then I used the preinstalled mqtt server integration to receive device changes.
Currently I only have one flow setup that turns on the tv when a virtual switch comes on with Wake On Lan and turn off with the command node from the lgtv. In the future I want to use the toast node to send notifications from smartthings and other services to my TV. For example: package arrived at the front door.
One limitation I figured out is that the node does not report the power status of the TV. If you turn it off or on with the remote then the virtual device on smartthings will be in the wrong state.
To the best of my knowledge there are no practical ways to ask “are you on or off right now?” however, you can deterministically infer state by simply pinging the device (send an ICMP packet). Devices capable of WOL should drop ICMP packets when they are off and, in my experimentation, LG TVs will reply to ICMP when they are on starting a few seconds into their boot process (and continually while they are awake). Note that ICMP is handled at the network interface level and it does not necessarily mean your TV is happy (it could be on but also locked/frozen). I’m sure there are innocuous functions you could run from the LG control libraries that would help validate if the TV is happy (like “check volume level”).
I have a Synology and have both Apache and node.js installed
I can pair my TV via the tvcontrol.js code, however, whenever I attempt to do an npm start I get:
I have to ask why you are trying to run npm start … literally what is your goal? I think you might be missing some fundamentals about Node (the webserver/daemon) and the Node Package Manager (npm). I would explain “npm start” in plain English as “Node Package Manager, please install a package called ‘Start’ to my computer.” … I’m going to guess that’s not what you’re trying to do.
I use Node to run individual scripts, directly. I do not have Node running all the time on any of my computers as a permanent “always on” webserver.
This is my first foray into the land of node and i’m beyond being newbie.
I was looking at the directions here: https://github.com/Danovadia/lgtv-http-server
I was hoping to have the ability to call a single URL that would allow me to turn off the LG TV, anything beyond that would be gravy. The WOL packet works for turning the LG on.
So I don’t use Node for much either (this is the only thing I’ve ever done with it), and after reading further right now I think my understanding of NPM (as I posted a few minutes ago) is incorrect. I suggest you ignore that
Perhaps someone else with more experience can help out here