GithubHelp home page GithubHelp logo

node-yeelight-wifi's Introduction

node-yeelight-wifi

"node-yeelight-wifi" is a node.js lib for controlling via wifi connected Yeelights.

It works with the RGBW bulbs, white bulbs and ceiling lights.

You need to activate "Lan control" on your lights. (see Troubleshooting)

Installation

npm install --save node-yeelight-wifi

Howto

Yeelight Lookup

You can lookup for yeelights in your local network like this:

const Lookup = require("node-yeelight-wifi").Lookup;

let look = new Lookup();

look.on("detected",(light) =>
{
    console.log("new yeelight detected: id="+light.id + " name="+light.name);
});

Methods

Once you have a Yeelight (light) object from a lookup you can use it like this:

setPower(power,duration)

Set the power of your Yeelight (on: true, off: false)

light.setPower(true).then(() =>
{
    console.log("success");
}).catch((error =>
{
    console.log("failed",error);
}));

setRGB(rgb,duration)

Set the RGB value (r: 0-255, g: 0-255, b: 0-255)

light.setRGB([255,255,0]).then(() =>
{
    console.log("success");
}).catch((error =>
{
    console.log("failed",error);
}));

setHSV(hsv,duration)

Set the HSV value (hue: 0-359, sat: 0-100, value/bright=0-100)

light.setHSV([180,70,100]).then(() =>
{
    console.log("success");
}).catch((error =>
{
    console.log("failed",error);
}));

setCT(hsv,duration)

Set the color temp value (1700 ~ 6500)

light.setCT(5000).then(() =>
{
    console.log("success");
}).catch((error =>
{
    console.log("failed",error);
}));

setBright(brightness,duration)

Set the color brightness (0-100)

light.setBright(80).then(() =>
{
    console.log("success");
}).catch((error =>
{
    console.log("failed",error);
}));

updateState()

If you want to request a state (color,bright,power) update

light.updateState().then(() =>
{
    console.log("success");
    console.log(light.rgb);
}).catch((error =>
{
    console.log("failed",error);
}));

Usable (public) Members of Yeelight-Class (read only)

  • light.power (true/false)
  • light.type ("unknown","white","color")
  • light.bright (0-100)
  • light.rgb (example: {r: 0, g: 0, b: 0})
  • light.hsb (example: {h: 0, s: 0, b: 0})

Events

A Yeelight instance has some events:

//socket connect and disconnect events
light.on("connected",() =>{ console.log("connected"); });
light.on("disconnected",() => { console.log("disconnected"); });

//if the color or power state has changed
light.on("stateUpdate",(light) => { console.log(light.rgb); });

//if something went wrong
light.on("failed",(error) => { console.log(error); });

Examples

  • see examples/examples.js

Troubleshooting

Licence

Copyright (c) Bastian Karge

MIT (see License.md)

node-yeelight-wifi's People

Contributors

bastl34 avatar igorclaudino avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-yeelight-wifi's Issues

Allow use of async / await

Hello. I think with the new ES5 / 6 updates, it would be interesting to use async / await. What do you think? I can work in a PR for this.

Yeelight bulb not dtecteed

I have powered on the bulb and started the discovery code, bulb not detected
Any other thing to add up?

code I tried

const Lookup = require("node-yeelight-wifi").Lookup;

let look = new Lookup();

look.on("detected",(light) =>
{
console.log("new yeelight detected: id="+light.id + " name="+light.name);
});

search/discovery timeout?

Is it possible to have a discovery timeout after a period of time? Currently, it is a forever loop.

Feature Request: Update event to indicate actual status change

First of thank you very for your effort in make this project available. I am using it since a couple of days now and it is working fine for me. However, I have an issue with respect to status update events.

The stateUpdate event only provides the Yeelight object with all its members, but it does not indicate which property has changed which can have some strange side-effect with some applications which represent the actual state of light. In particular, this is a problematic on first connect as the state is incomplete at this point as can be seen in the following example:

{ type: 'unknown',
  power: false,
  bright: 0,
  rgb: { r: 0, g: 0, b: 0 },
  hsb: { h: 0, s: 0, b: 0 } }
{ type: 'color',
  power: true,
  bright: 0,
  rgb: { r: 0, g: 0, b: 0 },
  hsb: { h: 0, s: 0, b: 0 } }
{ type: 'color',
  power: true,
  bright: 100,
  rgb: { r: 255, g: 255, b: 255 },
  hsb: { h: 0, s: 0, b: 100 } }

As one can see the first two states are incomplete

My question: Is it possible to suppress the first events (the first one might be easy for me to ignore as the type is unknown) until the bulb state is complete? Another approach might be to have status update event which contain the actual state property changed rather than the full object.

What do you think? I am happy to come up with PR based on your thoughts on the matter.

Allow sendCommand with empty params

Some of the api methods aren' t implemented.

Since it is possible to call the sendCommand function, it would be nice, if you can call the function without params.

In order to keep the stability, the parameters could be checked in the implemented function and not in the sendCommand function.
For instance the setRGB method requires prameters. Therefore setRGB should verify the parameters and pass them to the setCommand function.

This would allow to use api functionality that isn' t implemented in this module. e.g. "toggle"

Another option would be to explicitly tell the sendCommand function, that you want to call it without parameters.
e.g.:

setCommand('toggle', {
  params: [],
  allowEmptyParams: true
})

But this would be a breaking change.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.