AI & Agents

Build a Smart Home Security Alarm System with OpenClaw on Raspberry Pi

DIY alarm kits from Ring and SimpliSafe start at $130 to $250 for equipment, then tack on $25 to $33 per month in monitoring fees that never stop. A Raspberry Pi alarm system built with Home Assistant for automation and OpenClaw for natural language control costs roughly $140 in one-time hardware and zero in monthly charges. This guide covers the full build: sensor wiring, alarm panel configuration, OpenClaw integration, and persistent config storage.

Fastio Editorial Team 18 min read
AI agent interface for managing shared workspace files and automation configs

The Real Cost of Home Security

NerdWallet's 2026 home security pricing survey puts DIY starter kits from Ring, SimpliSafe, and ADT at $130 to $269 for equipment. Professional monitoring adds $25 to $33 per month on top of that. In year one alone, you are looking at $430 to $665, and the monitoring bill keeps running. Over five years, monitoring alone costs $1,500 to $2,000 for a service that mostly sends you phone notifications when a sensor trips.

A Raspberry Pi 4 with a handful of sensors, a relay module, and a 12V siren runs about $140 total. No monthly fees. No contract. The system operates on your local network, talks to nothing in the cloud unless you want it to, and Home Assistant handles the alarm logic that commercial providers charge you monthly to run on their servers.

The missing piece in most DIY alarm projects is the interface. You either get a raw web dashboard, a terminal script, or a physical keypad wired to more GPIO pins. OpenClaw fills that gap. Running as a gateway on the same Pi, it gives you a natural language layer over the entire alarm system. "Arm the house, I'm leaving for work." "Are all the windows closed?" "What triggered the alarm at 2 AM?" The Pi handles the gateway while a cloud LLM processes the language. Your total power draw stays under 5 watts at idle, which costs a few dollars per year in electricity.

The Raspberry Pi blog describes this isolation benefit directly: "Running OpenClaw on a standalone device like a Raspberry Pi is a great way to mitigate security concerns" compared to installing it on your primary computer. For an always-on alarm system, a dedicated Pi makes more sense than repurposing a laptop.

This guide walks through the complete build: hardware selection, sensor wiring, Home Assistant alarm panel setup, OpenClaw configuration, and storing your alarm configs in a workspace that survives SD card failures.

Hardware Bill of Materials

Every component here is available from standard electronics retailers. Prices reflect May 2026 listings and include the DRAM-driven price increases that hit Raspberry Pi boards earlier this year.

Raspberry Pi 4 Model B (4GB RAM): ~$100

The OpenClaw installation documentation lists the Pi 4 with 4GB as the "sweet spot" for running the gateway. It has enough RAM for both Home Assistant (running as a Docker container) and the OpenClaw gateway simultaneously. The Pi 5 is faster but starts at $65 for the 2GB model and $120 for 4GB after 2026 price adjustments. If you already own a Pi 5, use it. If you are buying new, the Pi 4 4GB offers the best value for this project.

MicroSD card (32GB) or USB SSD: ~$8 to $25

A 32GB microSD card works for getting started. For a system running 24/7, a USB SSD via a SATA-to-USB adapter is more reliable. SD cards wear out from constant writes, and losing your alarm system to a dead card at 3 AM defeats the purpose.

USB-C power supply (15W): ~$10

Use the official Raspberry Pi power supply or a quality third-party 5V/3A adapter. Underpowered supplies cause random reboots, which is the last thing you want from an alarm controller.

HC-SR501 PIR motion sensors (x2): ~$8

The HC-SR501 is a passive infrared sensor that detects body heat within a roughly 7-meter range at a 120-degree cone. Two sensors cover a main hallway and a ground-floor room. Each one has three pins: VCC (5V), GND, and a digital output that goes HIGH when motion is detected. They cost about $4 each from PiShop, Adafruit, or Amazon.

Magnetic reed switches (x3): ~$6 to $9

Reed switches detect whether doors and windows are open or closed. Each switch is two pieces: a wired sensor and a magnet. When the magnet separates from the sensor (door opens), the circuit breaks. A pack of five costs $6 to $9 on Amazon. Mount them on your front door, back door, and a ground-floor window.

2-channel relay module: ~$5 to $7

The Pi's GPIO pins cannot safely drive a 12V siren directly. A relay module acts as a switch: the Pi sends a low-current signal to the relay, and the relay switches the siren's 12V power circuit. A 2-channel module gives you one relay for the siren and a spare for a strobe light or secondary alert device.

12V piezo siren and 12V DC adapter: ~$15 to $20

