0

members

Easy Raspberry basics: Project 14a Raspberry PI 3 model B board - Node-RED and Xiaomi Mijia Bedside Lamp

of Acoptex.com in Raspberry Pi 3

Raspberry basics: Project 14a

Project name: Raspberry PI 3 model B board - Node-RED and Xiaomi Mijia Bedside Lamp

Tags: Raspberry, Raspberry PI 3 model B board, Node-RED, Xiaomi Mijia Bedside Lamp

In this project, you need these parts :

1.Raspberry PI 3 model B 1 pc

2. Micro SD card and SD card adapter 1 pc

3. Micro USB power supply (2.1 A, max 2.5 A) 1 pc

4. USB keyboard 1 pc

5. USB mouse 1 pc

6. TV or PC monitor 1 pc

7. Xiaomi Mijia Bedside Lamp

General

We will learn how to integrate Xiaomi Mijia Bedside Lamp with Node-RED on Raspberry PI 3 model B board.

Xiaomi Mijia Bedside Lamp can be controlled with touch, using the Yeelight app or using an home automation platform like Node-RED.

We will make a web application with Node-RED and Raspberry Pi to control the Xiaomi Mijia Bedside Lamp.

You need Node-RED installed on your Raspberry PI 3 and Node-RED Dashboard.

Project notes:

  • 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.
    The app will contain a color picker and a drop-down menu with preset colors;
  • We can change the color brightness, saturation, temperature and hue with sliders;
  • Will be a toggle switch to turn the lamp on and off;
  • We can set a 15 minute timer and it will turn off the lamp after 15 minutes.

Understanding Xiaomi Mijia Bedside Lamp

This lamp uses high CRI osram LED, offering 16 million RGBW lights for your year-round choice. With simply touch and slide, you can adjust brightness and colors as you desired. Also, special lights design provides you different scenarios. Moreover, you can control the lamp for more fun using dedicated App.Get Original Xiaomi Yeelight Bedside Lamp and start a colorful life! 

Main Features:

  • Magic colors: choose from a tremendous range of 16 million colors 
  • Dimmable: adjust color temperature and brightness for suitable light
  • Color temperature: 1700K - 6500K color temperature gradual change function
  • Perfect CRI: professional optical design with high-quality Osram LED that of high color rendering index 
  • Touch control design: simple touch to adjust brightness / change color / delay switch off / switch light mode as you needed.
  • Wattage: 10W
  • Lamp input voltage: 12V, 1A
  • Adapter input voltage: 100 - 240V, 50 / 60HZ, 0.5A
  • Lifetime: 20000h
  • Operation: touch control, App control
  • System: compatible with Android 4.4 / iOS 8.0 and above systems
  • Scan the QR code at the end of English user manual to download App. You can read more about Yeelight app here.

Specifications:

General
Brand: Mijia 
Model: MJCTD01YL 
Output Power: 10W 
Voltage (V): AC 100-240V 
Luminous Flux: 300lm 
Color Temperature or Wavelength: 1700 - 6500K 
Features: Bluetooth,WiFi 
Function: Home Lighting 
Available Light Color: RGBW 
Sheathing Material: ABS
Dimension and Weight
Product weight: 1.2980 kg 
Package weight: 1.3400 kg 
Product size (L x W x H): 10.00 x 10.00 x 22.10 cm / 3.94 x 3.94 x 8.7 inches 
Package size (L x W x H): 15.00 x 15.00 x 25.00 cm / 5.91 x 5.91 x 9.84 inches
Package Contents
Package Contents: 1 x Mijia Bedside Night Light, 1 x Power Adapter, 1 x Chinese User Manual

Understanding the Raspberry PI 3 model B

The Raspberry Pi 3 is the third-generation Raspberry Pi. It replaced the Raspberry Pi 2 Model B in February 2016.

Specification:

  • Quad Core 1.2GHz Broadcom BCM2837 64bit CPU
  • 1GB RAM
  • BCM43438 wireless LAN and Bluetooth Low Energy (BLE) on board
  • 40-pin extended GPIO
  • 4 USB 2 ports
  • 4 Pole stereo output and composite video port
  • Full size HDMI
  • CSI camera port for connecting a Raspberry Pi camera
  • DSI display port for connecting a Raspberry Pi touchscreen display
  • Micro SD port for loading your operating system and storing data
  • Upgraded switched Micro USB power source up to 2.5A

Signals and connections of the Raspberry PI 3 model B


Step by Step instruction

We recommend using a high-performance SD card for increased stability as well as plugging your device into an external display to see the default application booting up.

1. Setup and preparation

We assume that you have Windows 10 installed on your PC and Raspbian OS installed on your Raspberry PI 3 board.

  1. Insert your micro SD card with Raspbian OS to Raspberry Pi 3 board.
  2. Connect the TV or PC monitor Display port (HDMI Port) to your Raspberry PI 3 board HDMI Port (HDMI cable required).
  3. Make sure that your monitor or TV is turned on, and that you have selected the right input (e.g. HDMI 1,  etc).
  4. Plug in your USB mouse and USB keyboard to Raspberry PI 3 board USB ports.
  5. Get connected. Connect an Ethernet cable to 10/100 LAN port of Raspberry Pi 3 or plug in WiFi adapter (see the list of supported here) to USB port of Raspberry Pi 3.
  6. Connect Micro USB power supply to Raspberry PI 3 board micro USB input.
  7. The Raspberry PI desktop will start up.
  8. Open Terminal window and type the command: sudo apt-get update
  9. Then type the command: sudo apt-get install 

2. Install Node-RED and Node-RED Dashboard on your Raspberry PI 3.

