yeelight

package module
v0.0.0-...-8201450 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 2, 2022 License: GPL-3.0 Imports: 11 Imported by: 1

README

go-yeelight

Simple Go interface to control your Yeelights. Yeelight technical documentation: https://www.yeelight.com/download/Yeelight_Inter-Operation_Spec.pdf

Tested on

  • Yeelight Lightstrip Plus (yeelight.light.strip2)
  • Yeelight Bulb Color 1S (yeelight.light.color4)

Features

  • Turn on
  • Turn off
  • Set color temperature
  • Set RGB color
  • Set brightness
  • Ask light is power on

Credits

This project is inspired from

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrDiscoverNoDeviceFound is returned when no device is found when discovering
	ErrDiscoverNoDeviceFound = errors.New("no device found")
)

Functions

This section is empty.

Types

type Method

type Method string

Method describes the method string to send to a yeelight device.

const (
	SetColorTemperatureABX Method = "set_ct_abx"
	SetRGB                 Method = "set_rgb"
	SetHSV                 Method = "set_hsv"
	SetBrightness          Method = "set_bright"
	SetPower               Method = "set_power"
	Toggle                 Method = "toggle"
	GetProp                Method = "get_prop"
	Props                  Method = "props"
	AdjustBrightness       Method = "adjust_bright"
	AdjustColorTemperature Method = "adjust_ct"
)

Currently supported commands

func (Method) String

func (m Method) String() string

type Notification

type Notification struct {
	Method Method            `json:"method"`
	Params map[string]string `json:"params"`
}

Notification describes a change on Yeelight

type Response

type Response struct {
	ID     int           `json:"id"`
	Result []interface{} `json:"result"`
	Error  *struct {
		Code    int    `json:"code"`
		Message string `json:"message"`
	} `json:"error"`
}

Response describes command response from a yeelight device

type Yeelight

type Yeelight interface {
	fmt.Stringer

	// On turns on the yeelight
	On() error

	// Off turns the yeelight
	Off() error

	// SetColorTemperature will set the yeelight color temperature
	SetColorTemperature(temperature int) error

	// SetRGB will set yeelight red, green and blue values
	SetRGB(red, green, blue uint8) error

	// SetBrightness will set the yeelight brightness.
	SetBrightness(brightness int) error

	// IsPowerOn return whether the yeelight is power on
	IsPowerOn() (bool, error)

	// Toggle on or off the Yeelight
	Toggle() error

	// Listen for events on current Yeelight
	Listen(ctx context.Context) (<-chan *Notification, error)

	// AdjustBrightness adjust the brightness by specified percentage within specified duration.
	// The percentage range is: (-100,100).
	// duration is in milliseconds and minimum is 30ms.
	AdjustBrightness(percentage int, duration int) error

	// AdjustColorTemperature adjust the color temperature by specified percentage within specified duration.
	// The percentage range is: (-100,100).
	// duration is in milliseconds and minimum is 30ms.
	AdjustColorTemperature(percentage int, duration int) error
}

Yeelight is a light device you want to control

func Discover

func Discover() (Yeelight, error)

Discover tries to discover a Yeelight on your local network

func New

func New(address string) (Yeelight, error)

New creates a new yeelight object.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL