Having discussed Milight and Chris Mullins NodeMCU Milight Gateway in a prevous article, I thought it might be nice to create a little walkthrough of what’s involved in getting this up and running and connected to Domoticz.
Part 1 – Setting up the NodeMCU Hardware and Software
First the hardware
- NodeMCU (or compatible ESP8266 module), approx £5.00
- NRF24L01+ 2.4GHz Wireless Module, stard from about £2.00
- 7 Dupont Jumper cables, £1-£3 maximum
- Micro USB power adaptor for NodeMCU, a few pounds, I have tons lying around
- Micro USB cable to connect to PC
(Did I mention that this is a very cheap project?)
The following guide explains how to connect the NRF to the NodeMCU (scroll to the NRF24L01+ & ESP8266 section):
Next the Software
Download the NodeMCU flasher and the pre-compiled Gateway image from Chris’s Github page:
https://github.com/sidoh/esp8266_milight_hub/releases (select the latest nodemcuv2 download)
Plug your NodeMCU into your PC. Give it 30 seconds or so then load device manager (right click start menu and select device manager in the menu). Drill down into Ports (COM & LPT) and you should find a new COM port that relates to your NodeMCU.
Next run the flasher (it may ask for admin rights so say yes). Select the NodeMCU’s COM port, then click the Config tab. Enter the full path to the bin file of your downloaded gateway image on the first line and check the tick box. If the path is correct the background should turn green. You may need to use “” around your path if it has spaces in.
Now to back to the Operation Tab and click Flash.
Once the flash has complete sucesfully, unplug the NodeMCU from your computer and power it up via its own USB power source.
This part requires a device with wireless. On your device, look for a wireless network called ‘ESPXXXXX’ – where ‘XXXXX’ is your ESP/NodeMCU’s unique device ID – and connect to it. Once connected Open a browser and via the magic of the captive portal you should be redirected to a config screen. If this doesn’t happen it defaults to 192.168.4.1
Enter the credentials for your home wifi and the device should connect to that. Again you will need to find the IP, you can find this in your routers DHCP logs, via an IP scan, and I think it even shows up as a uPNP device.
Once you have the IP, load it up in your browser and login.
Part 2 – Using the Milight Gateway
As long as your hardware is all working and your gateway is successfully connected to your WiFi, you should now be in a position to start using your new shiny Milight Gateway.
You can test the gateway is working if you have a Milight remote control. Scroll to the Sniff Traffic section and click Start Sniffing. Press the buttons on your remote and you should see packet information appear in Sniff Traffic as you push each button.
I am using the gateway as an emulator to replace the ‘standard’ controller. This allows me to created a drop in replacement for a normal Milight gateway, but at a much cheaper price. That said, this is the most basic usage of this device, if you are any good ad coding and don’t mind getting your hands dirty, you might way to look into directly using the API presented by the device. I wont be covering that, at least not as part of this tutorial.
Part 3 – Connecting to Domoticz
You will first need to create a virtual controller on the Milight controller, the controller calls these Gateway Servers. Under the Gateway Server header, enter a device id in the format 0x**** (where **** is a 4-digit number) and a UDP Port number. I like to keep these close to the standard device id and port numbers, i.e. 0x2900 and 5987. Gateway version depends on the type of Milight bulbs or strip controller you are using, I’ve personally found version 5 to be more compatible, but you may need to fiddle with this.
Log in to the web interface of your Domoticz installation and head to Setup > Hardware. At the bottom of the Hardware page enter a name for your Gateway Server and set the type to Limitless/AppLamp/Mi Light with LAN/WiFi interface. Next, input the IP address and Port of your Gateway Server as above and click Add. Once added click Set Mode on the devices new entry in the hardware list and select the appropriate mode, again this is dependent on the bulb or strip controller type and you may need to tweak this.
Next head to Setup > Devices and click the Not Used button. You should be able to find your Milight controller channels here. They will be listed under a hardware entry that matches the name you set for your Gateway Server before, and will be called Applamp Group1 – Applamp Group4 and Applamp All. These match the buttons found on a physical Milight remote control. Add each device, Applamp Group1 – Applamp Group4 but dont bother with Applamp All and give them names based on the bulb/strip that you want to control.
Part 4 – Pairing Milight Bulbs / LED Strip Controllers
You should now be able to pair your bulbs or strip controllers in the normal fashion.
Head to the Switches page and you should now see your new switches created in the previous step and named accordingly. To pair a switch with its physical bulb/strip controller you will need to be physically present at the bulb, so take your laptop with the Domoticz page open or use the Domoticz android app.
Turn the power to the bulb off at the physical switch, and get your finger ready on the Domoticz virtual switch. Power on the physical switch to the bulb and immediately press the virtual switch button in Domoticz. If the pairing is successful, the light should switch on and off 3 times. If it doesn’t work the first time try again as it can be a little finicky.
Repeat this for each additional device (for your first 4 devices).
You are now at the stage you would be at with an official Milight Wifi Box controller, you’ve maxed out your 4 channels.
Part 5 – Beyond the 4 channel barrier..!
To go beyond 4 channels is simplicity. Head back to the Mighlight controller web interface. Under Gateway Servers add another entry with a slightly different device id and port number. Then head back to Domoticz and repeat steps 3-4. Thats it and you can do this as many times as you need dependent on your number of devices.!