Monitors a drainage pump via a sensor on some pin and calculates statistics accessible via HTTP.
- C++ 100%
| .vscode | ||
| lib/pump_monitor | ||
| src | ||
| test | ||
| .gitignore | ||
| platformio.ini | ||
| README.md | ||
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).