A microgrid balances local generation against local load in real time. Any surplus charges the
battery (or exports to the main grid, if connected); any deficit draws from the battery first, then
from the grid. In islanded mode the grid connection is cut — the battery alone must cover shortfalls.
P_net = P_solar + P_wind − P_load
if P_net > 0: charge battery (or export)
if P_net < 0: discharge battery (or import)
SOC(t+dt) = SOC(t) + P_net·dt / E_capacity
- Grid-tied / Islanded toggle — with the grid tie cut, an empty battery causes a brownout instead of drawing from the grid.
- Solar generation — power flowing in from the solar node along its line to the bus.
- Wind generation — power flowing in from the wind node.
- Household load — power draining out toward the house/load node.
Real-world relevance: this is the control logic behind real community microgrids and home
battery systems (e.g. Tesla Powerwall setups) that keep the lights on during grid outages by
islanding automatically.