Indoor piezo sirens rated at 110 to 120 dB are available for $8 to $12. Add a 12V/1A DC power adapter for $5 to $8. The siren's positive wire gets cut and routed through the relay's COM and NO (normally open) terminals. When the relay activates, the circuit closes and the siren sounds.

Breadboard and jumper wires: ~$5 to $8

For prototyping the sensor connections before you commit to soldering. A half-size breadboard and a pack of male-to-female jumper wires are enough.

Total: approximately $140 to $150

If you already own a Raspberry Pi and a power supply, the sensor and siren components alone run about $35 to $45. That puts a complete alarm system within reach of most hobbyist budgets.

How to Wire PIR Sensors and a Siren to Raspberry Pi GPIO

The physical wiring is straightforward. Each sensor connects to a GPIO pin on the Pi, and the relay module controls the siren. You do not need any custom PCBs or specialized HATs for a basic alarm setup, though the Pimoroni Automation HAT is a good option if you want screw terminals instead of breadboard jumpers.

PIR sensor connections

The HC-SR501 has three pins on its header. Connect them as follows:

  • VCC pin to the Pi's 5V power (physical pin 2 or 4)
  • GND pin to the Pi's ground (physical pin 6, 9, 14, or any GND pin)
  • OUT (data) pin to a GPIO input, such as GPIO 17 (physical pin 11) for the first sensor and GPIO 27 (physical pin 13) for the second

The sensor outputs 3.3V when motion is detected, which the Pi reads as a digital HIGH. The two trimpots on the back of the HC-SR501 control sensitivity (detection range) and delay time (how long the output stays HIGH after detection). Start with both at their midpoint and adjust after testing. High sensitivity in a room with pets will generate false triggers.

Reed switch connections

Magnetic reed switches are simple open/close circuits. Each switch needs two wires:

  • One wire to a GPIO input pin (GPIO 22, 23, or 24 for three switches)
  • The other wire to ground

Enable the Pi's internal pull-up resistor for each GPIO pin in your sensor script. When the door is closed and the magnet is near the sensor, the circuit completes and the pin reads LOW. When the door opens and the magnet separates, the pin floats HIGH through the pull-up resistor. This is a clean, reliable signal that requires no external resistors or components.

Relay and siren wiring

The relay module takes three connections from the Pi:

  • VCC to the Pi's 5V power
  • GND to the Pi's ground
  • IN1 (input for channel 1) to a GPIO output pin, such as GPIO 18 (physical pin 12)

For the siren circuit, cut the siren's positive (red) wire and connect one end to the relay's COM (common) terminal and the other end to the NO (normally open) terminal. When GPIO 18 goes HIGH, the relay closes, the 12V circuit completes, and the siren sounds. When the pin goes LOW, the relay opens and the siren stops.

Testing the wiring

Before configuring Home Assistant, test each sensor individually. A short Python script using the gpiozero library can read each pin and print its state to the terminal. Wave your hand in front of a PIR sensor and confirm the output goes HIGH. Open a door with a reed switch and confirm the pin state changes. Trigger the relay and verify the siren activates. Fix any wiring issues now, because debugging GPIO problems through Home Assistant's abstraction layer is much harder.

Mount PIR sensors at chest height (about 1.2 meters) and angled slightly downward for the best detection coverage. Reed switches go on the frame side of the door or window, with the magnet on the moving part. Use double-sided tape for testing and screws for permanent installation.

Fastio features

Store Your Alarm Configs Where a Dead SD Card Cannot Reach Them

Fastio workspaces give your Pi alarm system a backup layer for HA automations, sensor scripts, and OpenClaw configs. generous storage, no credit card, MCP-ready for your agent to read and write directly.

How to Configure Home Assistant as the Alarm Controller

Home Assistant turns your collection of GPIO sensors into a proper alarm system with armed states, trigger logic, and notification routing. You will install it as a container on Raspberry Pi OS so the host system retains direct GPIO access for the sensor bridge script.

Installing Home Assistant Container

Flash Raspberry Pi OS Lite (64-bit) to your SD card or SSD using Raspberry Pi Imager. Boot the Pi, connect via SSH, and install Docker. Then pull the Home Assistant container image and start it with host networking enabled. The HA web interface becomes available at port 8123 on your Pi's IP address. Walk through the onboarding wizard to create your admin account and set your time zone.

Setting up the MQTT broker

Install Mosquitto as a standalone MQTT broker on the Pi. MQTT acts as the message bus between your sensor script and Home Assistant. The sensor script publishes state changes (motion detected, door opened) to MQTT topics, and Home Assistant subscribes to those topics to update its entity states.

Add the MQTT integration in Home Assistant's settings, pointing it to localhost on the default MQTT port. Once connected, HA auto-discovers devices that publish with the standard HA MQTT discovery format.

The sensor bridge script

Write a small Python script that runs as a systemd service on the Pi. The script uses gpiozero to monitor each sensor pin and paho-mqtt to publish state changes. When PIR sensor 1 detects motion, the script publishes ON to home/alarm/motion/hallway. When the front door reed switch opens, it publishes ON to home/alarm/door/front. Home Assistant picks up these messages and updates the corresponding binary sensor entities.

This decoupled architecture has a real advantage: if Home Assistant restarts or crashes, the sensor bridge keeps running and queues messages. If the bridge restarts, Home Assistant still holds the last known state. Neither component depends on the other being continuously available.

Configuring the alarm panel

Home Assistant includes a built-in alarm control panel integration that supports four armed states: armed_home, armed_away, armed_night, and disarmed. You can configure it through the HA UI or YAML. The panel tracks which state the alarm is in and provides a PIN code for disarming.

Create automations that connect your sensors to the alarm panel:

  • When the alarm is in "armed_away" and any PIR sensor or reed switch triggers, set the alarm state to "triggered" and activate the siren relay via an MQTT publish to the relay control topic
  • When the alarm is in "armed_home," only trigger on door and window sensors (ignore motion, since you are home and walking around)
  • When the alarm is "armed_night," trigger on door sensors and ground-floor motion, but ignore upstairs motion
  • Add a 30-second entry delay for the front door so you have time to disarm after walking in
  • Add a notification action that sends an alert to your phone via the Home Assistant Companion app, Telegram, or email

This gives you a fully functional, zone-aware alarm system with no monthly monitoring fee. The automation runs locally on the Pi, with no cloud dependency for the core alarm logic.

Layered system architecture showing sensor inputs and alarm control hierarchy

Adding OpenClaw for Natural Language Alarm Control

With the alarm system running on Home Assistant, OpenClaw adds the ability to arm, disarm, and query the system through plain conversation instead of tapping through the HA dashboard or remembering PIN codes on a keypad.

Installing OpenClaw on the Pi

The OpenClaw installation documentation specifies minimum requirements of 1GB RAM, one CPU core, 500MB free disk space, and a 64-bit OS. Your Pi 4 with 4GB and Raspberry Pi OS 64-bit exceeds these comfortably. The official install script handles the setup. OpenClaw's gateway process runs locally on the Pi while routing language processing to a cloud LLM provider of your choice (Anthropic, OpenAI, Google, or others). You will need an API key from your chosen provider.

After installation, run the onboard command to configure the gateway as a background daemon. The OpenClaw documentation recommends adding 2GB of swap space on devices with 4GB RAM or less to handle peak memory loads when both HA and the gateway are active simultaneously.

Connecting to Home Assistant

