Skip to content

Site simulator: thermal plant, facility presets, and live schematic - #6

Draft
frahlg wants to merge 5 commits into
mainfrom
cursor/lua-driver-physical-plant-6d9d
Draft

Site simulator: thermal plant, facility presets, and live schematic#6
frahlg wants to merge 5 commits into
mainfrom
cursor/lua-driver-physical-plant-6d9d

Conversation

@frahlg

@frahlg frahlg commented Aug 19, 2026

Copy link
Copy Markdown
Member

Summary

This is now a site simulator, not only a bag of independent devices.

Pick a facility on the dashboard (house ASHP/GSHP, apartment, or PV+battery). That instantiates a physics plant and the Modbus facades an EMS (FTW/FTV) talks to. The site clock is the only integrator. Devices do not invent power; they project what the plant just solved.

EMS --Modbus--> Sungrow hybrid + generic heat pump + SDM630
                   ▲
                   │ site tick
            plant.Model (NativeSite; optional Site4.fmu for AC bus)
            P_grid + P_pv + P_batt + P_house + P_hp + P_ev = 0
            C·dT_in/dt = Q_hp_space + Q_solar + Q_int − Q_loss

The Site plant band is a live schematic: green electrical flows (Lua sign convention), orange heat, indoor/DHW temperatures, occupancy, SG Ready.

How to use it: docs/SITE_SIMULATOR.md. Bus sketch: docs/SITE_PLANT_SKETCH.md.

Facilities

Preset Plant
house-ashp Nordic house, air-source HP, DHW, 8 kW PV + 10 kWh
house-gshp Same house, ground-source HP (stable winter COP)
apartment-ashp Heavier envelope, larger ASHP, modest PV
pv-battery Occupancy plug loads only

POST /api/sites/{id}/facility with { "preset": "house-ashp" } creates the Sungrow + heat-pump devices if needed, sets scenario physical, and starts the clock.

Operating routines (not a full FTV stack, enough that the site feels occupied): occupancy plug loads and internal heat, heating curve + night setback, DHW draws, SG Ready 0–3.

Physics / Modelica

  • Native Go (internal/plant) is the live thermal + electrical DAE.
  • modelica/SiteEnergy.mo now has matching Building, HeatPump, DHWTank, HouseFacility.
  • Site4.fmu stays the electrical FMI 2.0 slave (make fmu). A facility forces native so heat and electricity share one clock.
make fmu                     # omc → modelica/Site4.fmu
SITEPLANT_FMU=...            # or drop Site4.fmu in modelica/
SITEPLANT_NATIVE=1           # force Go

Lua drivers still poll Modbus, not HTTP.

API (OpenAPI + MCP + /docs updated together)

  • GET /api/facilities
  • GET|POST /api/sites/{id}/facility
  • GET /api/sites/{id}/plant
  • Simulator type heat_pump (holding 1100–1103 enable/setpoint/mode/SG Ready; inputs indoor/DHW/COP/…)

Wails: GetFacilities, ApplySiteFacility, GetSitePlant.

Checklist

  • Tests pass locally (go test ./...)
  • Thermal tests: ASHP heat+electric, GSHP winter COP, SG Ready block, enable-off, occupancy house load, 24 h indoor hold
  • HTTP API change: openapi.json, internal/mcp/server.go, docs.html
  • Commit subject uses a release prefix when this should ship (patch: / minor: / major:)
Open in Web Open in Cursor 

cursoragent and others added 5 commits August 19, 2026 16:04
Introduce a conserved site-node power balance (Modelica-style DAE) so
automation can be more than independent sine waves, and fill the Sungrow
addresses srcfl/device-drivers actually polls (serial at 4990, device
type, running state, active-power limit). Scenario "physical" steps the
plant and writes semantic registers. See docs/LUA_DRIVER_PLANT.md.

Co-authored-by: Fredrik Ahlgren <fredrik@sourceful-labs.com>
Site physics lives in modelica/SiteEnergy.mo (Kirchhoff power connector,
hybrids, house load, grid slack). The simulator talks to plant.Model so
an FMI FMU can replace the Go native backend later. NativeSite already
solves the same bus: self-consumption batteries share house residual,
EMS units follow Lua setpoints, the site clock writes registers.

Physical site scenario skips per-inverter sine generation and steps the
bus from calculateAndUpdateMeter.

Co-authored-by: Fredrik Ahlgren <fredrik@sourceful-labs.com>
SVG plus short notes so the site DAE is reviewable as a picture:
one AC node, NativeSite/FMU plug, vendor maps, Modbus to Lua.

Co-authored-by: Fredrik Ahlgren <fredrik@sourceful-labs.com>
siteplant.Open loads a Site4 FMI 2.0 co-simulation FMU when present
(linux/amd64 + CGO) and falls back to the native Go DAE otherwise.
make fmu runs omc against modelica/SiteEnergy.mo. Mode-0 slack stays
in the Go master. Empty FMI slots are gated with u_on.

Co-authored-by: Fredrik Ahlgren <fredrik@sourceful-labs.com>
…atic

The dashboard can instantiate a house or apartment (ASHP or GSHP, DHW,
occupancy) whose physics plant drives Sungrow and heat-pump Modbus facades
on the site clock, so an EMS can talk to it as if it were a real site.

Co-authored-by: Fredrik Ahlgren <fredrik@sourceful-labs.com>
@cursor cursor Bot changed the title Physical plant + Lua driver compatibility for Sungrow Site simulator: thermal plant, facility presets, and live schematic Aug 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants