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
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
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.
Parts Required
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:
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):
pi@raspberrypi:~ $ node-red-stop pi@raspberrypi:~ $ cd ~/.node-red pi@raspberrypi:~/.node-red $ npm install node-red-contrib-yeelight-compat-hue
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 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.
Node-RED UI
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:
http://Your_RPi_IP_address:1880/ui
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):
Wrapping Up
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.
Congratulations !!!! Very good article!!!
Thanks 🙂
Regards,
Sara
Nice article like always ! It works like a charm with my RGBW Smart Bulb, but i can’t have it work with the LED Strip. Do you know if it’s compatible with this Xiaomi product ? Thanks !!
Hi!
We haven’t tested with the Xiaomi strip, so we can’t assure it works with it.
However, it should be compatible.
Hi Rui,
Great job, I’m wondering if there’s any chance to achieve same/similar results by using the beside lamp first version (only Bluetooth) and an Esp32 – BLE
Pls let me know:)
Hi Ricardo.
This project is not compatible with the Bluetooth version.
But maybe you can achieve similar results if you try to control your board using your ESP32…
We have a tutorial with ESP32 and BLE that shows how to get started with BLE on ESP32 that may help you in your project: https://randomnerdtutorials.com/esp32-bluetooth-low-energy-ble-arduino-ide/
Regards,
Sara
Hi There,
I am facing a problem. I am using node-red from my windows PC (OS win 10) and after import the flow Node-Red does not recognize the nodes at the left position. I mean, it shows “unknown: ui_colour_picker”, “unknown: ui_dropdown”, “unknown: ui_switch” and so on.
Any help or hint will be very appreciate.
Thanks and great work 🙂
Hi.
You need to install the dashboard nodes.
See the installation section in this article: https://flows.nodered.org/node/node-red-dashboard
Regards,
Sara