Skip to content
/ lgtv.js Public
forked from msloth/lgtv.js

Control LG TV(WebOS) using node.js or CLI

License

Notifications You must be signed in to change notification settings

blia/lgtv.js

 
 

Repository files navigation

LGTV

Installation

npm install @w4f/lgtv and set up the TV per below.

Discovering the TV

const { discover } = require('@w4f/lgtv');
discover(2000).then(tvInfo => {
  console.log(tvInfo);
});

Connecting to the TV

const { connect } = require('@w4f/lgtv');
connect(address).then(tv => {
  console.log(tv);
});

Sending a command

const { discover, connect, commands } = require('@w4f/lgtv');
const { setVolume } = commands;

async function run() {
  let { address } = await discover(2000);
  let tv = await connect(address);

  await tv.send(setVolume(15));
  tv.disconnect();
}

run();

Subscribing to events

const { discover, connect, commands } = require('@w4f/lgtv');
const { getVolume } = commands;

function listener({ payload }) {
  const { changed, action, muted, volume } = payload;
  if (typeof changed === 'undefined' || action !== 'changed') {
    return;
  }
  if (changed.includes('muted')) {
    console.log('Muted', muted);
  }
  if (changed.includes('volume')) {
    console.log('Volume', volume);
  }
}
async function run() {
  let { address } = await discover(2000);
  let tv = await connect(address);
  let unsubscribe = await tv.send(getVolume(listener));
}

run();

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%