项目作者: OllieDay

项目描述 :
Library for controlling Xiaomi Yeelight Smart LED Bulb
高级语言: F#
项目地址: git://github.com/OllieDay/Yeelight.git
创建时间: 2018-03-24T10:09:59Z
项目社区:https://github.com/OllieDay/Yeelight

开源协议:BSD 3-Clause "New" or "Revised" License

下载


Yeelight

Library for controlling Xiaomi Yeelight Smart LED Bulb.

Getting started

Install the NuGet package into your application.

Package Manager

  1. Install-Package Yeelight

.NET CLI

  1. dotnet add package Yeelight

Usage

All functions take an IPAddress for the target light.

  1. let address = IPAddress.Parse "192.168.0.x"

Many functions take an Effect that determines the behaviour of an operation.

  1. type Effect =
  2. // Instantaneous with no delay
  3. | Sudden
  4. // Gradual with the specified duration in milliseconds
  5. | Smooth of uint32

All functions return a Response with the value Ok for a successful request, or an Error that contains a message.

  1. type Response = Ok | Error of string

Power

  1. type Power = Off | On
  1. // Set power
  2. address |> Yeelight.setPower Yeelight.Off Yeelight.Sudden
  3. address |> Yeelight.setPower Yeelight.On Yeelight.Sudden
  4. // Switch off and on
  5. address |> Yeelight.off Yeelight.Sudden
  6. address |> Yeelight.on Yeelight.Sudden
  7. // Toggle off and on
  8. address |> Yeelight.toggle

Brightness

  1. // Percentage: 1 - 100
  2. type Brightness = int
  1. // Set brightness to 50%
  2. address |> Yeelight.setBrightness 50 Yeelight.Sudden

Temperature

  1. // Kelvin: 1700 - 6500
  2. type Temperature = int
  1. // Set temperature to 3500 K
  2. address |> Yeelight.setTemperature 3500 Yeelight.Sudden

Color

Color can be set using either RGB or HSV.

  1. // 0 - 255
  2. type Red = int
  3. type Green = int
  4. type Blue = int
  5. // 0 - 359
  6. type Hue = int
  7. // 0 - 100
  8. type Saturation = int
  9. type Color =
  10. // Triple of red, green, blue
  11. | Rgb of Red * Green * Blue
  12. // Tuple of hue, saturation
  13. | Hsv of Hue * Saturation
  1. // Set color to red = 255, green = 0, blue = 127
  2. address |> Yeelight.setColor (Yeelight.Rgb (255, 0, 127)) Yeelight.Sudden
  3. // Set color to hue = 180, saturation = 50
  4. address |> Yeelight.setColor (Yeelight.Hsv (180, 50)) Yeelight.Sudden

Name

  1. type Name = string
  1. // Set name to "Bedroom"
  2. address |> Yeelight.setName "Bedroom"

Note: When using the Yeelight official app, the device name is stored in the cloud. This method instead stores the name in device’s persistent memory, so the two names may differ.