A while ago I bought a Raspberry Pi 4B for my graduation project. After the defense, the Pi sat idle. Apart from setting up a local-network cloud drive, I thought about the OpenCV I’d dabbled in before, so I ordered a camera and a PIR sensor, wired them to the Pi, and built a simple “good-morning” push: every morning when I sit down at my desk, WeChat gets a greeting plus the weather forecast.

Good-morning greeting & weather forecast
The overall idea is: every day at 7 a.m. the Pi runs a Python script. The PIR sensor checks whether someone is at the desk; if yes, the camera opens to see if it’s me; if it is, a message is pushed to WeChat. Simple idea, smooth coding—no big issues except that when wiring the PIR I reversed VCC and GND and fried one sensor (plus a small burn on my hand) ∠( ᐛ」∠)_
Preparation
🖥️ One Raspberry Pi with OpenCV + Mediapipe installed
📹 One camera
✋ One (or more) PIR sensors
🔌 Several female-to-female DuPont wires
🎤 A server running Wecom酱 (or run it on the Pi, whatever)
PIR Sensor
Any cheap PIR from Taobao works, but pick one with a short range (~1 m). Mine senses 5–10 m; even at minimum sensitivity it’s still a bit too trigger-happy for daily use.

Raspberry Pi pinout & PIR pinout
Wire VCC to Pi pin 4 (5 V), GND to pin 6 (GND), and OUT to any GPIO—here GPIO 28 (physical pin 38).
NoteDon’t reverse VCC and GND or the sensor dies instantly. Use 3.3 V or 5 V according to the sensor’s spec.

Sensor wiring
Drop the following code onto the Pi and run:
If all goes well, waving a hand in front prints HIGH for a while (the sensor’s delay), otherwise LOW. Sensor check done.

PIR output
Face-Recognition Prep
Use OpenCV + Mediapipe to grab faces from the camera, then upload the crop to Megvii’s Face++ platform via API for recognition.
Face++ Face Detect
First, take a selfie to serve as the reference face. POST it with multipart/form-data to the detect API to get a face_token—unique per face, used later for comparison.
The face_token expires in 72 h if not added to a faceset, so next create a faceset for long-term storage.
Face++ Create Faceset
POST to the create API.
Get faceset_token, then add the face.
Face++ Add Face
Same idea:
Prep finished. Face++ docs have more details.
Main Program
For weather we use QWeather’s real-time API. GET https://devapi.qweather.com/v7/weather/now?location={city ID}&key={key}.
Face comparison calls the compare API, again with multipart/form-data. Full code:
To run daily at 7 a.m., crontab -e and add 0 7 * * * python3 {path} then Ctrl-O, Ctrl-X.
Finally
I’ve always wanted full smart-home gear, but the price is steep, so I DIY-ed it my way. The moment everything worked was hugely satisfying—probably a joy you don’t get by simply buying off the shelf.
P.S. To control smart devices (e.g., Mi smart plugs) as well, here’s a Python lib for Xiaomi gadgets that might help.