npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

yeelight.io

v1.1.7

Published

Yeelight Control for node

Downloads

21

Readme

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])
  • on(ip, [cb(err)])
  • off(ip, [cb(err)])
  • brightness(ip, [cb(err)])
  • color(ip, [cb(err)]

Bulb(ip, [port])

Create a new Bulb object

Properties:

  • connected

Methods:

  • connect()
  • toggle()
  • onn()
  • off()
  • brightness(level)
  • color(r, g, b)
  • getProps()

Events:

  • Event: 'connected'
  • Event: 'disconnected'
  • Event: 'error'
  • Event: 'data'

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