Node-RED with Xiaomi Mijia Bedside Lamp (Wi-Fi and Bluetooth)

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

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:

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:

A new window opens. 

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:

Thanks for reading.



Learn how to build a home automation system and we’ll cover the following main subjects: Node-RED, Node-RED Dashboard, Raspberry Pi, ESP32, ESP8266, MQTT, and InfluxDB database DOWNLOAD »
Learn how to build a home automation system and we’ll cover the following main subjects: Node-RED, Node-RED Dashboard, Raspberry Pi, ESP32, ESP8266, MQTT, and InfluxDB database DOWNLOAD »

Enjoyed this project? Stay updated by subscribing our newsletter!

8 thoughts on “Node-RED with Xiaomi Mijia Bedside Lamp (Wi-Fi and Bluetooth)”

  1. 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 !!

    Reply
  2. 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:)

    Reply
  3. 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 🙂

    Reply

Leave a Comment

Download Our Free eBooks and Resources

Get instant access to our FREE eBooks, Resources, and Exclusive Electronics Projects by entering your email address below.