Local porch monitoring for TP-LINK Tapo cameras with RTSP enabled, designed for a Raspberry Pi 4 and above and Telegram-based photo alert delivery.
This project watches a local RTSP camera stream, runs local face and object detection, saves annotated snapshots, records after detection video clips, and sends photo alerts to Telegram without any paid cloud service.
Tested setup:
- Raspberry Pi 4 with 4 GB RAM
- Raspberry Pi OS Bookworm or newer
- Tapo camera models that support RTSP streaming
- Stable operation tested up to 5 FPS; above that, Raspberry Pi 4 thermal throttling became an issue during longer runs, can be solved with a fan cooling case.
- Connects to a Tapo RTSP stream with OpenCV
- Detects faces with the OpenCV DNN face detector
- Detects people and delivery packages with YOLO11n NCNN
- Uses backpack and suitcase detections as package-like proxies
- Sends annotated photo alerts to Telegram
- Supports standard chats and Telegram forum topic threads
- Records a configurable MP4 clip after the first trigger in a burst
- Applies separate cooldowns for face, person, and package alerts
- Adds timestamps to saved images and recorded video
- Retries Telegram uploads automatically with backoff if the network is down
- Reconnects to the camera stream automatically if RTSP drops
- Cleans up old snapshots and videos automatically
- Includes helper scripts to test Telegram delivery and fetch your chat ID
- Face detection
- Person detection
- Package-like detection using
backpackandsuitcaseclasses as practical proxies
- Face detection uses the OpenCV DNN Caffe SSD face detector
- Person and package-like detection use YOLO11n exported in NCNN format
- NCNN is a good fit for Raspberry Pi because it is lightweight and optimized for edge-style inference workloads
detector.py: Main detector and alerting loopconfig.py: Camera, Telegram, cooldown, and storage settingsstart.sh: Launcher script intended for Raspberry Pi deploymenttelegram_test.py: Sends a test message and optional test photo to Telegramget_chat_id.py: Prints chat IDs seen by your Telegram bottemp_logger.sh: Optional Pi temperature loggeryolo11n_ncnn_model/: YOLO11 NCNN export used by the detector at runtime
The current scripts are written for this install path:
/home/pi/telegram_porch_detector
If you want to use the code exactly as it is in this repository, clone it to that location on the Pi.
The detector also writes media to:
/home/pi/porch_snapshots
/home/pi/porch_videos
- Python 3
- A Telegram bot token from
@BotFather - Your Telegram chat ID
- RTSP enabled on the Tapo camera
cv2available to the Python environment used for the detector
requirements.txt contains the Python packages used directly by the project:
requests
ultralytics
You also need OpenCV available for Python. On Raspberry Pi OS Bookworm, there are two common approaches:
- Install
opencv-pythoninto the virtual environment - Install
python3-opencvon the system and create the venv with access to system site packages
Before using the detector, create a Camera Account in the Tapo app and assign a username and password for the camera's RTSP access.
Those same camera-account credentials are what you place in the RTSP URL in config.py, for example:
rtsp://username:password@camera_ip_address:554/stream2
Tapo cameras typically expose multiple RTSP streams. In most setups:
stream1is the higher-quality streamstream2is the lower-quality stream and is lighter on the Raspberry Pi
This code has been tested with stream2.
Clone the repository on the Pi to the expected path:
cd /home/pi
git clone https://github.com/saad-git-007/tapo-camera-telegram-alerts.git telegram_porch_detector
cd telegram_porch_detectorCreate the virtual environment and install dependencies:
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txtMake sure OpenCV is available in that same Python environment before running the detector.
Edit config.py and set:
RTSP_URLTELEGRAM_BOT_TOKENTELEGRAM_CHAT_IDTELEGRAM_MESSAGE_THREAD_IDif you use a Telegram topic
You can also tune:
- Face confidence and minimum face size
- YOLO confidence
- Person height threshold
- Person bottom blind-spot filter
- Cooldowns
- Snapshot and video retention
- Detection loop FPS and video recording length
The default detector loop in config.py is conservative for Raspberry Pi use. This project has been tested up to 5 FPS on a Pi 4 with 4 GB RAM. Higher values increased heat and led to thermal throttling in extended runs.
- Open Telegram and search for
@BotFather - Start a chat with
@BotFatherand run the/newbotcommand - Follow the prompts to give your bot a display name and a unique bot username
- BotFather will return a bot token that looks similar to:
123456789:AAExampleTokenHere
- Copy that token into
TELEGRAM_BOT_TOKENinconfig.py - Send a message to your new bot from the Telegram chat where you want alerts to arrive
- Run:
python3 get_chat_id.py- Copy the numeric chat ID printed by the script into
TELEGRAM_CHAT_IDinconfig.py - If you are sending alerts into a Telegram forum topic, also set
TELEGRAM_MESSAGE_THREAD_ID - Optionally test messaging with:
python3 telegram_test.pyStart the detector with:
./start.shThe launcher will:
- Create the snapshot and video directories if needed
- Stop an older detector instance
- Set OpenMP limits to reduce CPU heat on the Pi
- Start
detector.pyand append logs todetector.log
- The camera frame is rotated 90 degrees clockwise before detection and recording. This was done for a Tapo camera mounted in portrait orientation. If your camera is mounted in landscape orientation, comment out the three
cv2.rotate(..., cv2.ROTATE_90_CLOCKWISE)lines indetector.py, currently at lines 294, 355, and 491 - Face model files are downloaded automatically on first run if they are missing
- Package alerts are heuristic alerts, not parcel-specific recognition
temp_logger.shis optional and intended for Raspberry Pi systems that providevcgencmd
If you want the detector to start automatically on boot, run it from a systemd service or a supervised startup script on the Pi. The included start.sh is a good entry point for that setup.