Where do I get the YeeLight API?

I’m planning to develop an app, where do I get the API for yee light? Is there a guide on how to get started on developing with the api? Does the API include the searching and storing of light bulbs (e.g like a bulb lobby where I can conveniently display and get all light bulbs from)? Or do i have to code my own functions to search for the bulbs in the lan? I’ve read through the documentations and only see the function names and their params but how do i actually get the api?

I have exactly what I wanna implement to the bulbs just that if the API requires me to also do networking stuffs (which I’ve no clue) it could be hard for me to implement my stuffs in.

Would be great if this API has all the necessary networking stuffs done, and all I have to do is to get a list of all light bulbs and their variables exposed through a list/array

Sorry for being unhelpful to your inquiry,but I’d like to ask what that app is about

Sure, the app is to add a music mode similar to that of phillips hue’s disco mode. Allowing the lights to be controlled by the computer’s sound card output/audio spectrum. This way I’d be able to assign various frequencies to each bulbs or possibly a group of bulbs and they’ll all be able to light up based on the frequencies instead of the current one which lights up based on the microphone’s input. (all the bulbs reacts to the same frequency / in synchronization which is really boring).

If there’s an app similar to what I’m looking for already or currently in development, please let me know else I’ll have to try making one myself if I can figure out how to use the api/get the control of the bulbs into my source. If all else fails my last resort would be to get the overpriced* phillips hues.

No app I’ve heard of unfortunately,but the concept sounds interesting,I’d like to see that in action

Same here. If the api provides and handles the connections of the light bulbs I’ll be able to at least attempt to integrate my code in. It would be even better if the yeelight developers provide a source with a user interface template of the networking portion/light bulb lobby (fully working), and all the potential developers would have to do is to add their own features onto it.

Perhaps a video or a step by step guide on how to get the bulbs using the commands may help.

Any info on the api at all? In the windows demo I see all these

but QtNetwork and the other includes are no where to be found in the folder.I’m opening this demo in visual studio and also unable to compile. What editor or preset should i use in visual studio?

I’ve gotten to the part where I can find the bulb, how do I store the bulb for control usage?

Basically how do I do the following?
Can you provide a sample code to do the following:

  1. Parses and validate the response message.
  2. Identify the device, check if the device is already maintained in local storage by
    searching local database by ID.
  3. Display the status to user if necessary.
  4. Follow the information in “LOCATION” header to establish a TCP connection with the
    WiFi smart LED.
  5. After the TCP connection is successfully established, send control message to control
    the smart LED or monitor the status change of the device and display any change to user.

Can you provide a sample code for this?

Here’s what I’m using so far to search and detect the bulb, jus put it in a main class and add the necessary includes

       IPAddress multicastaddress = IPAddress.Parse("");
        UdpClient udpclient = new UdpClient();
        IPEndPoint remoteep = new IPEndPoint(multicastaddress, 1982);
        string ssdpMessage = "M-SEARCH * HTTP/1.1\r\nHOST:\r\nMAN: \"ssdp:discover\"\r\nST: wifi_bulb";


        byte[] buffer = Encoding.ASCII.GetBytes(ssdpMessage);
        udpclient.Send(buffer, buffer.Length, remoteep);

        IPEndPoint AnyEndPoint = new IPEndPoint(IPAddress.Any, 0);

        while (true)
            Byte[] data = udpclient.Receive(ref AnyEndPoint);
            string strData = Encoding.ASCII.GetString(data);

Any help please? I’ve been trying to figure how to get the following:

Cache-Control: max-age=3600
Location: yeelight://
NTS: ssdp:alive
Server: POSIX, UPnP/1.0 YGLC/1
id: 0x000000000015243f
model: color
fw_ver: 18
support: get_prop set_default set_power toggle set_bright start_cf stop_cf set_scene
cron_add cron_get cron_del set_ct_abx set_rgb
power: on
bright: 100
color_mode: 2
ct: 4000
rgb: 16711680
hue: 100
sat: 35
name: my_bulb

