# Open Microgrid Lab

> A neighbourhood microgrid lab in one program: a simulated street of 20 homes and a community centre in Madrid, behind one 250 kVA transformer, each home with its own devices and smart meter. A microgrid controller islands the street on the community battery when the grid fails; neighbours trade energy every 15 minutes at their own prices or on automatic, settled into an append-only ledger and monthly bills. The control room reads the microgrid's devices over Modbus TCP and DNP3, with operator training and an MCP endpoint for AI assistants. A learning and portfolio project: the homes, their meters and the events are simulated; no real customer data.

## What it does

- The neighbourhood: 20 homes of different kinds (family houses with PV, a heat pump and an EV; retired couples; flats without a roof; home offices with a battery; a three-phase shop) and a community centre with the shared rooftop PV, the 200 kWh grid-forming community battery and a 60 kW genset; 3 homes are critical (home oxygen) and are never shed
- The microgrid controller (in the field, as a real one at the point of connection): islands the street when the grid is lost, sheds EV chargers and heat pumps first, then non-critical homes in turns, curtails PV by frequency, resynchronises and closes the PCC once the grid has been steady, black starts a dark street, changes the street's protection to its island setting group, starts the genset on a low battery
- The street: a per-phase load flow along its cable with the neutral, every meter's voltage against EN 50160, volt-watt on the PV inverters, the transformer's loading, and standing warnings for what is wrong with the network until its model is fixed
- An app for each home, made for a phone and a desktop, which can be installed: the home's own house drawn live (its roof, car and battery, the energy to and from the street) under the sky there is now, messages, Our street without the neighbours' data, the street market (its prices, a neighbour to buy from first, results), and the bill with a monthly budget and its forecast
- Energy sharing and bills: every 15 minutes the meters' registers become intervals and ledger entries under one rule (free P2P at the midpoint price, Spain's collective self-consumption coefficients, flat, German Mieterstrom, Italian CER or a street market where homes set their own prices, choose a neighbour to buy from first or leave it on automatic); exact integer money, an append-only ledger, monthly bills with savings against going alone, disputes, corrections and a month close with a hash
- The battery's plan: a least-cost 24 h plan on the street's forecast at the hour's prices, never below the island reserve; it charges only what the street's cable has room for on its fullest phase
- SCADA: the microgrid's own devices (the grid connection, the battery, PV and genset inverters, the street breaker) polled over Modbus or DNP3, a historian with trends, alarm management after ISA-18.2, controls over DNP3 with select before operate and confirmation by telemetry
- Network model: the neighbourhood edited as a picture, versions, validation, a second engineer's approval for changes to the neighbourhood's money, live switch-over
- Training: a control room per student, scenarios (an evening grid loss, a winter night, a failing battery, a fault in the island, a meter that reads high, closing the month), an instructor with a session clock, score and timeline, and built-in help (a ? on every console, tool and key term)

## Try it

- [Landing page](https://microgrid.vedranv.com/login): what it is, and the sign-in; "Try a home" opens a demo home's app and "Open the control room" the control room, both read-only, without an account and with the basics only

## Use it from an AI assistant

- MCP endpoint: `https://microgrid.vedranv.com/mcp` (streamable HTTP). It takes the same user name and password as the control room, as an `Authorization: Basic` header, or none: without one it answers with a few read-only tools (the microgrid's devices, alarms, trends and storm).
- With an account, the read-only tools return what the control room shows: the neighbourhood now, the bills, alarms, events, trends, the microgrid's devices. No tool can operate equipment, acknowledge alarms or change settings.
- An engineer's assistant can also read network model versions and, where the server's owner allows it, write drafts. Only a person can activate a model version.

## How it is built

- Rust, one binary: simulator, SCADA, the settlement and the web interface in one process, with SQLite for history and the ledger
- Tested: garbage-input tests on the protocol decoders and importers, a stress run, and state-machine and ledger invariants checked after every test
- Standards it follows: Modbus TCP, DNP3, EN 50160 voltage quality, IEC 62443 zones and roles, ISA-18.2 alarm management, Spain's RD 244/2019 shared self-consumption
- Data shapes: solar from PVGIS; the homes' load shapes are made up
