yeelight.io

1.1.7 • Public • Published

yeelight.io

NPM version NPM downloads

Description

yeelight.io is a simple library for you to control YeeLight LED bulb through LAN.

Installation

npm install yeelight.io

Usage

Using Bulb type

'use strict';

const { Bulb } = require('yeelight.io');

const l1 = new Bulb('192.168.1.227');

l1.on('connected', (light) => {
  console.log(`connected to ${light.ip}`);
  light.toggle();
  light.disconnect();
});

l1.on('disconnected', (light) => {
  console.log(`disconnected with ${light.ip}`);
});

l1.on('error', (light, err) => {
  console.error(`error [${err.message}] occur on ${light.ip}`);
  light.disconnect();

});

l1.connect();

Using pre-implement methods

'use strict';

const { toggle } = require('yeelight.io');

toggle('192.168.1.227', (err) => {
  if (err) {
    console.error(`error [${err.message}] occured on 192.168.10.227`);
  } else {
    console.log('toggle 192.168.1.227 success');
  }
});

API


Bulb(ip, [port])

Create a new Bulb object

Properties:

Methods:

Events:


instance.connected

Yeelight bulb connection state

const l1 = new Bulb(IP_STR);

if (l1.connected) {
  l1.toggle()
}

instance.connect()

Start connecting to Yeelight bulb

const l1 = new Bulb(IP_STR);

l1.connect();

Instance.toggle()

Toggle a Yeelight bulb

const l1 = new Bulb(IP_STR);

...

l1.toggle();

Instance.onn()

Turn on a Yeelight bulb. NOTE: onn on purpose to avoid same name with event on

const l1 = new Bulb(IP_STR);

...

l1.onn();

Instance.off()

Turn off a Yeelight bulb

const l1 = new Bulb(IP_STR);

...

l1.off();

Instance.brightness(level)

Change brightness of a Yeelight bulb

const l1 = new Bulb(IP_STR);

...

l1.brightness(50); // Turn brightness to half

Instance.color(r, g, b)

Change color of a Yeelight bulb

const l1 = new Bulb(IP_STR);

...

l1.color(255, 0, 0); // Turn bulb to red

Instance.getProps()

Retrieve properties from a Yeelight bulb, current support properties

  • power
  • bright
  • ct
  • rgb
  • hue
  • sat
  • color_mode
  • flowing
  • delayoff
  • flow_params
  • music_on
  • name
  • bg_power
  • bg_flowing
  • bg_flow_params
  • bg_ct
  • bg_lmode
  • bg_bright
  • bg_rgb
  • bg_hue
  • bg_sat
  • nl_b
const l1 = new Bulb(IP_STR);

...

l1.on('props', () => {
  console.log(l1.props)
  // {
  //    power: 'on',
  //    bright: '50',
  //    ct: '4357',
  //    rgb: '16711680',
  //    hue: '0',
  //    sat: '100',
  //    color_mode: '2',
  //    flowing: '0',
  //    delayoff: '0',
  //    flow_params: '0,0,1000,1,16776960,100,1000,1,65280,100,1000,1,16744192,100,1000,1,255,100',
  //    music_on: '0',
  //    name: '',
  //    bg_power: '',
  //    bg_flowing: '',
  //    bg_flow_params: '',
  //    bg_ct: '',
  //    bg_lmode: '',
  //    bg_bright: '',
  //    bg_rgb: '',
  //    bg_hue: '',
  //    bg_sat: '',
  //    nl_br: ''
  //  }
}
})

l1.getProps(); // Get bulb properties

Event: 'connected'

Emit when connected with Yeelight bulb

  • light <Bulb> bulb that is connected

Event: 'disconnected'

Emit when disconnected with Yeelight bulb

  • light <Bulb> bulb that is disconnected

Event: 'error'

Emit when any kind of error occured

  • light <Bulb>
  • err <Error>

Event: 'data'

Emit when Yeelight bulb sends response

  • light <Bulb>
  • data <object>

toggle(ip, [cb(err)])

Toggle a Yeelight bulb

  • ip <string> eelight bulb IP address
  • cb(err) <Function> called after toggle command is sent to the bulb, err <Error> not null if error occured

on(ip, [cb(err)])

Turn on a Yeelight bulb

  • ip <string> eelight bulb IP address
  • cb(err) <Function> called after toggle command is sent to the bulb, err <Error> not null if error occured

off(ip, [cb(err)])

Turn off a Yeelight bulb

  • ip <string> eelight bulb IP address
  • cb(err) <Function> called after toggle command is sent to the bulb, err <Error> not null if error occured

brightness(ip, level, [cb(err)])

Change brightness of a Yeelight bulb

  • ip <string> eelight bulb IP address
  • level <number> brightness level, 0 ~ 255
  • cb(err) <Function> called after toggle command is sent to the bulb, err <Error> not null if error occured

color(ip, r, g, b[cb(err)])

Change color of a Yeelight bulb

  • ip <string> eelight bulb IP address
  • r <number> red of RGB, 0 ~ 255
  • g <number> green of RGB, 0 ~ 255
  • b <number> blue of RGB, 0 ~ 255
  • cb(err) <Function> called after toggle command is sent to the bulb, err <Error> not null if error occured

License

MIT

Dependencies (0)

    Dev Dependencies (6)

    Package Sidebar

    Install

    npm i yeelight.io

    Weekly Downloads

    4

    Version

    1.1.7

    License

    MIT

    Unpacked Size

    15.4 kB

    Total Files

    12

    Last publish

    Collaborators

    • tonylin0826