The connection between OpenClaw and Home Assistant uses a community-built Home Assistant skill available in the OpenClaw skills registry. This skill communicates with HA through its REST API, requiring two configuration values: the Home Assistant URL (typically the Pi's localhost address on port 8123) and a Long-Lived Access Token.

Create the access token in Home Assistant by navigating to your user profile and scrolling to the Long-Lived Access Tokens section. Generate a token, name it something identifiable like "OpenClaw Alarm," and copy it immediately. HA only displays the token once. For better security, create a separate HA user account with access restricted to the alarm panel and sensor entities, then generate the token from that limited account.

Once the skill is installed and configured, verify the connection by asking the agent a simple question about your alarm state: "Is the alarm armed?" or "What is the front door sensor status?" If the skill is working, the agent queries HA entities and returns real data.

Practical alarm commands

With the integration running, you interact with the alarm system through conversation:

  • "Arm the house, we're going out" triggers the HA alarm panel to enter armed_away mode
  • "Set the alarm to night mode" activates armed_night, which monitors doors and ground-floor motion while ignoring upstairs sensors
  • "Disarm the alarm" takes the system out of armed state
  • "Which sensors are currently triggered?" queries all binary sensor entities and returns a summary
  • "What happened last night?" can pull the HA event log for alarm-related events

The value over a traditional keypad or app is contextual interaction. If the agent reports that the back door sensor is open, you can follow up with "close the back door alert and rearm" without navigating to a different screen. If a sensor keeps false-triggering, you can ask "how many times has the hallway PIR triggered today?" and decide whether to adjust the sensitivity or exclude it from the night mode automation.

Security considerations

Running an AI agent with access to your alarm system requires attention to security. Bind the OpenClaw gateway to localhost only so it is not accessible from other devices on your network. Set a gateway authentication token. Keep OpenClaw updated, because security researchers identified thousands of exposed instances in early 2026 running with default credentials. The same caution applies to the HA skills registry: install only the specific skills you need and review their source code. A February 2026 investigation found malicious skills in the ClawHub marketplace.

AI interface querying and summarizing system activity events

Persisting Alarm Configs in a Central Workspace

An alarm system that lives entirely on one Pi's SD card has a single point of failure. SD cards degrade from constant writes, and when yours dies at month eight, you lose your Home Assistant automations, OpenClaw skill configs, sensor calibration notes, and the MQTT topic map you spent an afternoon getting right.

Fastio workspaces solve this by giving you a shared storage layer that both humans and AI agents can access. Create a workspace for your alarm project, upload your HA automation exports, sensor wiring documentation, and OpenClaw configuration files. The Business Trial includes 50GB of storage, included credits per month, and 5 workspaces with no credit card required.

A practical setup: export your Home Assistant alarm automations as YAML and upload them to the workspace after each change. Store your sensor bridge Python script there as well. If the SD card fails, you flash a new one, reinstall the stack, and pull your configs from the workspace instead of rebuilding from memory.

Fastio's MCP server means your OpenClaw agent can interact with the workspace directly through the same Model Context Protocol interface it uses for Home Assistant. The agent can upload alarm event logs, download configuration templates, or search workspace files. Enable Intelligence Mode on the workspace and your files are automatically indexed for semantic search, so you can ask the agent "What GPIO pin is the hallway PIR connected to?" and get an answer grounded in your actual documentation, not a guess.

For households where more than one person manages the smart home, Fastio's granular permissions control who can read or edit alarm configs. The audit trail tracks every change, so you can see who modified an automation and when. If you expand to a second property with its own Pi, both alarm systems can pull from the same workspace to stay synchronized.

The alternative is scattering configs across the Pi's filesystem, a Google Drive folder, and a chat thread. That approach works until someone reformats the SD card or the chat history scrolls past the message with the GPIO pinout. A central workspace that both humans and agents can access eliminates that fragility. When an agent builds a new alarm configuration, ownership transfer lets you hand the workspace off to whoever will maintain the system long-term.

Frequently Asked Questions

Can I build a home security system with Raspberry Pi?

Yes. A Raspberry Pi 4 or Pi 5 can run Home Assistant as the alarm controller, read PIR motion sensors and magnetic reed switches through its GPIO pins, and drive a siren through a relay module. The total hardware cost is roughly $140 to $150. You get armed states, zone-based automation, phone notifications, and entry delays without any monthly monitoring fee.

How do I connect motion sensors to Raspberry Pi?

The HC-SR501 PIR sensor has three pins: VCC connects to the Pi's 5V power pin, GND connects to any ground pin, and the data output connects to a GPIO input pin like GPIO 17. The sensor outputs 3.3V (digital HIGH) when it detects body heat. Use the gpiozero Python library to read the pin state, or publish sensor events to an MQTT broker so Home Assistant can track them as binary sensor entities.

Can OpenClaw control home security devices?

OpenClaw connects to Home Assistant through a community-built skill that uses the HA REST API. Once configured, you can arm and disarm the alarm, check sensor states, trigger automations, and query event logs through natural language commands. OpenClaw handles the language interface while Home Assistant handles the actual device control and automation logic.

What is the cheapest DIY home alarm system?

A Raspberry Pi-based alarm system is one of the cheapest options with real automation capabilities. The Pi itself costs $45 to $100 depending on the model, and sensors, a relay, and a siren add another $35 to $45. The total stays under $150 with no recurring fees. Commercial DIY kits from Ring and SimpliSafe start at $130 to $250 for equipment, then add $25 to $33 per month for monitoring.

Do I need a separate server for Home Assistant?

No. Home Assistant runs as a Docker container on the same Raspberry Pi that hosts OpenClaw and reads your sensors. A Pi 4 with 4GB RAM handles both workloads comfortably. For larger smart home setups with dozens of Zigbee or Z-Wave devices, dedicated hardware helps, but a basic alarm system with five to ten sensors does not need it.

How reliable is a DIY Pi alarm compared to a commercial system?

The hardware is comparable. PIR sensors and reed switches are the same technology commercial systems use. The difference is in monitoring: commercial services have 24/7 call centers that contact emergency services. A Pi alarm sends you notifications directly, which means it depends on you being awake and available to respond. For break-in detection and deterrence (loud siren, phone alerts), a Pi alarm works well. For monitored emergency dispatch, you either need to add a third-party monitoring service or accept that limitation.

Related Resources

Fastio features

Store Your Alarm Configs Where a Dead SD Card Cannot Reach Them

Fastio workspaces give your Pi alarm system a backup layer for HA automations, sensor scripts, and OpenClaw configs. generous storage, no credit card, MCP-ready for your agent to read and write directly.