Monitors a drainage pump via a sensor on some pin and calculates statistics accessible via HTTP.
Find a file
2026-06-12 21:03:18 +02:00
.vscode Add PlatformIO VSCode extension 2026-05-25 00:19:59 +02:00
lib/pump_monitor Add Persistence that writes PumpCycles in some file 2026-06-09 21:20:31 +02:00
src Add main that ties everything together 2026-06-09 21:20:31 +02:00
test Add Persistence that writes PumpCycles in some file 2026-06-09 21:20:31 +02:00
.gitignore Initial commit with README.md 2026-05-24 22:59:34 +02:00
platformio.ini fu platform io tests 2026-06-12 21:03:18 +02:00
README.md Initial commit with README.md 2026-05-24 22:59:34 +02:00

ESP32 Pump Monitor

A lightweight ESP32-based pump monitoring system using an AC current switch (e.g. SZC23-NO-AL-CH).

The device detects pump activity, records pump cycles, aggregates statistics, and exposes metrics via a simple HTTP JSON API.

Features

  • Detect pump activity via digital GPIO input
  • Poll sensor periodically (default: 500 ms)
  • Debounce state transitions
  • Record completed pump cycles
  • Synchronize time via NTP
  • Provide rolling statistics for:
    • last 24 hours
    • last 7 days
    • last 30 days
    • lifetime
  • Expose metrics via HTTP/JSON
  • Designed for integration with external monitoring systems such as Icinga2

No web UI, authentication, or embedded alerting is implemented.

Pump Cycle Definition

A pump cycle consists of:

  • start timestamp
  • end timestamp
  • idle time since previous cycle

Idle time is defined as:

next_cycle_start - previous_cycle_end

Metrics

Current State

{
  "running": true,
  "current_cycle_duration": 512,
  "time_since_last_cycle": 18234
}

Rolling Statistics

For each interval (24h, 7d, 30d, lifetime):

{
  "count": 17,
  "runtime_total": 812,
  "duration_min": 22,
  "duration_max": 91,
  "duration_avg": 47,
  "gap_min": 180,
  "gap_max": 8200,
  "gap_avg": 2400
}

HTTP API

GET /metrics

Returns current state and aggregated statistics as JSON.

Storage

Completed pump cycles are stored persistently as append-only event records.

Statistics may be recomputed from recorded events after reboot.

Intended Use

The monitor is intended to:

  • observe pump behavior
  • provide operational statistics
  • support external monitoring and alerting

Alert thresholds and notifications should be implemented externally (e.g. in Icinga2).