Inverter load manager

Watches the inverter / battery current and switches off non-critical loads with a relay when the battery runs low.

Power & batteries Board: ESP32 DevKit V1 (WROOM-32) Level: ●●● ⏱ 3–5 h

⛔ High risk

Mains 220–230 V can kill. Work with the power off, use certified isolated modules in an enclosure, fuse the line, and ask a qualified electrician if you are not sure.

Shed the load before the inverter does it for you

When the battery is nearly empty the inverter simply shuts down, and everything stops, including the things you cared about. A smarter plan is to cut the boiler, the air conditioner or the washing machine early and keep the router, lights and fridge alive for hours longer.

Design decisions

Use a current reading and the battery voltage together. Voltage sags under load, so compare it with a smoothed value and a margin, or better, take the state of charge from the BMS (see the BMS monitor idea). Define a shedding order and a recovery order, and keep a minimum delay of several minutes before re-connecting, otherwise the relay will chatter around the threshold.

  • Switch 220 V loads through a contactor or a relay rated well above the load, not through a small module relay.
  • Decide what should happen if the ESP32 hangs. A normally closed contact keeps the load on, a normally open one drops it. For heavy loads dropping is usually the safer default.
  • The inverter’s own low-battery cut-off stays as the last line of defence; never rely only on the ESP32.

Components

  • ESP32 DevKit V1 (30 pin, WROOM-32)
  • INA219 current/voltage sensor module
  • Relay module 1-channel 5V (opto-isolated)
  • Inline fuse holder + fuses
  • Plastic project enclosure
  • Lever connectors (WAGO type) 2/3-pin

Wiring

Module Module pin ESP32 pin Note
INA219 SDA / SCL I2C GPIO21 / GPIO22
INA219 Vin+ / Vin- shunt battery + → inverter side fuse next to the battery
Relay IN signal GPIO26 active LOW module
Relay contacts COM / NO control circuit of a contactor never switch heavy loads directly

Libraries

  • Adafruit INA219

Code

#include <WiFi.h>

const char* WIFI_SSID = "YOUR_WIFI";
const char* WIFI_PASS = "YOUR_PASSWORD";

bool connectWiFi(uint32_t timeoutMs = 20000) {
  WiFi.mode(WIFI_STA);
  WiFi.begin(WIFI_SSID, WIFI_PASS);
  uint32_t t0 = millis();
  while (WiFi.status() != WL_CONNECTED && millis() - t0 < timeoutMs) {
    delay(250);
    Serial.print(".");
  }
  Serial.println();
  if (WiFi.status() == WL_CONNECTED) {
    Serial.print("IP: ");
    Serial.println(WiFi.localIP());
    return true;
  }
  return false;
}
#include <Wire.h>
#include <Adafruit_INA219.h>
Adafruit_INA219 ina;
#include <WebServer.h>

WebServer server(80);
String buildJson();   // implemented in the project below

String num(float v, int d = 1) { return isnan(v) ? String("null") : String(v, d); }

const char PAGE_HTML[] PROGMEM = R"rawliteral(
<!doctype html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
<title>ESP32</title>
<style>body{font-family:system-ui;background:#0b0f14;color:#e6edf3;margin:20px}table{border-collapse:collapse}td{padding:6px 14px;border-bottom:1px solid #223}button,input{font-size:16px;padding:8px 14px;margin:4px;border-radius:6px;border:1px solid #345;background:#16202b;color:#e6edf3}</style>
</head><body><h2>ESP32</h2><table id="t"></table>
<script>
function load(){fetch('/json').then(r=>r.json()).then(d=>{let h='';for(const k in d){h+='<tr><td>'+k+'</td><td>'+d[k]+'</td></tr>';}document.getElementById('t').innerHTML=h;});}
load();setInterval(load,2000);
</script></body></html>
)rawliteral";

void startWeb() {
  server.on("/", []() { server.send_P(200, "text/html", PAGE_HTML); });
  server.on("/json", []() { server.send(200, "application/json", buildJson()); });
  server.begin();
}
const int PIN_RELAY = 26;            // active LOW
float V_OFF = 11.8, V_ON = 12.6;     // hysteresis for a 12 V battery; set for your chemistry
bool loadOn = false;
float busV = 0;
String buildJson() { return String("{"V":") + num(busV, 2) + ","load":" + (loadOn ? ""on"" : ""off"") + "}"; }
void setLoad(bool on) { loadOn = on; digitalWrite(PIN_RELAY, on ? LOW : HIGH); }
void setup() {
  pinMode(PIN_RELAY, OUTPUT); setLoad(false);
  Serial.begin(115200);
  Wire.begin(21, 22);
  ina.begin();
  connectWiFi();
  startWeb();
}
void loop() {
  server.handleClient();
  static uint32_t t = 0;
  if (millis() - t > 2000) {
    t = millis(); busV = ina.getBusVoltage_V();
    if (loadOn && busV < V_OFF) setLoad(false);        // protect the battery
    else if (!loadOn && busV > V_ON) setLoad(true);
  }
}

Build tips

  • Set V_ON higher than V_OFF by at least 0.8 V so the load does not flap.
  • Use a contactor rated for the load; the relay only drives its coil.

What you need

Buy the parts kit · Estimated total: $14.50

ESP32 DevKit V1 (30 pin, WROOM-32) × 1
$4.00
Buy at AliExpress Buy at Amazon.com
INA219 current/voltage sensor module × 1
$2.00
Buy at AliExpress Buy at Amazon.com
Relay module 1-channel 5V (opto-isolated) × 1
$1.50
Buy at AliExpress Buy at Amazon.com
Inline fuse holder + fuses × 1
$1.50
Buy at AliExpress Buy at Amazon.com
Plastic project enclosure × 1
$3.00
Buy at AliExpress Buy at Amazon.com
Lever connectors (WAGO type) 2/3-pin × 1
$2.50
Buy at AliExpress Buy at Amazon.com
🇺🇦 Ukraine🌍 Other countries

Other countries: order these parts on AliExpress with the links below.

Some links are affiliate links: we may earn a commission at no extra cost to you.

Related ideas

⛔ High risk

Mains 220–230 V can kill. Work with the power off, use certified isolated modules in an enclosure, fuse the line, and ask a qualified electrician if you are not sure.

Mains voltage monitor

Measures 220 V mains through an isolated ZMPT101B module and warns about sags, surges and blackouts in Telegram or Home Assistant.

  • Board ESP32 DevKit V1 (WROOM-32)
  • Level ●●○ Intermediate
  • Build time 2–3 h
Pick parts / kit
⛔ High risk

High-current battery: a short circuit can start a fire. Put a fuse next to the battery plus, use thick enough wires and respect the BMS limits.

LiFePO4 / battery monitor

Shows voltage, current and power of a battery bank (INA219) so you know the real charge and load during outages.

  • Board ESP32 DevKit V1 (WROOM-32)
  • Level ●●○ Intermediate
  • Build time 1–2 h
Pick parts / kit
⛔ High risk

Mains 220–230 V can kill. Work with the power off, use certified isolated modules in an enclosure, fuse the line, and ask a qualified electrician if you are not sure.

Smart energy meter

Reads voltage, current, power and kWh with PZEM-004T and publishes them to a web page, MQTT or Home Assistant.

  • Board ESP32 DevKit V1 (WROOM-32)
  • Level ●●○ Intermediate
  • Build time 2–4 h
Pick parts / kit

← All module ideas →

Comments

No comments yet. Share your experience or ask a question.

Comments are moderated.