Xiaomi Yeelight is a Wi-Fi smart RGBW LED bulb that you can integrate with Node-RED. So, in this project we’re going to show you how to build a web application with Node-RED and Raspberry Pi to control the Yeelight lamp.
Note: If you have any trouble following this tutorial, you can follow this one instead, that is also compatible with the Xiaomi Yeelight Smart bulb: Node-RED with Xiaomi Mijia Bedside Lamp
Watch the video demonstration
If you want to learn more about the Xiaomi Yeelight specifications and how it works with the official app, go to Maker Advisor to read our review.
Prerequisites
- You should be familiar with the Raspberry Pi – read Getting Started with Raspberry Pi.
- You should have the Raspbian operating system installed in your Raspberry Pi – read Installing Raspbian Lite, Enabling and Connecting with SSH.
- You need Node-RED installed on your Pi and Node-RED Dashboard.
If you like home automation and you want to learn more about Node-RED, Raspberry Pi, ESP8266 and Arduino. I recommend that you download my course: Build a Home Automation System with Node-RED, ESP8266 and Arduino.
Project overview
Here’s some important aspects about the Node-RED application built in this project:
- The Xiaomi Yeelight Smart Wi-Fi Bulb will be controlled using the Yeelight node that you need to install;
- In the application, you have a color picker or a drop-down menu to change the bulb color;
- The application also allows you to change the temperature and brightness;
- Finally, you have the “Toggle” button. This means that if you press that button when the lamp is on, the lamp turns off and vice versa.
Parts required
- Raspberry Pi Board – read Best Raspberry Pi Starter Kits
- Xiaomi Yeelight Smart Bulb RGBW – E27 AC220V – read full review
You can use the preceding links or go directly to MakerAdvisor.com/tools to find all the parts for your projects at the best price!
Enabling LAN Control
Having the Yeelight bulb connected to your router, you have to go to your Yeelight app and enable the LAN Control.
1) Select the Yeelight Color Bulb:
2) Open the bottom right menu and choose the LAN Control option:
3) Tap the enable button:
After that your Node-RED flow can interact with the Yeelight bulb. You can find the documentation of the Yeelight app here.
Installing the yeelight Node-RED node
To control the Yeelight with Node-RED, first you need to install node-red-contrib-yeelight. In the Terminal window type the following (this may take a few seconds to complete):
pi@raspberrypi:~ $ node-red-stop pi@raspberrypi:~ $ cd ~/.node-red pi@raspberrypi:~/.node-red $ npm install node-red-contrib-yeelight
Starting Node-RED
To start Node-RED, enter the following in the Terminal window:
pi@raspberrypi:~ $ node-red-start
To access Node-RED, open a tab in any browser on the local network and type the following:
http://Your_RPi_IP_address:1880
You should replace Your_RPi_IP_address with your Raspberry Pi IP address. If you don’t know your Raspberry Pi IP address, in the Terminal enter:
pi@raspberrypi:~ $ hostname -I
Creating the Node-RED Flow
Before creating the flow, make sure you have the yeelight node, as show in the figure below. If you don’t have the node, check that you’ve followed the instructions above in the Installing the yeelight Node-RED node section.
Here’s the flow to control the Xiaomi Yeelight bulb.
As this flow is a bit complex, we recommend importing the flow we provide instead of building it from scratch. Then, you can make modifications to the flow, if necessary.
Importing the Node-RED flow
To import the Node-RED flow provided, go to the GitHub repository or click the figure below to see the raw file, and copy the code provided.
Next, in the Node-RED window, at the top right corner, select the menu, and go to Import > Clipboard.
Then, paste the code provided and click Import.
Adding your Yeelight’s IP address
In order to retrieve the Yeelight IP address, you can use the an IP scanner like Advanced IP Scanner or Angry IP Scanner.
In my case, the Yeelight’s IP address is 192.168.1.131. Double-click one of the Yeelight’s nodes:
Open the config node:
Type your Yeelight’s IP address (leave the default port number 55443):
Node-RED UI
After making all the necessary changes, click the Deploy button to save all the changes.
Now, you Node-RED application is ready. To access Node-RED UI and see how your application looks, access any browser in your local networks and type:
http://Your_RPi_IP_address:1880/ui
Your application should look as in the following figure.
Here’s a quick demonstration (for the full demonstration see the video at the beginning of the post):
Wrapping up
In this project we’ve made a Node-RED application to control the Xiaomi Yeelight. We hope you’ve liked this project, and have fun controlling your LED lamp.
Note: If you have any trouble following this tutorial, you can follow this one instead, that is also compatible with the Xiaomi Yeelight Smart bulb: Node-RED with Xiaomi Mijia Bedside Lamp
If you like this project, you may also like:
- Xiaomi Yeelight RGBW Smart Bulb Review
- Node-RED with WS2812B Addressable RGB LED Strip
- What’s the Best LED Strip For Your Project?
- Build a Home Automation System with Node-RED
Thanks for reading.
Hi Rui,
I wold like to see more projects based on home assistant (home-assistant.io), please
Thank You
Hi Daniel.
We intend to start making more projects using Home-Assistant, like controlling the Xiaomi Yeelight.
Thank you for your suggestion 🙂
This is very good~
Hello
Nice tutorial. I have Yeelight RGB LED strip, but this does not work with this – any idea what can be different, and how to make it work?
Hi Pire.
Unfortunately, we don’t have an Yeelight RGB LED strip to test.
So, we can’t tell why it doesn’t work.
Ok, I suggest that you buy one. of course it should be of the good sorts or you will have to repair it frequently.
Your Sincerely
Saeed
Hi.
We’ve already ordered one. We’ll test it when it arrives.
But if you are having trouble with this tutorial, try following this one that uses another node, and works similarly: https://randomnerdtutorials.com/node-red-with-xiaomi-mijia-bedside-lamp/
I hope this helps.
Thanks 🙂
Firstly, excellent instructions and also great site! Been enjoying having a read about the various Yeelight solutions you have in place.
I’ve hit an issue where I’m getting the following in the logs:
17 Feb 23:54:48 – [info] Starting flows
17 Feb 23:54:48 – [error] [yeelight-config:ada24ea5.54244] ReferenceError: window is not defined
17 Feb 23:54:48 – [info] Started flows
17 Feb 23:55:03 – [error] [yeelight:Toggle] TypeError: Cannot read property ‘toggle’ of null
17 Feb 23:55:11 – [error] [yeelight:Set Brightness] TypeError: Cannot read property ‘set_bright’ of null
17 Feb 23:57:20 – [error] [yeelight:Set RGB Color] TypeError: Cannot read property ‘set_rgb’ of null
17 Feb 23:58:08 – [error] [yeelight:Set RGB Color] TypeError: Cannot read property ‘set_rgb’ of null
17 Feb 23:58:11 – [error] [yeelight:Toggle] TypeError: Cannot read property ‘toggle’ of null
17 Feb 23:58:14 – [error] [yeelight:Toggle] TypeError: Cannot read property ‘toggle’ of null
Any ideas what may be wrong in the setup. I have reviewed the steps with nothing weird being found. Any help would be appreciated!
Hi Gareth.
Thanks a lot for your words.
If you’re having issue with this tutorial, it may be an issue with the yeelight node itself.
Please follow the next tutorial that is also compatible with the yeelight: https://randomnerdtutorials.com/node-red-with-xiaomi-mijia-bedside-lamp/
Hello dear,
thanks for the project.
I am not abble to edit the yeelight node, there is a note on the top of the editor : “restrict by Service UUID
Thanks in adavnce for your help
Marc
Hi Marc, I’ve never encountered that error before. Can you try to run/open Node-RED with sudo?
Is there any way to make this work with the new version of this Bulb?
Hi Fabian.
We just tested this example with this specific bulb.
But I think it might work as long as you enable the LAN mode.
What version do you have?
Regards,
Sara 🙂
Hello Rui,
thanks for the tutorial but i have an error that i can’t fix when i try to change the color with node-red dashboard. The lamp color didn’t change and in the terminal i have the following error :
[error] [yeelight:Set RGB Color] TypeError: Cannot read property ‘set_rgb’ of null
Please can you help me because i found yur tutorial very interessant and would to reproduce him
Hi.
If you’re having issue with this tutorial, it may be an issue with the yeelight node itself.
Please follow the next tutorial that is also compatible with the yeelight: https://randomnerdtutorials.com/node-red-with-xiaomi-mijia-bedside-lamp/ and see if it works.
Regards,
Sara
Hi, when i import the node-RED flow from Github there is a problem left of the flow. like: “unknown: ui_colour_picker”
What is the problem?
Hi.
Did you install node-RED UI?
Regards,
Sara