I Built an AI That Monitors My Basement and Prevented a Flood

Todd Deshane · April 11, 2026 · 8 min read

Last month, my sump pump's float switch got stuck. The pump was drawing 500 watts continuously, the motor temperature was climbing toward 40C, and water was rising in the pit. I was asleep.

The AI I built caught it. It detected the abnormal power draw pattern, identified it as a stuck float, and began an automated recovery protocol. By the time I woke up, the system had run 97 recovery cycles, keeping the basement dry while preventing the motor from burning out. No flood. No dead pump. No $10,000 remediation bill.

Here's how I built it with a $25 smart plug, a local LLM running on my Mac, and three USGS stream gauges.

The Problem

Sump pumps fail in exactly two ways, both catastrophic:

  1. The pump dies and water rises until it floods your basement
  2. The float switch sticks, the pump runs continuously until the motor overheats and dies, then water rises until it floods your basement

Both failures happen silently. You find out when you step in water. By then, you're looking at $5,000-$15,000 in water damage, mold remediation, and a new pump.

I wanted something that would catch both failure modes before they became emergencies. Not a $300 "smart" water sensor that sends a push notification after the water is already on the floor. Something that understands what the pump is doing and why.

The Architecture

Shelly Plug US Gen4 ($25) USGS Stream Gauges (free) | power monitoring | Mohawk River @ Fonda | watts, temp, voltage | Mohawk River @ Amsterdam v | Schoharie Creek v +---------+ +------------------+ +-----------+ | pump.py | --> | ai_analyzer.py | <-- | Open-Meteo| | state | | Flask + SQLite | | weather | | machine | | + Ollama (32B) | | API | +---------+ +------------------+ +-----------+ | [Every 5 minutes] | Ollama qwen3:32b running locally on Mac M3 Max (128GB) | Advisory insights + weather risk score + stream correlation | Email + ntfy alerts

Three components, each doing one thing well:

1. The Sensor: Shelly Plug US Gen4

A $25 smart plug with built-in power monitoring. It reports watts, voltage, current, and internal temperature over HTTP. No cloud subscription. No app required. Just a REST API on your local network.

The key insight: you don't need a water sensor to detect a pump problem. A sump pump draws 0 watts when idle and ~500 watts when running. If it's been drawing 500 watts continuously for 3 minutes, the float is stuck. If it's drawing 0 watts during a rainstorm when the stream gauges are rising, the pump may have failed. Power monitoring tells you everything.

2. The State Machine: pump_state.py

A 7-state machine that manages the pump through failure scenarios without human intervention:

NORMAL -> stuck 3 min -> POWER_CYCLE
POWER_CYCLE -> success -> NORMAL
POWER_CYCLE -> fail -> TIER_1 (60s ON / 15 min OFF)
TIER_1 -> 3 cycles still stuck -> TIER_2 (90s ON / 10 min OFF)
TIER_2 -> 6 cycles still stuck -> TIER_3 (120s ON / 10 min OFF)
Any tier -> pump stops naturally -> COOLDOWN
COOLDOWN -> stable idle 90s -> NORMAL
Any state -> motor overtemp -> LOCKOUT (manual only)

The tiered escalation is the critical design. When the float sticks, you can't just leave the pump running (motor death) or turn it off (flood). You need a duty cycle that keeps the water manageable while giving the motor time to cool. Each tier increases the ON duration and decreases the OFF duration as the situation escalates.

Safety principle: The state machine controls the power relay. The AI layer is purely advisory. It analyzes patterns and sends alerts, but it never touches the pump. This separation is essential for any safety-critical physical AI system.

3. The Brain: ai_analyzer.py + Ollama

A Flask server running on my Mac M3 Max that fuses three data streams:

Every 5 minutes, it sends the fused context to a Qwen 32B model running locally via Ollama. The model analyzes the current situation and produces:

Why local inference matters: This runs on a Mac in my basement. No cloud API calls. No internet dependency. When the power goes out and the backup battery kicks in, the monitoring system keeps running on local hardware. A cloud-dependent system would go blind exactly when you need it most.

What It Caught

On April 11, 2026, the system detected a stuck float at approximately 3am. Power draw was 493-506W continuously. The state machine began recovery:

Meanwhile, the AI analyzer correlated this with rising stream levels on the Mohawk and noted elevated soil moisture from recent rain. It correctly assessed this as a high-risk period where the pump was doing real work (not just a sensor glitch).

I got the alert email and text. The basement was dry. The motor was intact. The system was doing exactly what it was designed to do.

The Bigger Picture: Physical AI for Everyone

This isn't a toy project. It's a proof of concept for a much larger idea: edge AI that understands physical systems.

The same architecture works for:

The pattern is always the same: cheap sensors + edge inference + domain knowledge = predictive intelligence that prevents expensive failures.

I'm building these systems for small businesses that can't afford Siemens or Honeywell but still need their buildings to work. A church. A 3-location HVAC company. A bus parts distributor. The $1M-$5M businesses that the enterprise players ignore.

Need monitoring for your building or equipment?

I build custom AI monitoring systems using off-the-shelf sensors and local inference. No cloud subscriptions. No vendor lock-in.

Let's Talk

Technical Details

The full system is approximately 2,000 lines of Python across three files:

Hardware cost: $25 (Shelly Plug). Software cost: $0 (all open source). Compute: runs on any Mac, Linux box, or Raspberry Pi with enough RAM for the LLM.

The state machine persists to /var/tmp/ so it survives reboots. The SQLite database retains 30 days of readings. Weather data is cached to avoid hammering free APIs.

If you want to build something similar, the core insight is: start with the sensor data you already have. A smart plug gives you power monitoring. A smart thermostat gives you temperature. A water meter gives you flow. Feed it to a local LLM with domain context and let it find the patterns.

The robots are coming. But before they arrive, there's a massive opportunity in making the buildings and equipment we already have smarter with the AI tools we already have.