Dart library for controlling Yeelight products over LAN.
More info about Yeelight API:
- https://www.yeelight.com/en_US/developer
- https://www.yeelight.com/download/Yeelight_Inter-Operation_Spec.pdf
- Depend on it
Run this command:
With dart:
$ dart pub add yeedart
With flutter:
$ flutter pub add yeedart
This will add a line like this to your package's pubspec.yaml (and run an implicit dart pub get
/flutter pub get
):
dependencies:
yeedart: ^0.3.2
- Import it
Now in your Dart code, you can use:
import 'package:yeedart/yeedart.dart';
First of all, you need to know your device's IP address and port.
You can use Yeelight.discover()
method which returns list of DiscoveryResponse
.
final responses = await Yeelight.discover();
final response = responses.first; // or filter..
Each response contains IP address and port for given device and other properties (name, firmware version, current state,...).
ℹ️ You can also specify timeout for discovery. Default is 2 seconds.
Note that for device discovery to properly work on Android, you at least need the
INTERNET
permission granted.
final device = Device(
address: InternetAddress("192.168.1.183"),
port: 55443,
);
await device.turnOn(); // turn the device on
// set red color with smooth transition
await device.setRGB(
color: Colors.red,
effect: const Effect.smooth(),
duration: const Duration(milliseconds: 500),
);
await device.setBrightness(brightness: 70); // set brightness to 70 %
device.disconnect(); // always disconnect when you are done!
Command
, new TCP connection will be created automatically.
This single TCP connection is then used for another command(s). But when you are done,
you should close the connection.
ℹ️ Note that when you call device.disconnect()
and then call
for example device.turnOff()
, new TCP connection will be created automatically.
ℹ️ If you don't want to send any command and just listen on the notificationMessageStream
, use the device.connect()
to create a connection manually.
ℹ️ Also note that Yeelight connections are rate-limited to 60 per minute.
Some devices can be equiped with two lights: main and background. Methods in Device
class control main light by default
(for example device.setRGB(color: Colors.red)
sets RGB color for main light. If you want to set RGB color for background light, you have to specify lightType
parameter: device.setRGB(color: Colors.red, lightType: LightType.backgroud);
.
You can also use LightType.both
but ONLY for toggling: device.toggle(lightType: LightType.both)
.
Flow (color flow) is basically a list of transitions. To start a flow use startFlow()
method and provide Flow
. Flow
has 3 required parameters:
- count - number of transitions to run, 0 for infinite loop. If you have 10 transitions and count is 5, it will run only first 5 transitions!
- action - specifies action to take after the flow ends.
FlowAction.stay
to stay at the last state when the flow is stopped.FlowAction.recover
to recover the state before the flow.FlowAction.turnOff
to turn off.
- transitions - list of
FlowTransition
,FlowTransition.rgb()
,FlowTransition.colorTemperature()
orFlowTransition.sleep()
.
Following example will loop red, green and blue colors at full brightness.
await device.startFlow(
flow: const Flow(
count: 0,
action: FlowAction.recover(),
transitions: [
FlowTransition.rgb(color: 0xff0000, brightness: 100),
FlowTransition.sleep(duration: Duration(milliseconds: 500)),
FlowTransition.rgb(color: 0x00ff00, brightness: 100),
FlowTransition.sleep(duration: Duration(milliseconds: 500)),
FlowTransition.rgb(color: 0x0000ff, brightness: 100),
FlowTransition.sleep(duration: Duration(milliseconds: 500)),
],
),
);
To manually stop flow, use device.stopFlow()
.
This library also includes some predefined flows:
Flow.rgb()
- changes color from red, to green to blueFlow.police
- changes red and blue color like police lights.Flow.pulse()
- creates pulse with given color
Scene allows you to set light to specific state. To use scene, use setScene()
method and provide Scene
.
You can use:
Scene.color()
orScene.hsv()
to set color and brightnessScene.colorTemperature
to set color temperature and brightnessScene.colorFlow()
to start a color FlowScene.autoDelayOff()
to turn on the device to specified brightness and start a timer to turn off the light after specified number of minutes.
Example:
device.setScene(scene: Scene.color(color: 0xff0000, brightness: 100));
Please file feature requests and bugs at the issue tracker.