YeelightPro 2.4.0

dotnet add package YeelightPro --version 2.4.0
                    
NuGet\Install-Package YeelightPro -Version 2.4.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="YeelightPro" Version="2.4.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="YeelightPro" Version="2.4.0" />
                    
Directory.Packages.props
<PackageReference Include="YeelightPro" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add YeelightPro --version 2.4.0
                    
#r "nuget: YeelightPro, 2.4.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package YeelightPro@2.4.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=YeelightPro&version=2.4.0
                    
Install as a Cake Addin
#tool nuget:?package=YeelightPro&version=2.4.0
                    
Install as a Cake Tool

YeelightPro 局域网本地控制

[个人根据官方局域网通讯协议协议开发,非官方库]

Yeelight Pro照明控制系统由硬件、云端、用户App组成。硬件包括网关、灯具、传感器、面板、全面屏等组成。网关通过蓝牙MESH协议与其他蓝牙mesh子设备进行通信,通过Wi-Fi或者有线与云端/本地服务器通信。

本库通过 局域网协议(Ver2.4)与 S21/S21增强版 网关进行本地通讯控制以上描述设备,相关可控制设备详见: https://cn.yeelight.com/zh_CN/pro

(特别说明:非 Yeelight 普通线上产品控制库,也就是连接米家的那些设备,无法使用本库控制。)

基本使用方法

设备初始化

       
        private Gateway _gateway;
        _gateway = new Gateway("192.168.0.0");
        //连接记录
        _gateway.CommunicationRecord += (_, r) =>
        {
            //r:GatewayCommunicationRecordEventArgs
        };
        //连接改变事件
        _gateway.ConnectChanged += async (_, e) =>
        {
            //重连操作
            if (!e.Connected)
            {
                while (true)
                {
                    //等待10S
                    await Task.Delay(10000);
                    try
                    {
                        _gateway.Connect();
                        return;
                    }
                    catch (YeelightPro.GatewayRepeatedConnectException ex)
                    {
                             //重复连接 说明已经连接上了
                             //      return;
                    }
                    catch (Exception ex)
                    {
                        //其他则是连接失败
                    }
                }
            }
        };
        //设备事件触发事件
        _gateway.EventTriggered += Gateway_EventTriggered;
        //设备属性变化事件
        _gateway.PropertiesUpdated += _gateway_PropertiesUpdated;
        //连接
        _gateway.Connect();

控制设备

//控制单元分为 属性控制 和行为控制

//属性控制举例:构建控制灯具类设备命令

var lightCmd=new GatewayCommandModel()
{
    //节点设备ID 
    Id=id,
    //期待设置的属性和⽬标值
    Set=new()
    {
        //从 GatewayNodeDeviceProperties 选择属性名称,属性注释上表明了 操作包含 ‘写’ 的是属于可控的,并且标标明了相关类型可范围
       { GatewayNodeDeviceProperties.Light_Power, true }, //开灯
       { GatewayNodeDeviceProperties.Light_Brightness, 50} //50%的亮度
    },
    //渐变事件 单位 毫秒
    Duration=2000
};



//行为举例:构建控制床帘类设备命令
var curtainCmd=new GatewayCommandModel()
{
    //节点设备ID 
    Id=id,
    //行为动作
    Action=new GatewayCommandActionModel()
    {
        //调整窗帘电机动作
        MotorAdjust =new GatewayCommandActionMotorAdjustModel()
        {
            //选择 GatewayCommandActionMotorAdjustModel 里面的常量字段
            Type=GatewayCommandActionMotorAdjustModel.Auto
        }
    }
}

//通过命令组进行命令控制执行
(bool executed, string? msg)=await _gateway.CommandAsync([lightCmd,curtainCmd]);

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.4.0 139 7/8/2025