How to Build a Package Delivery Detection Agent with OpenClaw on Raspberry Pi
Guide to openclaw raspberry package delivery detection mailbox agent: Porch piracy costs consumers billions every year, and commercial smart mailboxes run $150 to $400. This guide builds a smarter alternative for under $40: a Raspberry Pi with an ultrasonic sensor and camera, powered by an OpenClaw agent that distinguishes real deliveries from false triggers and sends photo-verified alerts to your phone.
Why Package Detection Needs an AI Layer
An estimated 49 million Americans had packages stolen in 2023, costing consumers roughly $12 billion in losses according to Security.org's annual package theft report. The problem is straightforward: packages sit unattended on porches for hours between delivery and pickup, and opportunistic theft is easy and rarely prosecuted.
Commercial solutions exist. The eufy SmartDrop is a locked delivery box with a built-in camera priced at $399. Ring and other doorbell cameras record footage but cannot distinguish a delivery from a passing pedestrian, a neighbor's cat, or wind blowing leaves across the porch. You get dozens of motion alerts per day and learn to ignore them, which defeats the purpose.
A Raspberry Pi with a $3 ultrasonic distance sensor and a $15 camera module can detect when a new object appears in a monitored zone. That is the hardware side. The intelligence gap is what happens next. A basic script triggers on every distance change, which means rain, animals, and shifting shadows all generate false alerts. An OpenClaw agent running on the same Pi adds a reasoning layer: it can compare the current distance reading against a baseline, request a photo when the change persists for more than a few seconds, analyze the image to confirm whether a package is actually present, and send a single verified notification instead of a stream of false positives.
The total hardware cost for this build is under $40 if you already have a Raspberry Pi. Even starting from scratch with a Pi Zero 2 W ($15), an HC-SR04 ultrasonic sensor ($2-3), a USB camera ($10-15), and a weatherproof enclosure ($5-10), you stay well under $50. Compare that to the $150-400 range for commercial smart mailbox products that lack the AI reasoning component entirely.
What to check before scaling openclaw raspberry pi package delivery detection mailbox agent
The build uses three main components: a Raspberry Pi for compute, an ultrasonic distance sensor for detection, and a camera for visual confirmation. Here is what you need and why each piece matters.
Raspberry Pi selection
Any Pi model with Wi-Fi works. The Raspberry Pi Zero 2 W ($15) is the most compact and power-efficient option, drawing around 0.4W idle and 1W under load. Its quad-core Cortex-A53 processor handles OpenClaw's agent runtime without issues since the LLM inference happens via API calls, not on the Pi itself. If you already have a Pi 4 or Pi 5, those work equally well but draw more power (3-5W), which matters if you plan to run on battery or solar.
Ultrasonic distance sensor (HC-SR04)
The HC-SR04 measures distance by sending an ultrasonic pulse and timing the echo. It detects objects from 2 cm to 400 cm with roughly 3 mm accuracy, though reliable readings fall in the 10-250 cm range. At $2-3 from most electronics retailers, it is one of the cheapest sensors you can buy. For a mailbox or porch mount, you point the sensor downward at the delivery surface. When the measured distance drops (because a package now occupies the space), the agent knows something arrived.
Important: the original HC-SR04 runs on 5V logic, but the Pi's GPIO pins are 3.3V. You need a voltage divider on the Echo pin to avoid damaging the Pi. Two resistors (1K and 2K ohm) form the divider. Newer 3.3V-compatible versions of the HC-SR04 exist (sometimes labeled HC-SR04P) and skip this requirement entirely. Check which version you have before wiring.
Wiring the HC-SR04
- VCC to 5V (pin 2)
- GND to ground (pin 6)
- Trig to GPIO 23 (pin 16)
- Echo to GPIO 24 (pin 18) through a voltage divider: connect a 1K resistor from the Echo pin to GPIO 24, and a 2K resistor from GPIO 24 to ground
Camera module
A USB webcam ($10-15) is the simplest option. OpenClaw on Raspberry Pi supports USB cameras for image capture. The Pi Camera Module 3 ($25) offers better image quality and connects via the CSI ribbon cable, but a basic USB webcam is sufficient for confirming whether a box is sitting on your porch.
Position the camera to capture the same zone the ultrasonic sensor monitors. For a mailbox mount, angle it downward at the package landing area. For a porch setup, mount it at waist height looking at the delivery zone.
Power supply
A standard 5V/2.5A USB power supply works for a permanent installation near an outlet. For remote mailboxes without power, a 10,000 mAh USB power bank provides 20-40 hours of runtime on a Pi Zero 2 W, depending on how frequently the camera activates. A small 6W solar panel with a charge controller can sustain indefinite operation if the mailbox gets a few hours of sunlight.
Weatherproofing and Physical Installation
Electronics and rain do not mix. Your Pi, sensor, and camera all need protection from moisture, temperature swings, and direct sunlight.
Enclosure options
An IP65-rated plastic junction box ($5-8 from hardware stores) is the simplest enclosure. Cut holes for the ultrasonic sensor's transmitter and receiver, the camera lens, and a cable grommet for power. Seal the edges with silicone caulk. The sensor needs a direct line of sight to the delivery surface, so its openings cannot be covered with glass or plastic (ultrasonic pulses will bounce off the cover instead of the target).
For the camera, a small glass or clear acrylic window works. UV-resistant acrylic holds up better than standard acrylic over months of sun exposure. Apply a thin layer of Rain-X or similar hydrophobic coating to keep the lens window clear during rain.
Preventing condensation
Temperature changes cause condensation inside sealed enclosures. Two approaches help: a small packet of silica gel desiccant inside the box (replace monthly), or a pressure equalization vent (sometimes called a Gore-Tex vent or breather plug) that allows air pressure to equalize while blocking water. Industrial enclosure suppliers sell these for $2-3 each.
Sensor placement
Mount the HC-SR04 pointing straight down at the delivery surface. For a standard mailbox, mount it inside the lid or top panel. The sensor works best when the target surface is flat and perpendicular to the sensor beam. Angled surfaces scatter the ultrasonic pulse and reduce accuracy. If your mailbox floor is uneven, place a flat piece of cardboard or foam board as a baseline surface.
Measure and record the baseline distance (sensor to empty floor) during setup. The OpenClaw agent uses this baseline to detect changes. If the mailbox floor is 30 cm below the sensor and a package reduces that to 15 cm, the agent registers a 15 cm change. Set the detection threshold to at least 3-5 cm to avoid false triggers from temperature-related sensor drift.
Mounting the camera
Position the camera to see the full delivery surface. For porch mounting, consider adding a small LED that the agent can trigger for night shots. A standard 3mm white LED on a GPIO pin with a 220-ohm resistor draws minimal power and provides enough light for a camera capture at close range.
Store and Search Your Delivery Logs in One Place
Fastio gives your OpenClaw agent 50 GB of free cloud storage with built-in AI search. Upload delivery photos, query your history by date or carrier, and share access with your household. No credit card required. Built for openclaw raspberry package delivery detection mailbox agent workflows.
Configuring the OpenClaw Detection Agent
With hardware installed, the next step is configuring OpenClaw to poll the sensor, evaluate readings, and decide when to alert you.
How the detection logic works
The agent runs a polling loop that reads the ultrasonic sensor at regular intervals. When the measured distance drops below the baseline by more than your configured threshold (say, 5 cm), the agent does not immediately fire an alert. Instead, it waits a few seconds and takes a second reading to confirm the change is persistent, not caused by a bird landing briefly or a gust of wind pushing debris through the sensor beam.
If the change persists, the agent triggers a camera capture. The captured image goes to the LLM for analysis. The prompt asks a specific question: "Is there a package, envelope, or delivery box visible in this image?" The LLM responds with a yes/no assessment and a brief description of what it sees. Only confirmed deliveries generate a notification.
This two-stage approach (distance change confirmed by visual verification) cuts false positives dramatically compared to motion-only detection systems. A doorbell camera triggers on every passing car. This system only triggers when an object is physically present in the monitored zone and visually confirmed as a delivery.
Polling frequency and power management
For a mains-powered setup, polling every 5-10 seconds provides responsive detection without excessive API calls. Each distance measurement takes microseconds. Camera captures and LLM analysis only happen when the distance threshold trips, so you might process 2-3 images per day rather than hundreds.
For battery-powered installations, reduce polling to every 30-60 seconds or use an interrupt-driven approach. Some HC-SR04 wrapper libraries support threshold-based interrupts, though most Pi implementations use polling. The power savings between 5-second and 30-second polling are modest on a Pi Zero since the idle draw dominates.
Notification delivery
OpenClaw supports multiple notification channels. The agent can send alerts through Telegram, WhatsApp, Discord, Slack, or email. For package delivery alerts, a Telegram or push notification works well because you see the photo confirmation immediately on your phone. The notification includes the captured image, the LLM's assessment, and a timestamp.
Configure your preferred channel through OpenClaw's notification settings. Telegram is the most common choice for Pi-based agents because the Telegram Bot API is free, reliable, and does not require a phone number tied to the agent.
Handling edge cases
The agent should account for several real-world scenarios:
- Pickup detection: when you retrieve the package, the distance returns to baseline. The agent can log this as "package collected" and stop sending reminders
- Multiple deliveries: if a second package arrives on top of the first, the distance changes again. The agent re-captures and sends a new notification
- Weather interference: rain hitting the sensor can cause erratic readings. The confirmation delay and visual verification handle most weather noise, but persistent heavy rain may require temporarily increasing the confirmation window
- Night detection: the ultrasonic sensor works in complete darkness (sound, not light), so distance detection is unaffected. Camera captures need ambient light or the LED described in the installation section
Logging Deliveries and Building a History
A delivery detection agent generates useful data over time: when packages arrive, how long they sit before pickup, which carriers deliver at what times, and seasonal patterns. Logging this data turns a simple alert system into a delivery management tool.
Local logging
The simplest approach stores delivery events as JSON lines in a file on the Pi's SD card. Each entry records the timestamp, distance reading, image filename, LLM assessment, and notification status. This works for personal use but has obvious limits: SD cards fail, storage is finite, and the data is only accessible if you SSH into the Pi.
Cloud logging with Fastio
For persistent, accessible delivery logs, the agent can upload capture images and event data to a Fastio workspace. Each delivery event becomes a file (the photo) with metadata (timestamp, assessment, sensor reading) stored in a structured workspace folder.
Fastio's Business Trial provides 50 GB of storage, 5,000 monthly API credits, and 5 workspaces with no credit card and no expiration. That is enough for years of delivery photos. The agent authenticates through the Fastio MCP server and uploads images as they are captured.
The practical benefit goes beyond storage. Fastio workspaces support Intelligence Mode, which auto-indexes uploaded files for semantic search. After a few months of logged deliveries, you can ask questions like "show me all deliveries from the last two weeks" or "when did the large box arrive last Tuesday" and get answers with citations pointing to specific photos and timestamps.
Sharing access
If multiple household members need delivery visibility, share the workspace through Fastio's branded share links. Each person sees the delivery log and photos through a web interface without needing SSH access to the Pi. Permissions are granular: you can give view-only access to household members while keeping admin control yourself.
Alternatives for logging
Local SQLite databases work for simple event logging without cloud connectivity. InfluxDB paired with Grafana provides a dashboard for tracking delivery frequency over time. Google Sheets (via the Sheets API) is another lightweight option for logging structured data from the Pi. Fastio's advantage is combining storage, search, and sharing in one platform that the OpenClaw agent can access through a single MCP connection.
Extending the Agent Beyond Basic Detection
Once the core detection loop works, the OpenClaw agent can handle increasingly sophisticated tasks without any hardware changes.
Carrier identification
The same camera image that confirms a package can identify the carrier. USPS, UPS, FedEx, and Amazon boxes have distinct branding. The LLM prompt can ask "which carrier delivered this package based on visible logos or box markings?" This data is useful for tracking delivery patterns and correlating with tracking numbers.
Theft deterrence
If the agent detects a package arrival and then detects removal before you marked it as collected, it can flag the event as potential theft. Combined with a camera that captures the removal, you have timestamped photo evidence. The agent can send an urgent alert ("Package removed, not by you") and save the removal photo to your Fastio workspace as a time-stamped record.
Multi-zone monitoring
A single Pi can drive multiple ultrasonic sensors on different GPIO pins. Monitor the front porch and back door simultaneously, or add a sensor inside the mailbox for letter mail alongside the porch sensor for packages. Each sensor gets its own baseline and threshold in the agent's configuration.
Integration with tracking APIs
If you forward shipping confirmation emails to a monitored inbox, the agent can cross-reference expected deliveries with actual detections. "You had a FedEx delivery expected today, and a FedEx box was detected at 2:34 PM" provides much richer context than a bare motion alert.
Seasonal adjustments
Temperature affects ultrasonic sensor accuracy because the speed of sound changes with air temperature. At 0 degrees Celsius, sound travels at 331 m/s. At 30 degrees Celsius, it travels at 349 m/s, a 5% difference. For a 30 cm baseline, this translates to roughly 1.5 cm of drift. The agent can read a temperature sensor (or use a weather API) and apply a correction factor, or widen the detection threshold during temperature extremes.
Battery monitoring
For solar or battery-powered installations, the agent can monitor its own power supply. A simple voltage divider on an ADC (like the MCP3008, around $4) lets the agent read battery voltage and warn you when it drops below a safe threshold. This prevents the agent from going offline silently when the battery dies.
Frequently Asked Questions
How do you detect package delivery with Raspberry Pi?
Mount an HC-SR04 ultrasonic distance sensor pointing at the delivery surface and measure the distance at regular intervals. When a package arrives, the measured distance drops. An OpenClaw agent running on the Pi confirms the detection by capturing a camera image and analyzing it with an LLM before sending a notification. This two-stage approach eliminates most false positives from motion-only systems.
Can AI tell the difference between mail and packages?
Yes. When the ultrasonic sensor triggers a camera capture, the LLM can analyze the image and describe what it sees, including size estimates, carrier logos, and whether the object looks like a letter envelope or a box. It is not perfect at precise size measurement from a single camera angle, but it reliably distinguishes a flat envelope from a box.
What is the cheapest smart mailbox solution?
A Raspberry Pi Zero 2 W ($15), HC-SR04 ultrasonic sensor ($2-3), and a USB webcam ($10-15) total under $40 and provide both detection and visual confirmation. Commercial alternatives like the eufy SmartDrop start at $399. The Pi solution also adds AI reasoning for filtering false alarms, which commercial products do not offer.
Does the ultrasonic sensor work at night or in rain?
The HC-SR04 uses sound waves, not light, so it works in complete darkness. Rain can cause erratic readings if drops hit the sensor face directly. A recessed mount or small rain shield over the sensor helps. The OpenClaw agent's confirmation delay and visual verification handle most weather-related noise in the sensor data.
How long does the battery last on a Raspberry Pi package detector?
A Pi Zero 2 W draws roughly 0.4-1W depending on activity. A 10,000 mAh USB power bank provides approximately 20-40 hours of continuous operation. A small 6W solar panel with a charge controller sustains indefinite runtime with a few hours of daily sunlight. Mains power via a USB adapter is the simplest option for porch installations near an outlet.
Can one Raspberry Pi monitor multiple delivery zones?
Yes. The Pi has enough GPIO pins for several HC-SR04 sensors, each monitoring a different zone (front porch, back door, mailbox). Configure each sensor with its own baseline distance and detection threshold in the OpenClaw agent. A single camera can serve multiple zones if mounted with a wide enough field of view, or add USB cameras for separate coverage.
Related Resources
Store and Search Your Delivery Logs in One Place
Fastio gives your OpenClaw agent 50 GB of free cloud storage with built-in AI search. Upload delivery photos, query your history by date or carrier, and share access with your household. No credit card required. Built for openclaw raspberry package delivery detection mailbox agent workflows.