yeelight.io v1.1.7
yeelight.io
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 addresscb(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 addresscb(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 addresscb(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 addresslevel
<number>
brightness level, 0 ~ 255cb(err)
<Function>
called after toggle command is sent to the bulb,err
<Error>
not null if error occured
color(ip, r, g, bcb(err))
Change color of a Yeelight bulb
ip
<string>
eelight bulb IP addressr
<number>
red of RGB, 0 ~ 255g
<number>
green of RGB, 0 ~ 255b
<number>
blue of RGB, 0 ~ 255cb(err)
<Function>
called after toggle command is sent to the bulb,err
<Error>
not null if error occured
License
MIT