Xiaomi RGB Bulb simple UDP server solution

  • OK, I think you are listening on the wrong port. if you used the same ports as i did, you have to use port 20450 in the yee.py


    Ok, so I changed the port to 20450, but still nothing.


    Let me give you what I wrote in the yee.py file and in all the others:


    yee.py: [MEDIA=pastebin]f8A0tcCy[/MEDIA]


    yeelight1.config.json: [MEDIA=pastebin]rDb0ADj1[/MEDIA]
    yeelight1.config.json: [MEDIA=pastebin]j621apzz[/MEDIA]


    main hyperion.config.json has the following added, as instructed:



    "forwarder" :
    {
    "json" : [ "192.168.1.29:20450", "192.168.1.59:20452" ],
    "proto" : [ "192.168.1.29:20451", "192.168.1.59:20453" ]
    },


    "endOfJson" : "endOfJson"
    }


    Again, there must be something escaping me. What am I doing wrong?

  • Assuming your IPs are correct, it's simply a port issue. Let's have a look step by step:


    yee.py looks ok, the IP here should be the IP of your first yeelight.
    For your second yeelight, you need another .py file, for example yee2.py. Obviously use the IP of your second yeelight and another port, for example port 20541.


    Regarding your yeelight.config.json files:
    In the "device" block, the "output" line must not be the same in both configs. Change the port in the second file, use 20451 as above. The IP here should match the IP of the RPi where the .py files are run (if your .py files run on the same RPi as hyperion you may also use 127.0.0.1 as the IP).
    Also, your "jsonServer" and "protoServer" ports are wrong. Use 19450 and 19451 in config1, 19452 and 19453 ind config 2. These ports must be different from the udp port you used above!


    Finally, change "forwarder" block to

    Code
    "forwarder" :
    {
    "json" : [ "192.168.1.59:19450", "192.168.1.59:19452" ],
    "proto" : [ "192.168.1.59:19451", "192.168.1.59:19453" ]
    },


    Be careful with the IP here, you mixed up .29 and .59. Again this is the IP of your RPi, thus you can also use 127.0.0.1.


    I know it's a big mess with the IPs and ports. For me it helped doing small graphs. Essentially you need 3 servers for each yeelight, each with a different port: udp, json and proto server.

  • It is possible to use this from windows pc (win7)
    I have a setup with USB Grabber: https://hyperion-project.org/wiki/HyperCon-GrabberTab is working fine.
    The source is my Windows 7 PC and i like to add a yeelight color bulb.


    the bad is that i use kodi openelec and this is only working for the internal grabber, because i cannot install with pip.
    But when i can execute python yeelight library, then i should be able to use this from there?


    Otherwise is there a solution that i can use with grabber setup for my yeelight?

  • i get an error that i'm not able to fix (new to python)


    python yeelight.py
    ('waiting on port:', 20450)
    Traceback (most recent call last):
    File "yeelight.py", line 6, in <module>
    from yeelight import *
    File "/root/yeelight.py", line 39, in <module>
    bulb = Bulb(ip_address, effect="smooth", duration=timeout)
    NameError: name 'Bulb' is not defined


    can anybody help?
    Installed yeelight trough pip

  • I know this is an oldie but I'm just trying to get it working.


    I've followed the instructions and when I run yee.py, my yeelight bulb comes on white but doesn't change in sync with my LED strips round the TV. This is what I have in my second config file:


    [INDENT]{
    "device" :
    {
    "name" : "MyPiudp",
    "type" : "udp",
    "output" : "192.168.1.43:20450", "protocol" : 0,
    "rate" : 1000000,
    "colorOrder" : "rgb"
    },
    "leds" :
    [
    {
    "index" : 0,
    "hscan" : { "minimum" : 0.0000, "maximum" : 0.1000 },
    "vscan" : { "minimum" : 0.0000, "maximum" : 1.0000 }
    }
    ],


    "forwarder" :
    {
    "json" : [ "192.168.1.43:19450" ],
    "proto" : [ "192.168.1.43:19451" ]
    },
    }
    [/INDENT]
    So, I know my IP address is right or yee.py wouldn't turn the light on.


    I'm stuck on where to look next

  • Hi, my yeelights lamp in the color transition is not so soft...What could it be?
    And how do I set the lamp to the right side of the TV?


    This is my config:


    yee1.py:
    [MEDIA=pastebin]ev3Lba7M[/MEDIA]


    yeelight1.config:
    [MEDIA=pastebin]TtYXJps9[/MEDIA]


    hyperion.config
    [MEDIA=pastebin]8BmdPxiH[/MEDIA]

  • Hello, I have a Rpi3 (Raspbian Stretch and Kodi 18.2 with Hyperion) and it syncs perfectly. Now I have a yeelight color version 2. I have activate LAN-Control and I can do ping to my bulb.


    When I run yee.py with my bulb off, yee.py put my bulb on (white).



    My yee.py is:


    #!/usr/bin/python
    import socket
    import time
    import math
    from yeelight import *
    ip_address = "10.42.0.233"
    timeout = 200
    def rgb2hsv(r, g, b):
    r, g, b = r/255.0, g/255.0, b/255.0
    mx = max(r, g, b)
    mn = min(r, g, b)
    df = mx-mn
    if mx == mn:
    h = 0
    elif mx == r:
    h = (60 * ((g-b)/df) + 360) % 360
    elif mx == g:
    h = (60 * ((b-r)/df) + 120) % 360
    elif mx == b:
    h = (60 * ((r-g)/df) + 240) % 360
    if mx == 0:
    s = 0
    else:
    s = df/mx
    v = mx
    return round(h), round(s * 100, 1), round(v * 100, 1)
    #UDP SERVER
    port = 20450
    last = ""
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    s.bind(("", port))
    print("waiting on port:", port)
    #YEELIGHT
    bulb = Bulb(ip_address, effect="smooth", duration=timeout)
    bulb.turn_on()
    status = "on";
    # bulb.effect = "smooth"
    #Stop/Start music mode, bypasses lamp rate limits, ensures that previous sockets close before starting
    while True:
    try:
    bulb.stop_music()
    break
    except BulbException:
    break
    time.sleep(1)
    while True:
    try:
    bulb.start_music()
    break
    except BulbException:
    break
    time.sleep(1)
    try:
    while True:
    d = s.recvfrom(3)
    new = bytearray(d[0])
    hsv = rgb2hsv(new[0], new[1], new[2])
    if new != last:
    if hsv[2] == 0.0:
    if status == "on":
    bulb.turn_off()
    status = "off"
    elif status == "off":
    bulb = Bulb(ip_address, effect="smooth", duration=timeout)
    while True:
    try:
    bulb.start_music()
    break
    except BulbException:
    break
    bulb.turn_on()
    status = "on"
    if status == "on":
    bulb.set_hsv(*hsv)
    last = new
    except KeyboardInterrupt:
    print("Exit ...")




    My yeelight.config.json is:


    {
    "device" :
    {
    "name" : "MyPiudp",
    "type" : "udp",
    "output" : "127.0.0.1:20450", "protocol" : 0,
    "rate" : 1000000,
    "colorOrder" : "rgb"
    },
    // COLOR CALIBRATION CONFIG
    "color" :
    {
    "transform" :
    [
    {
    "id" : "default",
    "leds" : "*",
    "hsl" :
    {
    "saturationGain" : 1.0000,
    "luminanceGain" : 1.0000,
    "luminanceMinimum" : 0.0000
    },
    "red" :
    {
    "threshold" : 0.0000,
    "gamma" : 2.3000
    },
    "green" :
    {
    "threshold" : 0.0000,
    "gamma" : 2.3000
    },
    "blue" :
    {
    "threshold" : 0.0000,
    "gamma" : 2.4000
    }
    }
    ],
    // SMOOTHING CONFIG
    "smoothing" :
    {
    "type" : "linear",
    "time_ms" : 200,
    "updateFrequency" : 20.0000,
    // "updateDelay" : 0
    }
    },
    // JSON SERVER CONFIG
    "jsonServer" :
    {
    "port" : 19450
    },
    // PROTO SERVER CONFIG
    "protoServer" :
    {
    "port" : 19451
    },
    "leds" :
    [
    {
    "index" : 0,
    "hscan" : { "minimum" : 0.0000, "maximum" : 0.1000 },
    "vscan" : { "minimum" : 0.0000, "maximum" : 1.0000 }
    }
    ],

    "blackborderdetector" :
    {
    "enable" : true,
    "threshold" : 0.1
    },

    "endOfJson" : "endOfJson"
    }



    And in hyperion.config.json I added:


    "forwarder" :
    {
    "json" : [ "127.0.0.1:19450" ],
    "proto" : [ "127.0.0.1:19451" ]
    },
    "endOfJson" : "endOfJson"



    What am I doing wrong? Because when I run python yee.py only put the yeelight on (white) if previously is off, but if I see a film only sync the leds strip I have on tv.

  • hi,


    Python
    ('waiting on port:', 20450)
    Traceback (most recent call last):
      File "/etc/hyperion/yeelight.py", line 7, in <module>
        from yeelight import *
      File "/etc/hyperion/yeelight.py", line 40, in <module>
        bulb = bulb(ip_address, effect="smooth", duration=timeout)
    NameError: name 'bulb' is not defined


    i get this error pi2 on python 2.7

  • hi,


    Python
    ('waiting on port:', 20450)
    Traceback (most recent call last):
      File "/etc/hyperion/yeelight.py", line 7, in <module>
        from yeelight import *
      File "/etc/hyperion/yeelight.py", line 40, in <module>
        bulb = bulb(ip_address, effect="smooth", duration=timeout)
    NameError: name 'bulb' is not defined


    i get this error pi2 on python 2.7


    k got this. Never name the scripts yeelight.py - choose a different name


  • Hello everyone,


    i have the same problem, did you find a solution?
    My Yeelight Bulbs also turn white and then nothing changes anymore.
    When I start the yee.py: it is just waiting for the port. But nothing changes.
    Ip's seem to be correct, because they are turning white.
    But no syncronization.
    pi@raspberrypi:~ $ python yee2.py
    ('waiting on port:', 20451)


    Thanks in advance for any help!
    Best Paff

  • hi


    i am running into the same problem with hyperion.ng and Yeelight 1s.


    once i configured everything and fire up the .py it just says "waiting on port: 5568" -- if the lamp is already on nothing happens. if the lamp is off it will turn on with the last selected color/preset.


    has anybody been able to fix this?


  • Same error for me:

    but the bulb is turned on; of course I'm not able to control it with hyperion.

    • Offizieller Beitrag

    Hi @MSpedy


    Please see, if the fix outlined in the following forum thread helps


    https://forum.hyperion-project…light-bridge.10386/page-2


    In addition, you can have a look at earlyYeeligh native support in hyperion.ng:


    https://github.com/hyperion-project/hyperion.ng/issues/727


    Kind regards


  • Thank You very much for rapid support!
    I'm not completly understanding: have I to install Hyperion yeelight bridge instead or in addition to standard Hyperion service?

    • Offizieller Beitrag

    @MSpedy


    I just wanted to give you two options:


    1. Either you continue with the Hyperion-NG Yeelight Bridge (see link 1 above),
    but there you need to amend the configurator.py to add 'color4', 'stripe' to the modelslist array to have Bulb 1S and/or Stripe v2 running.
    i.e. modelsList = ['color', 'color1', 'color2', 'strip1', 'color4', 'stripe']


    2. If you are able to compile hyperion.ng yourself, you can try Hyperion.n Yeelight native support (without Yeelight Bridge) which is under development.
    The development version is not yet officially available. That is why you would need compiling yourself using my repository (see instructions link 2 above).


    Hoping that clarifies.

Jetzt mitmachen!

Sie haben noch kein Benutzerkonto auf unserer Seite? Registrieren Sie sich kostenlos und nehmen Sie an unserer Community teil!