YeelightAPI 1.1.5
See the version list below for details.
dotnet add package YeelightAPI --version 1.1.5
NuGet\Install-Package YeelightAPI -Version 1.1.5
<PackageReference Include="YeelightAPI" Version="1.1.5" />
paket add YeelightAPI --version 1.1.5
#r "nuget: YeelightAPI, 1.1.5"
// Install YeelightAPI as a Cake Addin #addin nuget:?package=YeelightAPI&version=1.1.5 // Install YeelightAPI as a Cake Tool #tool nuget:?package=YeelightAPI&version=1.1.5
YeelightAPI
C# API (.Net) to control Xiaomi Yeelight Color Bulbs
Prerequisites
The console project uses C# 7.1 "Async Main Method" Feature, make sure your visual studio version is up to date !
Installation
To install the latest release from NuGet package manager:
Install-Package YeelightAPI
Contribution
If you find this package useful, please make a gift on Paypal : https://www.paypal.me/roddone
Usage
Single Device
The YeelightAPI.Device
allows you to create a device. Just instanciate a new Device with an ip adress or a hostname: Device device = new Device("hos.tna.meo.rIP");
and initiate connection : device.Connect();
.
Then you can use the device object to control the device :
- Power on / off :
device.SetPower(true);
- Toggle State :
device.Toggle();
- Change brightness level :
device.SetBrightness(100);
- Change color :
device.SetRGBColor(80, 244, 255);
- ...
Some methods use an optional parameter named "smooth", it refers to the duration in milliseconds of the effect you want to apply. For a progressive brightness change, use device.SetBrightness(100, 3000);
.
If you need a method that is not implemented, you can use the folowing methods :
ExecuteCommandWithResponse(METHODS method, int id = 0, List<object> parameters = null)
(with response)ExecuteCommand(METHODS method, int id = 0, List<object> parameters = null)
(without response).
These methods are generic and use the METHODS
enumeration and a list of parameters, which allows you to call any known method with any parameter.
All the parameters are defined in the doc "Yeelight WiFi Light Inter-Operation Specification", section 4.1 : COMMAND Message.
Multiple-devices
If you need to control multiple devices at a time, you can use the YeelightAPI.DeviceGroup
class.
This class simply ihnerits from native .net List<Device>
and implements the IDeviceController
interface, allowing you to control multiple devices the exact same way you control a single device.
DeviceGroup group = new DeviceGroup();
group.Add(device1);
group.Add(device2);
group.Connect();
group.Toggle();
...
Color Flow
You can create a Color Flow to "program" your device with different state changes. Changes can be : RGB color, color temperature and brightness.
Just create a new ColorFlow()
, add some new ColorFlowExpression()
to it, and starts the color flow with your ColorFlow object.
ColorFlow flow = new ColorFlow(0, ColorFlowEndAction.Restore);
flow.Add(new ColorFlowRGBExpression(255, 0, 0, 1, 500)); // color : red / brightness : 1% / duration : 500
flow.Add(new ColorFlowRGBExpression(0, 255, 0, 100, 500)); // color : green / brightness : 100% / duration : 500
flow.Add(new ColorFlowRGBExpression(0, 0, 255, 50, 500)); // color : blue / brightness : 50% / duration : 500
flow.Add(new ColorFlowSleepExpression(2000)); // sleeps for 2 seconds
flow.Add(new ColorFlowTemperatureExpression(2700, 100, 500)); // color temperature : 2700k / brightness : 100 / duration : 500
flow.Add(new ColorFlowTemperatureExpression(5000, 1, 500)); // color temperature : 5000k / brightness : 100 / duration : 500
device.StartColorFlow(flow); // start
/* Do Some amazing stuff ... */
device.StopColorFlow(); // stop the color flow
The ColorFlow
constructor has 2 parameters : the first one defines the number of repetitions (or 0 for infinite), the second one defines what to do when the flow is stopped. you can choose to restore to the previous state, keep the last state or turn off the device.
Find devices
If you want to find what devices are connected, you can use YeelightAPI.DeviceLocator
to find them :
List<Device> devices = await DeviceLocator.Discover();
Async / Await
If you have to deal with asynchronism, the API fully supports async / await. The methos are the same, but they have a "Async" suffix. Example :
// with single device
await device.Connect();
await device.Toggle();
//with groups
await group.Connect();
await group.Toggle();
...
Events
Notifications
When you call a method that changes the state of the device, it sends a notification to inform that its state really change. You can receive these notification using the "OnNotificationReceived" event. Example :
device.OnNotificationReceived += (object sender, NotificationReceivedEventArgs arg) =>
{
Console.WriteLine("Notification received !! value : " + JsonConvert.SerializeObject(arg.Result));
};
Errors
When a method returns an error, it fires a "OnCommandError" event. Example :
device.OnCommandError += (object sender, CommandErrorEventArgs arg) =>
{
Console.WriteLine($"An error occurred : {arg.Error}");
};
VNext
turn into a nuget packagehandle dns host name for bulb discoveryadd device discovery method in the DeviceManager- add more native methods in the DeviceManager
full use of async / awaitallow to group devices to control multiple devices- correct bugs if needed
Help
If there is a functionality that you need which is not implemented, or even worse if there is a bug, you can create a pull request or contacts me at "romain.oddone.github@outlook.com"
Licence
Apache Licence
Source
This code is an implementation of the "Yeelight WiFi Light Inter-Operation Specification" as defined on January 1st, 2018
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net46 is compatible. net461 was computed. net462 was computed. net463 was computed. net47 is compatible. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.6
- Newtonsoft.Json (>= 10.0.3)
- System.Net.NetworkInformation (>= 4.3.0)
-
.NETFramework 4.7
- Newtonsoft.Json (>= 10.0.3)
- System.Net.NetworkInformation (>= 4.3.0)
-
.NETStandard 2.0
- Newtonsoft.Json (>= 10.0.3)
- System.Net.NetworkInformation (>= 4.3.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories (2)
Showing the top 2 popular GitHub repositories that depend on YeelightAPI:
Repository | Stars |
---|---|
RonSijm/ButtFish
Effortlessly transmitting Morse Code of chess moves to your butthole 💝
|
|
isaacrlevin/presencelight
PresenceLight is a solution to broadcast your various statuses to light bulbs.
|
Version | Downloads | Last updated |
---|---|---|
1.11.0-beta-CI-20221212-082524 | 214 | 12/12/2022 |
1.10.2 | 12,984 | 3/21/2021 |
1.10.1 | 1,433 | 2/8/2021 |
1.10.0 | 2,469 | 12/28/2020 |
1.9.0 | 3,879 | 8/11/2020 |
1.8.0 | 1,150 | 7/1/2020 |
1.7.0 | 1,456 | 12/15/2019 |
1.6.0 | 534 | 12/7/2019 |
1.5.2 | 673 | 10/14/2019 |
1.5.1 | 534 | 10/10/2019 |
1.5.0 | 2,510 | 8/25/2018 |
1.4.1 | 839 | 8/7/2018 |
1.4.0 | 1,072 | 7/13/2018 |
1.3.3 | 1,038 | 4/29/2018 |
1.3.2 | 863 | 4/3/2018 |
1.3.1 | 963 | 3/22/2018 |
1.3.0 | 953 | 3/5/2018 |
1.2.3 | 950 | 2/25/2018 |
1.2.2 | 958 | 2/22/2018 |
1.2.1 | 1,045 | 2/15/2018 |
1.2.0 | 981 | 2/15/2018 |
1.1.5 | 996 | 2/9/2018 |
1.1.4 | 942 | 2/7/2018 |
1.1.3 | 930 | 2/4/2018 |
1.1.2 | 863 | 1/28/2018 |
1.1.1 | 858 | 1/28/2018 |
1.1.0 | 961 | 1/27/2018 |
1.0.6 | 996 | 1/7/2018 |
1.0.5 | 1,091 | 1/7/2018 |
1.0.4 | 1,040 | 1/6/2018 |
1.0.2 | 1,005 | 1/3/2018 |
1.0.1 | 977 | 1/3/2018 |
1.0.0 | 992 | 1/3/2018 |
Add Color Flow