This is a simple library that allows you to control the 15$ Xiaomi´s YeeLight WiFi RGB LED bulbs (real alternative to Phillips Hue) through your LAN.
So far only tested with the RGB version (v1) but maybe it works also with the white bulb and strips.
You need to enable “Lan Control” in the App.
Yeelight
More Features will be added soon!
The following code turns on the lamp and starts a custom colorflow
Version 1.0
First Upload
Version 1.2
added MusicMode
Version 1.3
control multiple Bulbs
Version 1.4
small improvements
Discover all Yeelight based Lights such Color, Mono (White), Strip, Bedside Lamp
So far only tested with the RGB version (v1) but maybe it works also with the white bulb and strips.
You need to enable “Lan Control” in the App.
Yeelight
- setPower (state As Boolean, transistion As Int)
Set the Bulbs state
state: switch the Bulb On or Off
trasition: Fading time - sendCommand (cmd As String)
Send the Raw Command
cmd: JSON string - setBrightness (value As Int, transistion As Int)
This method is used to change the brightness
value: target brightness from 0 to 100
trasition: Fading time - setRGB (color As Int, transistion As Int)
This method is used to change the color
color: target color from 0 to 16777215
trasition: Fading time - setColorFlow (count As Int, action As Int, expression As String)
This method is used to o start a color flow
count: total number of visible state changing before color flow stopped. 0 means infinite Loop.
action: is the action takenafter the flow Is stopped.
0 = State before the color flow started.
1 = Stay at the state when the flow Is stopped.
2 = turn off after the flow Is stopped.
expression: expression of the state changing series
Every state contains Duration, Mode, Value, Brightness
Duration = Gradual change time Or Sleep time, in milliseconds, minimum value 50.
Mode = 1 –color, 2 –color temperature, 7–Sleep.
Value = RGB value when mode is 1, CT value when mode is 2, Ignored when mode 7
Brightness= Brightness value, -1 Or 1 ~ 100.Ignored when mode Is 7.
When this value Is -1, brightness in this tuple Is ignored
(only color Or CT change takes effect) - stopColorFlow()
This method is used to stop a running color flow. - setDefault()
This method is used to save current state of smart LED in persistent memory.
So If user powers off And Then powers on the Bulb again (hard Power reset),
the Bulb will show last saved state. - Toggle()
This method is used to toggle the Bulbs power state. - setSleep (minutes As Int)
Switch the bulb off after X minutes. - setName (name As String)
This method is used to name the device.
The name will be stored on the device and
reported in discovering response. - stopSleep()
Stops the Sleeptimer - setKelvin (kelvin As Int, transistion As Int)
This method is used to change the color temperature
kelvin: target color temperature. Range Is 1700 ~ 6500 (k)
trasition: Fading time - setHSV (hue As Int, sat As Int, transistion As Int)
This method is used to change the color
hue: ranges from 0 to 359
sat: ranges from 0 to 100
trasition: Fading time - setMusicMode (active As Boolean)
This Mode puts the Bulb in Client mode and connects to the library TCP Serversocket
In this Mode no property will be reported and no message quota Is checked.
In Servermode(Musicmode Off) the bulb only accepts 144 comands per Minute (4 x 60 x 60%)
After set the Musicmode to True you can send any Command as usual. - Disconnect
Disconnects from the Bulb - Discover
Discover all Yeelights in your network
'he "discoverComplete" event will be raised when discover is finished
More Features will be added soon!
The following code turns on the lamp and starts a custom colorflow
B4X:
Sub Process_Globals
Private fx As JFX
Private MainForm As Form
Dim light As Yeelight
End Sub
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.RootPane.LoadLayout("main") 'Load the layout file.
MainForm.Show
light.Initialize(Me,"yee")
light.Connect("192.168.178.20")
End Sub
'Return true to allow the default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
Return True
End Sub
Sub yee_Connected(Successful As Boolean)
If Successful then
light.setPower(True,500)
light.setColorFlow(0,1,"1000,2,2700,100,500,1,255,10,5000,7,0,0,500,2,5000,1")
end if
End Sub
Sub yee_Response(Message As String)
Log(Message)
End Sub
Version 1.0
First Upload
Version 1.2
added MusicMode
Version 1.3
control multiple Bulbs
Version 1.4
small improvements
Discover all Yeelight based Lights such Color, Mono (White), Strip, Bedside Lamp
Attachments
Last edited: