How to Automate Your Chicken Coop Door with OpenClaw on Raspberry Pi
Backyard chicken keepers have relied on timers and light sensors to open and close coop doors for years. This guide adds an AI reasoning layer: wire a motor controller, light sensor, and optional camera to a Raspberry Pi, install OpenClaw as the decision agent, and build a coop door that responds to dawn, dusk, weather conditions, and potential threats rather than following a fixed schedule.
Why a Timer Is Not Enough for Coop Door Automation
Backyard chicken keeping surged during the pandemic and has kept growing. Rising egg prices and avian flu disruptions in commercial supply chains pushed household chicken ownership to roughly 11 million U.S. households by 2024. More chickens in more backyards means more people dealing with the daily chore of opening and closing coop doors at dawn and dusk.
The simplest automation approach is a timer. Set it to open at 6:30 AM and close at 8:00 PM, wire it to a motor, and forget about it. Dozens of Raspberry Pi tutorials cover this exact pattern. The hardware works. The logic does not hold up.
The SmartCoop project, built on a Raspberry Pi Zero 2 W, discovered this firsthand. The team originally used fixed schedules for gate control but found that foxes learned the predetermined opening times and began waiting near the coop before the door opened. SmartCoop adapted by switching to light sensor measurements combined with live weather data, opening and closing the gate based on actual daylight conditions rather than clock times. The system also monitors food and water levels, alerts caregivers when supplies run low, and closes the gate when intruders are detected.
SmartCoop's approach works well for its Java and Pi4J stack, but it is custom-built software that requires you to code every decision branch yourself. OpenClaw offers a different path: instead of writing conditional logic for each scenario, you describe the rules in natural language and let an AI agent handle the reasoning. The agent reads sensor data, checks weather APIs, evaluates camera feeds if available, and decides whether the door should open or close right now. When conditions change, like an unexpected storm at 3 PM or motion detected near the coop after dark, the agent can react without you adding a new if-else block.
The total hardware cost beyond the Pi runs $30-60 depending on your motor choice and whether you add a camera. The intelligence layer is free if you use a cloud LLM with a free tier.
Hardware You Need Beyond the Pi
A chicken coop door controller needs five components beyond the Raspberry Pi itself. Each one serves a specific function in the sensing and actuation loop.
Raspberry Pi 4 or 5 (4GB minimum, 8GB recommended):
OpenClaw supports both models. The Pi 5 with 8GB gives the most headroom for running the agent alongside camera processing. A Pi 4 with 4GB works for a coop door agent since the workload is lighter than continuous video analysis.
Linear actuator or geared DC motor ($15-35):
A linear actuator pushes the door open and pulls it closed in a straight line. A 12V actuator with 50-150mm stroke length handles most coop doors. If your door slides sideways rather than lifting, a geared DC motor with a pulley or rack-and-pinion mechanism works better. Choose based on your door's weight and movement direction. Most backyard coop doors weigh under 2 kg, so you do not need an industrial actuator.
L298N motor controller ($5-12):
An L298N H-bridge module lets the Pi control motor direction and speed through GPIO pins. Connect the L298N's input pins (IN1, IN2) to two GPIO pins on the Pi, such as GPIO 17 (pin 11) and GPIO 18 (pin 12). Setting IN1 HIGH and IN2 LOW drives the motor one direction (door opens). Reversing the signals drives it the other direction (door closes). The L298N accepts 5-35V motor power, so it works with 12V actuators directly. Wire the motor power supply to the L298N's VCC and GND terminals, and connect a shared ground between the L298N and the Pi.
If your actuator has built-in limit switches (many 12V linear actuators do), the motor stops automatically at full extension and retraction. This simplifies control because you do not need to track position precisely.
BH1750 light sensor ($3-8):
A BH1750 digital light sensor communicates over I2C and gives calibrated lux readings, which makes dawn and dusk detection reliable across seasons. Connect SDA to GPIO 2 (pin 3), SCL to GPIO 3 (pin 5), VCC to 3.3V, and GND to ground. A simpler alternative is a photoresistor (LDR) with a voltage divider read through an MCP3008 ADC, but the BH1750 is more consistent and does not need calibration.
Reed switch or limit switches ($2-4):
Mount a magnetic reed switch at the door's closed position. When the door is shut, the magnet holds the switch closed and the Pi reads a LOW signal on the GPIO pin. When the door opens, the switch opens and the pin goes HIGH. This gives the agent a definitive answer about door state without relying on motor timing. Enable the internal pull-up resistor on the GPIO pin in your Python script so readings are clean.
Pi Camera Module (optional, $12-25):
Adding a Camera Module 3 lets the agent visually verify what is happening around the coop. A camera pointed at the door area can detect animals near the entrance, confirm the door actually moved, and capture frames for a remote log. Connect via the CSI ribbon cable. This is optional but valuable if predator pressure is a concern in your area.
Power supply:
The Pi needs its official 5V supply. The linear actuator needs its own 12V supply (a 12V/2A wall adapter works for most small actuators). Do not try to power a 12V motor from the Pi's GPIO pins. Keep the two supplies electrically separate except for a shared ground connection between the Pi and the L298N.
Installing OpenClaw and Writing Coop Control Scripts
With the hardware wired and tested manually (always confirm the motor opens and closes the door correctly before adding software), the next step is installing OpenClaw and creating the Python scripts that handle sensor reads and motor control.
OpenClaw installation:
Follow the official Raspberry Pi installation guide at docs.openclaw.ai/install/raspberry-pi. The process covers flashing 64-bit Raspberry Pi OS, installing Node.js, running the OpenClaw installer, and configuring your preferred LLM backend. Claude and OpenAI are the recommended cloud backends. The agent runs as a systemd service and persists state across reboots in the ~/.openclaw/ directory.
Motor control script:
Create a Python script that accepts commands like "open" and "close." The script sets the appropriate GPIO pins HIGH or LOW through the gpiozero library (pre-installed on Raspberry Pi OS) to drive the L298N in the correct direction. For a linear actuator with limit switches, the script sets the direction and waits for the actuator to reach its endpoint. Add a timeout (10-15 seconds for most actuators) so the script does not hang if a limit switch fails.
Light sensor script:
A second script reads the BH1750 sensor over I2C and returns the current lux value. Dawn typically registers 10-50 lux depending on cloud cover, while full daylight exceeds 10,000 lux. Dusk readings mirror dawn in reverse. The agent calls this script periodically and uses the readings to decide when conditions match "dawn" or "dusk" rather than relying on a clock.
Door state script:
A third script reads the reed switch GPIO pin and returns "open" or "closed." The agent checks this before and after issuing motor commands to confirm the door actually moved.
Camera capture script (optional):
If you installed a Pi Camera, a script using libcamera-still grabs a single JPEG frame for the agent to analyze. The agent can send this frame to a vision-capable LLM to identify animals near the coop, verify door position visually, or document unusual activity.
The OpenClaw agent calls these scripts as system commands. It never touches GPIO registers directly. This separation keeps the agent focused on reasoning (should the door open right now?) while purpose-built scripts handle the hardware interaction. If you swap your actuator for a different model or change your sensor wiring, you update the relevant script without touching the agent's decision logic.
Give Your Coop Agent a Workspace for Logs and Alerts
Fastio's Business Trial includes 50GB storage and included credits. Upload door logs, sensor readings, and camera captures from your Raspberry Pi, then check on your flock from any browser. No credit card required.
Building the Door Logic with OpenClaw
This is where OpenClaw turns a motorized door into a smart one. Instead of a fixed schedule or a simple light threshold, the agent evaluates multiple signals before every open or close decision.
Dawn and dusk detection:
The agent reads the light sensor at regular intervals (every 5-10 minutes is sufficient). When the reading crosses a threshold you define, like 20 lux for "getting light" and 15 lux for "getting dark," the agent considers opening or closing the door. But light level alone is not the only factor.
Weather awareness:
The agent can query a weather API (OpenWeatherMap's free tier provides current conditions and forecasts) before opening the door. Heavy rain, high winds, or an approaching storm might mean the chickens are better off staying inside. You describe this logic in the agent's system prompt: "If wind speed exceeds 50 km/h or heavy rain is forecast within the next hour, delay opening until conditions improve." The agent interprets this and applies it to the current weather data.
Camera-based safety checks:
If a camera is connected, the agent can capture a frame before opening the coop door at dawn. A vision-capable LLM can scan the image for animals near the entrance. While this is not a guaranteed predator detection system (image classification depends on lighting, angle, and model accuracy), it adds a layer of awareness that a timer or light sensor cannot provide. If the agent sees something unusual, it can delay opening and log the event for you to review.
Night lockdown:
After dusk, the agent closes the door and enters a lockdown mode. During lockdown, the door will not open regardless of light changes (like car headlights or a neighbor's floodlight) unless you explicitly override the decision. This prevents false dawn triggers that could leave the coop open at night.
Handling edge cases:
Cloudy mornings produce low, fluctuating lux readings. Rather than opening and closing the door repeatedly as clouds pass, the agent can require a sustained reading above the threshold for 10-15 minutes before acting. If the door fails to close (the reed switch still reads "open" after the close command), the agent can retry once, then send an alert. If someone needs to manually override the door for maintenance or cleaning, the agent logs the manual action and resumes its normal schedule afterward.
Seasonal adaptation:
Dawn and dusk times shift by hours between summer and winter. A timer-based system needs manual adjustment every few weeks. The light sensor approach adapts automatically because it responds to actual conditions rather than clock times. The agent's schedule adjusts with the seasons without any configuration change on your part.
Syncing Coop Data to Fastio for Remote Monitoring
A coop door agent running on a Pi in your backyard generates useful data: door open and close times, light sensor readings, weather conditions at each decision point, camera captures, and any alerts. Storing that data only on the Pi's SD card limits its value. SD cards degrade from continuous writes, the Pi has limited storage, and you cannot check logs from your phone while at work or on vacation.
You have several options for syncing logs off the Pi. A local SQLite database keeps things simple but is only accessible when you SSH into the Pi. Pushing logs to S3 works if you already have AWS infrastructure. Google Drive is convenient but does not offer built-in semantic search across structured log data.
Fastio workspaces give the agent a place to store door logs, sensor readings, and camera captures where both the agent and you can access them from any browser. The Business Trial includes 50GB of storage and 5,000 monthly API credits, which covers months of coop logging with room to spare. The agent connects through the Fastio MCP server, which exposes 19 tools for file operations, workspace management, and AI queries via Streamable HTTP.
What the agent uploads:
- A daily door log with timestamps, lux readings at each open/close event, and the reasoning behind each decision
- Camera snapshots from dawn and dusk checks (and any triggered alerts)
- Weekly summaries with sunrise/sunset trends and anomalies
- Alert records for door failures, unusual motion, or weather overrides
With Intelligence Mode enabled on the workspace, uploaded files are auto-indexed for semantic search. You can ask questions like "when did the door last fail to close?" or "show me camera captures from Monday morning" without writing database queries. This is more useful than searching through raw log files over SSH.
For households where multiple people share coop care, the workspace provides a shared view of coop status. Everyone can see whether the coop is open or closed, when the last event happened, and whether any alerts need attention. Fastio also supports ownership transfer, so if you build this setup for a friend or neighbor, you can hand off the workspace and accumulated data while keeping admin access for troubleshooting.
Weatherproofing, Power, and Seasonal Maintenance
A chicken coop controller runs outdoors, year-round, in conditions that would destroy most consumer electronics. Treat weatherproofing and power reliability as part of the build, not an afterthought.
Enclosure:
Mount the Raspberry Pi, motor controller, and wiring inside a weatherproof junction box (IP65 rated or better). Run sensor and motor cables through cable glands to keep moisture out. The BH1750 light sensor needs exposure to ambient light, so mount it outside the enclosure under a small transparent cover that blocks rain but allows light through. A section of clear acrylic glued over a hole in the enclosure works well.
Power reliability:
A power outage with the coop door open at night is a predator invitation. A small Pi-compatible UPS ($15-25) provides 15-30 minutes of backup power, enough to close the door and shut down the Pi gracefully. If your area has frequent outages, consider a larger battery backup or a solar panel with a charge controller. The 12V motor supply can run directly from a 12V battery, and a buck converter steps it down to 5V for the Pi.
If the Pi loses internet, the agent cannot reach cloud LLM APIs. Build in a fallback: a simple Python script that the systemd service runs as a backup, opening the door when light exceeds a threshold and closing it when light drops below. When connectivity returns, the agent resumes normal operation and uploads any queued logs.
Cold weather:
Below-freezing temperatures can affect electronics and mechanical components. Linear actuators rated for outdoor use handle cold well, but cheaper indoor models may seize. Check your actuator's operating temperature range. The Pi itself is rated down to 0C officially, though many users run them colder inside insulated enclosures. Condensation is a bigger risk than cold in most climates. Add silica gel packets inside the enclosure and replace them seasonally.
Mechanical maintenance:
If your coop door swells in humid months or sticks in winter, the actuator may struggle. The agent can detect this when the door state does not change within the expected timeframe after a motor command. Periodic lubrication of the door track and actuator pivot points prevents most mechanical issues.
Predator-proofing the door itself:
The smartest agent cannot compensate for a flimsy door. Use hardware cloth (not chicken wire, which predators can tear through), a solid door panel, and a latch mechanism that the actuator engages when closed. The reed switch confirms the latch is seated. Physical security and AI awareness work together: the agent decides when to lock down, and the hardware makes sure the lockdown actually keeps predators out.
Frequently Asked Questions
How do I automate my chicken coop door with Raspberry Pi?
Connect a 12V linear actuator to your coop door and wire it through an L298N motor controller to two GPIO pins on the Pi. Add a light sensor (BH1750 on I2C) for dawn and dusk detection and a reed switch for door position feedback. Write Python scripts using gpiozero to control the motor and read sensors. For basic automation, a simple light threshold script works. For AI-driven decisions that account for weather and visual safety checks, install OpenClaw as the reasoning layer on top.
Can AI detect predators near a chicken coop?
A Pi Camera connected to a vision-capable LLM can identify animals in captured frames, adding a layer of awareness beyond what timers or light sensors provide. The agent captures a frame before opening the door at dawn, sends it for analysis, and delays opening if something unusual appears. This is not a replacement for physical predator-proofing (hardware cloth, solid latches, secure enclosures), but it provides an early warning system and a visual record of activity around the coop.
What sensors does a smart chicken coop need?
At minimum, a light sensor (BH1750 or photoresistor) for dawn and dusk detection and a reed switch for door position confirmation. Useful additions include a temperature and humidity sensor (DHT22 or BME280) for climate monitoring, a water level sensor for the waterer, and a Pi Camera for visual verification. The SmartCoop project also uses weight sensors for feed monitoring and motor encoders for precise door positioning.
Can OpenClaw run on a Raspberry Pi for coop automation?
Yes. OpenClaw runs on Raspberry Pi 4 (4GB) and Pi 5 (4/8GB) with 64-bit Raspberry Pi OS. It accesses GPIO through Python scripts using libraries like gpiozero and Adafruit Blinka. The agent handles decision logic while Python scripts manage hardware interaction. Cloud LLM backends (Claude, OpenAI) handle the reasoning since local models are too slow on Pi hardware.
How much does a Raspberry Pi chicken coop door controller cost?
The hardware beyond the Pi costs $30-60. That covers a 12V linear actuator ($15-35), an L298N motor controller ($5-12), a BH1750 light sensor ($3-8), a reed switch ($2-4), and a weatherproof enclosure ($5-10). A Raspberry Pi 4 with 4GB runs about $55, or $80 for a Pi 5 with 8GB. Adding a Pi Camera adds $12-25. The total ranges from $100-170 depending on component choices.
Related Resources
Give Your Coop Agent a Workspace for Logs and Alerts
Fastio's Business Trial includes 50GB storage and included credits. Upload door logs, sensor readings, and camera captures from your Raspberry Pi, then check on your flock from any browser. No credit card required.