Simple Node.js module to remote control LG WebOS smart TVs.
this is a fork of LGTV.js, heavily modified and rewritten to suite my needs.
With v1.4.0 the location and filename of the keyFile is changed, so you likely will have to accept the connection on your TV again after upgrading to 1.4.0.
- node-red-contrib-lgtv - Node-RED Nodes to control LG webOS Smart TVs.
- lgtv2mqtt - Interface between LG WebOS Smart TVs and MQTT.
- homebridge-webos-tv - Homebridge plugin for LG WebOS TVs.
- ioBroker.lgtv - LG WebOS SmartTV adapter for ioBroker.
npm install lgtv2
You need to allow "LG Connect Apps" on your TV - see http://www.lg.com/uk/support/product-help/CT00008334-1437131798537-others
Subscribe to volume and mute changes and output to console:
var lgtv = require("lgtv2")({
url: 'ws://lgwebostv:3000'
});
lgtv.on('error', function (err) {
console.log(err);
});
lgtv.on('connect', function () {
console.log('connected');
lgtv.subscribe('ssap://audio/getVolume', function (err, res) {
if (res.changed.indexOf('volume') !== -1) console.log('volume changed', res.volume);
if (res.changed.indexOf('muted') !== -1) console.log('mute changed', res.muted);
});
});
Turn TV off:
var lgtv = require("lgtv2")({
url: 'ws://lgwebostv:3000'
});
lgtv.on('error', function (err) {
console.log(err);
});
lgtv.on('connect', function () {
console.log('connected');
lgtv.request('ssap://system/turnOff', function (err, res) {
lgtv.disconnect();
});
});
- url - websocket url of TV. default: 'ws://lgwebostv:3000'
- timeout - request timeout in milliseconds, default: 15000
- reconnect - reconnect interval in milliseconds, default: 5000
- keyFile - path for key storage. Will be suffixed with hostname/ip of TV. default: Linux:
~/.lgtv2/keyfile-
, macOS:~/Library/Preferences/lgtv2/keyfile-
- saveKey - you can override this with your own function for saving the key
- clientKey - you have to supply the key here if you're using a custom saveKey method
Payload and callback params are optional.
Closes the connection to the TV and stops auto-reconnection.
Get specialized socket connection for mouse and button events
Example:
lgtv.getSocket(
'ssap://com.webos.service.networkinput/getPointerInputSocket',
function(err, sock) {
if (!err) {
sock.send('click');
}
}
);
is called when TV prompts for App authorization
is called when a connection is established and authorized
is called when trying to connect to the TV
is called when Websocket connection errors occur. Subsequent equal errors will only be emitted once (So your log isn't flooded with EHOSTUNREACH errors if your TV is off)
Enable/Disable mute
Example: lgtv.request('ssap://audio/setMute', {mute: true});
Example: lgtv.request('ssap://audio/setVolume', {volume: 10});
Example: lgtv.request('ssap://media.controls/play');
Example: lgtv.request('ssap://media.controls/pause');
Show a Popup Window.
Example: lgtv.request('ssap://system.notifications/createToast', {message: 'Hello World!'});
Start an app.
Example: lgtv.request('ssap://system.launcher/launch', {id: 'netflix'});
MIT (c) Sebastian Raff