How DER Twin Works — Architecture of an Open Source Energy Device Simulator
This is Part 3 of my series on DER Twin. Part 1 covered why I built it. Part 2 showed how to use it for EMS testing. This one is about how it works inside. If you want to contribute — add a new dev...

Source: DEV Community
This is Part 3 of my series on DER Twin. Part 1 covered why I built it. Part 2 showed how to use it for EMS testing. This one is about how it works inside. If you want to contribute — add a new device type, extend the physics, or add a new protocol — this is the article to read first. The Four Layers DER Twin is built around a strict separation of concerns. Every component lives in exactly one layer and communicates only through defined interfaces. Protocol layer — accepts Modbus connections and exposes register addresses. Never touches device state directly. Controller layer — maps register reads and writes to device telemetry and commands. Owns the encoding/decoding logic. Device layer — owns physics. Knows nothing about protocols. A BESS device doesn't know if it's being read via TCP or RTU. Simulation engine — owns time. Calls step(dt) on every device on every tick. External models — the environment. Irradiance, ambient temperature, grid frequency, grid voltage. Devices read from t