to display but failed. The documentation isn’t really helpful. If i can get pass the issue of storing the bulbs and setting the brightness to whatever’s in my code, I would be able to progress and begin adding my music analyzer stuffs in. You guys should at least provide a sample code to show how exactly to retrieve the bulbs and store it in a variable… This way it would be so much easier to begin implementing stuffs in…

The spec is pretty clear, but storing and controlling is implementation specific, if you find it’s hard for you, you could google some sample code or library.

I tried googling but couldn’t find the answer I’m looking for so i’m asking here since you guys are the developers… thanks anyway for the helpful comment

Sorry, we only provide spec, but not implementation.

I have an app written in php to control the Yeelight color bulb. The app is based on the Qingdao Yeelink specification. I run it on the Raspberry-Pi. It will run on anything that supports current versions of PHP. It will do things with your light bulb not possible with the phone app.


Here is some Python code to get the first bulb that responds to a search and calls various functions on it:

# Copyright Jan Newmarch
# Berkeley license
import struct
import re
import json

SRC_PORT = 5159 # my random port

CR_LF = "\r\n"

def get_ip_port():
  sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
  sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 2)
  sock.bind(('', SRC_PORT))
  sock.sendto("M-SEARCH * HTTP/1.1\r\n\
  MAN: \"ssdp:discover\"\r\n\
  ST: wifi_bulb\r\n", (MCAST_GRP, MCAST_PORT))

  sock_recv = socket.socket(socket.AF_INET, socket.SOCK_DGRAM,
  # ensure this socket is listening on the same
  # port as the multicast went on
  sock_recv.bind(('', SRC_PORT))
  response = sock_recv.recv(10240)

  # match on a line like "Location: yeelight://"
  # to pull ip out of group(1), port out of group(2)
  prog = re.compile("Location: yeelight://(\d*\.\d*\.\d*\.\d*):(\d*).*")
  for line in response.splitlines():
    result = prog.match(line)
    if result != None:
      ip = result.group(1)
      port = result.group(2)
      return (ip, int(port))
  return (None, None)

def sendto(ip, port, command):
  sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_TCP)
  sock.connect((ip, port))
  sock.send(command + CR_LF)
  response = sock.recv(10240)

  # the response is a JSON string, parse it and return
  # the "result" field
  dict = json.loads(response)
  #print "Response was ", response

def get_prop(prop, ip, port):
  # hard code the JSON string
  command = '{"id":1,"method":"get_prop","params":["' + prop + '"]}'
  response = sendto(ip, port, command)
  return response

def set_prop(prop, params, ip, port):
  # hard code the JSON string
  command = '{"id":1,"method":"set_' + prop +\
            '", "params":' + params +\
  response = sendto(ip, port, command)
  return response

def set_name(name, ip, port):
   params = '["' + name + '"]'
   response = set_prop('name', params, ip, port)
  return response

def set_power(state, ip, port):
  params = '["' + state + '", "smooth", 500]'
  response = set_prop('power', params, ip, port)
  return response

def set_bright(state, ip, port):
  params = '[' + str(state) + ', "smooth", 500]'
  response = set_prop('bright', params, ip, port)
  return response

if __name__ == "__main__":
  print 'Starting'
  (ip, port) = get_ip_port()
  if (ip, port) == (None, None):
    print "Can't get address of light"
  print 'IP is ', ip, ' port is ', port

  # sample set commands:
  success = set_power("on", ip, port)
  print 'Power set is', success[0]

  success = set_bright(90, ip, port)
  print 'Brightness set is', success[0]

  name = set_name('bedroom', ip, port)
  print 'Name is ', name[0]

  # sample get commands:
  power = get_prop("power", ip, port)
  print 'Power is', power[0]

  bright = get_prop("bright", ip, port)
  print "Bright is ", bright[0]

  name = get_prop('name', ip, port)
  print "name now is", name[0]

  # getting multiple properties at once.
  # Be careful with the quotes, words need to be separated by "," !
  prop_list = get_prop('name", "power", "bright', ip, port)
  print "Property list is", prop_list

For more info see Ch 35 of my online book IoT for Techies