members
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:
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.
- Insert your micro SD card with Raspbian OS to Raspberry Pi 3 board.
- Connect the TV or PC monitor Display port (HDMI Port) to your Raspberry PI 3 board HDMI Port (HDMI cable required).
- Make sure that your monitor or TV is turned on, and that you have selected the right input (e.g. HDMI 1, etc).
- Plug in your USB mouse and USB keyboard to Raspberry PI 3 board USB ports.
- 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.
- Connect Micro USB power supply to Raspberry PI 3 board micro USB input.
- The Raspberry PI desktop will start up.
- Open Terminal window and type the command: sudo apt-get update
- 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.
- Select the Xiaomi Mijia Bedside Lamp.
- Open the bottom right menu and choose the LAN Control option.
- Tap the enable button.
- 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
- 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:
- node-red-stop
- cd ~/.node-red
- npm install node-red-contrib-yeelight-compat-hue
5a Creating Node-RED flow
- To start Node-RED enter the command: node-red-start
- Type this command to find out your IP address: hostname -I In our case it is 192.168.0.121.
- To access Node-RED go to any Web browser on your PC.
- 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.
- Make sure you have these nodes. If you don’t have these nodes check that you have followed the steps above.
- Select Color Picker x1, Slider x4, Dropdown x1, Button x1, Switch x1 from Dashboard; Function x6, delay x1 from Function, yeelight x 1 from lights.
- Make a tab Room 1, Bedside Lamp group in Room1. How to create tab and group you can find here.
- See the settings for tab and group below.
- Let's modify nodes now. See the Color picker settings below.
- See the Function node - Format color settings below:
- Add these lines in Function filed -
- msg.payload='{"on": true, "hex": "' + msg.payload + '", "sat":0}' ;
- return msg;
- Modify one Dropdown node with settings below:
- Modify one Slider node with settings below:
- Modify one Slider node with settings below:
- Modify one Slider node with settings below:
- Modify one Slider node with settings below:
- Modify one Button node with settings below:
- Modify Switch node with settings below:
- See the Function node - Format Brightness settings below:
- Add these lines in Function filed -
- msg.payload='{"on": true,"bri":' + msg.payload + '}' ;
- return msg;
- See the Function node - Format Saturation settings below:
- Add these lines in Function filed -
- msg.payload='{"on": true, "sat":' + msg.payload + '}' ;
- return msg;
- See the Function node - Format Temperature settings below:
- Add these lines in Function filed -
- msg.payload='{"on": true, "ct":' + msg.payload + '}' ;
- return msg;
- See the Function node - Format Temperature settings below:
- Add these lines in Function filed -
- msg.payload='{"on": true, "hue":' + msg.payload + '}' ;
- return msg;
- See the Function node - Format Off settings below:
- Add these lines in Function filed -
- msg.payload='{"on": false}' ;
- return msg;
- See the Delay node settings below:
- See the Yeelight node settings below:
- Connect all nodes. See the picture below.
- 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
- To start Node-RED enter the command: node-red-start
- Type this command to find out your IP address: hostname -I In our case it is 192.168.0.121.
- To access Node-RED go to any Web browser on your PC.
- 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.
- Make sure you have these nodes. If you don’t have these nodes check that you have followed the steps above.
- To import the Node-RED flow provided click here to download and view the file. Copy the code provided in file.
- At the top right corner of Node-RED select the menu, and go to Import -> Clipboard.
- Paste the code and click on Import button.
6. Adding Yeelight bulb IP address
- 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.
- Double-click on yeelight node.
- 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.
- After making all changes click on Deploy button to save all the changes.
- 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).
- Your application should look as example below.
- 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










Viewed: 1506 times