In this tutorial we’ll show you how you can integrate the Xiaomi Mijia Bedside Lamp with Node-RED. The Xiaomi Mijia Bedside Lamp is a smart lamp with built-in Bluetooth and Wi-Fi. It can be controlled with touch, using the Yeelight app, or using an home automation platform like Node-RED.
To learn more about the Xiaomi Mijia Bedside Lamp, you can read our review here.
Note: this tutorial is also compatible with the Xiaomi Yeelight Smart Bulb.
Watch the video demonstration
- 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.
In this tutorial we’ll build a Node-RED application that can control your Xiaomi Mijia Bedside lamp. Here are the features of the app you’re going to build:
- The app contains a color picker, and a drop-down menu with preset colors;
- You can change the color brightness, saturation, temperature, and hue with sliders;
- There is a toggle switch to turn the lamp on and off;
- You can set a 15 minute timer – this will turn off the lamp after 15 minutes.
For this project you need the following parts:
- Raspberry Pi Board – read Best Raspberry Pi Starter Kits
- Xiaomi Mijia Bedside Lamp – read full review
This is also compatible with:
- Xiaomi Yeelight Smart Bulb RGBW – E27 AC220V – read full review
- Xiaomi Yeelight Smart Bulb RGBW – E26 AC110V – 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 Bedside Lamp connected to your router, you have to go to your Yeelight app and enable the LAN Control.
1) Select the Bedside Lamp (or the Yeelight, if you’re using that instead)
2) Open the bottom right menu and choose the LAN Control option:
3) Tap the enable button:
After this configuration, Node-RED can communicate with the Bedside Lamp. You can find the documentation of the Yeelight app here.
Installing the node-red-contrib-yeelight-compat-hue Node
To control the Bedside Lamp with Node-RED, first you need to install node-red-contrib-yeelight-compat-hue node – you can take a look at the node documentation here. In the Terminal window type the following (this may take a few seconds to complete):
Download our Free eBooks and Resources
pi@raspberrypi:~ $ node-red-stop pi@raspberrypi:~ $ cd ~/.node-red pi@raspberrypi:~/.node-red $ npm install node-red-contrib-yeelight-compat-hue
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:
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 required node, as show in the figure below. If you don’t have the node, check that you’ve followed the previous instructions.
Here’s the flow to control the Bedside Lamp.
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 Bedside Lamp IP address
You need to add the IP address of your Bedside Lamp to the node-RED flow. In order to retrieve the beside lamp IP address, you can use the an IP scanner like Angry IP Scanner.
In my case, the Bedside Lamp IP address is 192.168.1.133.
Double-click the Bedside Lamp node:
Add your Bedside Lamp to the node by clicking the icon highlighted in red in the figure below:
Type the Bedside Lamp IP address in the Hostname/IP field. The port is set by default.
After making all the necessary changes, click the Deploy button to save all the changes.
Now, your 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:
Your application should look as in the following figure.
Here’s how the app looks on my OnePlus 5 smartphone (for the full demonstration see the video at the beginning of the post):
In this project we’ve built a Node-RED application to control the Xiaomi Mijia Bedside Lamp. The method used is also able to control other Xiaomi smart lights.
We hope you’ve liked this project, and have fun controlling your LED lamp. If you like this project, you may also like:
- Xiaomi Mijia Bedside Lamp Review
- Node-RED with Xiaomi Yeelight RGBW Smart Bulb
- Node-RED with WS2812B Addressable RGB LED Strip
- Build a Home Automation System with Node-RED
Thanks for reading.