Mi-Light controller for Mysensors



  • MiLight is a radio controlled RGB-W LED light bulb. You can buy them from ebay or aliexpress for about $10-$15 a piece. The light bulb is controlled by a handheld controller. The RF chip used in these lights are PL1167 but fortunately, people have reverse engineered the RF protocol (see https://hackaday.io/project/5888-reverse-engineering-the-milight-on-air-protocol) and have developed code to control these lights using a NRF24 radio.

    I have adapted these code to control these light bulbs using a mysensors module, which also serves as a repeater node. Once it receives command from the gateway, it switches to a different operation mode to simulate PL1167 and send commands to control the LED bulb. Afterwards, the sensor switches back to NRF24 mode and serve as repeater.

    The code currently supports two modes of operation: (1) turn the white light on/off using a light switch node; and (2) relay any command that is supported by the MI protocol using a custom sensor node.
    You need to 'pair' the light bulb with the controller the first time using it (UPDATE: you can do the pairing using the repeater node. No need to buy a separate wifi or wireless controller). To do so, turn on the power switch and send 'on' command to the light bulb within couple of seconds. The led bulb will flash a couple of times if the paring is successful.

    If you have multiple LED lights, you can assign each light with the same or different remote ID so you can control them as a group or individually.

    The code can be downloaded here (also see below for required library):
    0_1460251721914_open_Mi_Light_Controller_repeater.zip


  • Admin

    Great!
    You should add this project (with a image) to openhardware.io so it becomes easier to find.



  • Wonderfull. I have a lot of milight bulbs and using openmili too. Your work is fantastic, I will try it when have little time.



  • can rgb bulbs also be controlled/set color/dim ?



  • @Cliff-Karlsson
    Yes, I can control RGB color as well. The node can relay any command from the gateway to the Mi Bulb. It can implement the full capability of the original remote controller. The format of the MI protocol can be found here: https://hackaday.io/project/5888-reverse-engineering-the-milight-on-air-protocol . The node receives the command as a ASCII string; it then convert it to HEX format and send it to the bulb.



  • i'm getting this error:

    [code]
    open_Mi_Light_Controller_repeater.ino:3:23: fatal error: nRF_24L01.h: No such file or directory
    compilation terminated.
    [/code]



  • oops. I forgot to attach the modified nrf24 library.
    Somehow the module that simulates PL1167 is not compatible with mysensors' nrf24 library; instead, it requires the nrf24 library found here: http://tmrh20.github.io/RF24 , which, strangely, is not compatible with mysensors. So I end up with using two different nrf24 libraries, one for mysensor and the other for simulating PL1167. To make this work, I have to change the variable/file names of one of the libraries. Maybe there is something I didn't do correctly. Anyway, if you import the following library, it should work. 0_1460766143691_RF_24-master.zip

    @koen01



  • I just ordered four 9w rgbww bulbs to try your script out. But when reading the reviews one of the main disadvantages I found where that it was not possible to query the bulbs for the current state/color/dim-level.
    But if the bulbs are wired so that they are always on then the script/repeater-node or the controller keep track of all the states, right?

    Also is it possible to connect an battery powered arduino/nrf to the existing non powered wall-switch and have the arduino to send the switch-commands directly to the mi-light-repeater-node for faster reaction times for turning the bulbs on/off?



  • @Cliff-Karlsson

    Yes, it is possible to keep track of the bulb state from the controller.

    As to the switching speed, it is almost instantaneous (<<1 s). You can for sure add another node, but that will make the whole thing much more complicated to build.



  • @ted

    Thanks, I forgot to ask but if the node(s) have the full capability as the original remote controler. That means that I can also control ledstrips using the mi-light led dimmers like this: Led controller right?



  • Assuming the on-air protocols are the same, yes.
    I only have the RGB-W light bulb and were able to control it without ever using the remote controller.
    @Cliff-Karlsson



  • @ted said:

    (1) turn the white light on/off using a light switch node

    What does this mean? do I connect a light switch to the repeater-node? Or does it just mean that I can use another arduino to detect button-switches and send command to domoticz or other controller?



  • I have received my lamps now but no controller yet. Is it possible to pair/control the bulbs without controller?



  • @Cliff-Karlsson
    To pair, turn on the light switch, and send 'ON' command within 2-3 seconds. If successful, you will see the light flash on and off a couple of times.

    The repeater-node simply relay any command it receives from the controller (I use openhab) to the light wirelessly. There is no physical wire connection between the node and milight.



  • Ok, I meant to say that I had not got any bridge for the mi-light yet. In the first post it is mentioned that you need to pair using a bridge.



  • @Cliff-Karlsson
    thanks, the original post was updated to clarify this.



  • Thanks, next stupid question. How do I control the rgb/dimming features of the lamp? I got a ordinary on/off lamp under device in domoticz.



  • @Cliff-Karlsson
    You have to program your controller to produce the command string and send it to the node. The command string is transmitted as a ASCII string to the 'custom' node. See https://hackaday.io/project/5888-reverse-engineering-the-milight-on-air-protocol for the command format. Sorry I don't use domoticz.



  • Do I need to unpair the bulbs if I want to try pairing again? It got paired as a regular on/of bulb the first time. But I think I found out that I could add mi-lights using a dummy switch. But The bulb are not pairing.



  • @Cliff-Karlsson
    I don't know. Let us know what you find out. :)
    To unpair, you turn on the power to the bulb and send 'off' command within seconds.


Log in to reply
 

Looks like your connection to MySensors Forum was lost, please wait while we try to reconnect.