Java API to connect and control Xiaomi Yeelight Bulb.
// There are two ways to connect to a Bulb:
// 1 - automatically discovers every bulb on the network, see doc to get more info
Collection<Bulb> bulbs = Bulb.discover(10 * 1000);
// 2 - specify Bulb ip to connect to
Bulb bulb = new Bulb("192.168.1.94");
// turns bulb on
bulb.turnOn();
// turns bulb off
bulb.turnOff();
// sets bulb's brightness to 100 (max)
bulb.setBrightness(100);
/* you can specify the method (and params) you want to run on the bulb
* this API does not implement every available methods
* (see Yeelight developer doc to know about available methods)
* so this method is useful because it let's you run any method. */
String method = "set_power";
Object[] params = new Object[]{"on", "smooth", 500};
bulb.runMethod(method, params);
-
You need to enable LAN control in order to allow 3rd party API's (like this one) to access and controll your device. See this site to set it up.
-
As already said in example of usage, this API does not implement every available methods, however there is an easy and elegant way to simplify method invocation. Using bulb.runMethod() you just need to specify the method using String and its parameteres using Object Array, internally it encapsulates command conversion to Yeelight's protocol and TCP socket writting. See official yeelight doc to know all available methods.
-
This API is directed to Bulb device however it works with all Yeelight devices, you can use bulb.runMethod() to invoke a specific method not implemented in this API. Note that in the current version Bulb.discover() method is Bulb specific.
This software is released into the public domain under The Unlicense.