3. Enable LAN Control

When the Xiaomi Mijia Bedside Lamp connected to our router, we go to your Yeelight app and enable the LAN Control.

  1. Select the Xiaomi Mijia Bedside Lamp.
  2. Open the bottom right menu and choose the LAN Control option.
  3. Tap the enable button.
  4. You are ready for next step as your Node-RED flow can interact with the Xiaomi Mijia Bedside Lamp now. 

4. Installing the node-red-contrib-yeelight-compat-hue Node-RED node

  1. To control the Xiaomi Mijia Bedside Lamp with Node-RED, first you need to install node-red-contrib-yeelight-compat-hue. In the Terminal window type the commands: 
  2. node-red-stop
  3. cd ~/.node-red
  4. npm install node-red-contrib-yeelight-compat-hue

5a Creating Node-RED flow

  1. To start Node-RED enter the command: node-red-start
  2. Type this command to find out your IP address: hostname -I  In our case it is 192.168.0.121.
  3. To access Node-RED go to any Web browser on your PC.
  4. Locate the address bar at the top and type intype http://your_Raspberry_Pi_IP_address:1880 (in our case that is http://192.168.0.121:1880) then press Enter button. This will display the Node-RED. 
  5. Make sure you have these nodes. If you don’t have these nodes check that you have followed the steps above.
  6. Select Color Picker x1, Slider x4, Dropdown x1, Button x1, Switch x1 from DashboardFunction x6, delay x1 from Function, yeelight x 1 from lights.

  7. Make a tab Room 1, Bedside Lamp group in Room1. How to create tab and group you can find here.
  8. See the settings for tab and group below.
  9. Let's modify nodes now. See the Color picker settings below.
  10. See the Function node - Format color settings below:
  11. Add these lines in Function filed - 
  12. msg.payload='{"on": true, "hex": "' + msg.payload + '", "sat":0}' ;
  13. return msg;

  14. Modify one Dropdown node with settings below:
  15. Modify one Slider node with settings below:
  16. Modify one Slider node with settings below:
  17. Modify one Slider node with settings below:
  18. Modify one Slider node with settings below:
  19. Modify one Button node with settings below:
  20. Modify Switch node with settings below:
  21. See the Function node - Format Brightness settings below:
  22. Add these lines in Function filed -
  23. msg.payload='{"on": true,"bri":' + msg.payload + '}' ;
  24. return msg;
  25.  
  26. See the Function node - Format Saturation settings below:
  27. Add these lines in Function filed -
  28. msg.payload='{"on": true, "sat":' + msg.payload + '}' ;
  29. return msg;

  30. See the Function node - Format Temperature settings below:
  31. Add these lines in Function filed -
  32. msg.payload='{"on": true, "ct":' + msg.payload + '}' ;
  33. return msg;

  34. See the Function node - Format Temperature settings below:
  35. Add these lines in Function filed -
  36. msg.payload='{"on": true, "hue":' + msg.payload + '}' ;
  37. return msg;

  38. See the Function node - Format Off settings below:
  39. Add these lines in Function filed -
  40. msg.payload='{"on": false}' ;
  41. return msg;

  42. See the Delay node settings below:
  43. See the Yeelight node settings below:
  44. Connect all nodes. See the picture below.
  45. As you can see this flow is very complex. We recommend importing the flow (see the section below how to do it) instead of make it from the begining.

5b Importing the Node-RED flow

  1. To start Node-RED enter the command: node-red-start
  2. Type this command to find out your IP address: hostname -I  In our case it is 192.168.0.121.
  3. To access Node-RED go to any Web browser on your PC.
  4. Locate the address bar at the top and type intype http://your_Raspberry_Pi_IP_address:1880 (in our case that is http://192.168.0.121:1880) then press Enter button. This will display the Node-RED. 
  5. Make sure you have these nodes. If you don’t have these nodes check that you have followed the steps above.
  6. To import the Node-RED flow provided click here to download and view the file. Copy the code provided in file.
  7. At the top right corner of Node-RED select the menu, and go to Import  -> Clipboard.
  8. Paste the code and click on Import button.

 

6. Adding Yeelight bulb IP address

  1. You can use the an IP scanners like Advanced IP Scanner or Angry IP Scanner to scan for your Bedside Lamp IP address. In our case the Bedside Lamp’s IP address is 192.168.0.124.
  2. Double-click on yeelight node.
  3. Make a new config node. Press on pen sign and enter your Yeelight bulb IP address (we have 192.168.0.124) with default port 55443. Click on Add button and then click on Done button.
  4. After making all changes click on Deploy button to save all the changes.
  5. Your Node-RED application is ready. To access Node-RED UI and see how your application looks open any web browser in your local network and type: http://Your_RPi_IP_address:1880/ui (in our case it is http://192.168.0.121:1880/ui).
  6. Your application should look as example below.
  7. You can control your Xiaomi Mijia Bedside Lamp with Node-RED now.

Summary

We have learnt how to integrate Xiaomi Mijia Bedside Lamp with Node-RED on Raspberry PI 3 model B board.

Library

  • No libraries needed in this project

Sketch

  • No sketches needed in this project


Other projects of Acoptex.com
Easy Raspberry basics: Project 26a Raspberry PI Zero W board - Enable SSH of Acoptex.com in Raspberry Pi Zero W 07-01-2019
Easy Raspberry basics: Project 24a Raspberry PI Zero W board - Apache web server of Acoptex.com in Raspberry Pi Zero W 05-01-2019

« Go back to category
Is this project fake? Report it!   
Recommend to a friend
Published at 06-11-2018
Viewed: 196 times