sitesim

package
v0.0.0-...-cc71c16 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 29, 2026 License: AGPL-3.0 Imports: 4 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package sitesim is a simulated house behind one main fuse, for testing Core in a closed loop. It holds the physics and the devices' own behaviour; Core reads what the devices report and sends them commands. A test advances it one second at a time on a pinned clock. Nothing here sleeps or starts a goroutine.

Signs follow docs/site-convention.md: positive W flows into the site. Phase currents are signed the same way unless a meter drops the sign.

Index

Constants

View Source
const Step = time.Second

Step is the plant's time step.

Variables

This section is empty.

Functions

This section is empty.

Types

type Battery

type Battery struct {
	Phases                    int // 1 (on L1) or 3
	MaxChargeW, MaxDischargeW float64
	CapacityWh, SoC           float64
	Latency                   time.Duration
	W                         float64 // power now, positive charging
	// contains filtered or unexported fields
}

Battery is a battery inverter that follows a power command after Latency.

func (*Battery) Command

func (b *Battery) Command(now time.Time, w float64)

Command asks for w from now + Latency.

type BatteryReading

type BatteryReading struct{ W, SoC float64 }

BatteryReading is what the battery reports.

type Car

type Car struct {
	Phases  int     // phases its onboard charger uses
	MaxW    float64 // the most it takes, whatever it is offered
	Plugged bool
}

Car is the vehicle on the EVSE.

type EVReading

type EVReading struct {
	W, SessionWh float64
	Plugged      bool
}

EVReading is what the charger reports. W is ReadbackLag late.

type EVSE

type EVSE struct {
	Phases        int // wired phases, 1 or 3
	MinA, MaxA    float64
	Delay         time.Duration // from command to current at the car
	ReadbackLag   time.Duration // the charger reports the draw this late
	LoadBalancerA float64       // > 0: its own balancer keeps each phase under this
	OfferA        float64       // current limit in force
	OfferPhases   int
	DrawW         float64 // the car's draw now
	DrawPhases    int
	SessionWh     float64 // since the car plugged in

	// The Easee driver's own choice for "auto" (easee_cloud.lua pick_phases):
	// without a phase_split_w it splits at the fuse's current on one phase,
	// and it keeps a phase count PhaseHold before it changes it.
	SplitAtA  float64       // > 0: auto with no split splits at voltage × SplitAtA
	PhaseHold time.Duration // > 0: an auto phase count stays this long
	// contains filtered or unexported fields
}

EVSE is a charger with its driver: it turns a power command into a current limit, as the Easee driver does, and applies it after Delay.

func (*EVSE) Command

func (e *EVSE) Command(now time.Time, powerW float64, phaseMode string, splitW, voltage float64)

Command sends powerW in phaseMode ("1p", "3p", "auto" or empty). Auto picks one phase below splitW, as the Easee driver does; PhaseHold adds its hysteresis. Below MinA the charger pauses.

func (*EVSE) Queued

func (e *EVSE) Queued() (a float64, phases int, ok bool)

Queued is the last order the charger has not applied yet, as current per phase and phases; false when every order is in force.

type Event

type Event struct {
	At     time.Duration
	Kind   EventKind
	For    time.Duration
	Device string // "battery" or "evse"
	Do     func(*Plant)
}

Event is one change on the timeline, At after the plant started.

type EventKind

type EventKind int

EventKind says what an event does.

const (
	Change        EventKind = iota // run Do on the plant
	CoreRestart                    // Core stops for For and starts with no memory
	MeterSilent                    // the site meter sends nothing for For
	DriverOffline                  // Device sends nothing for For; Offline says so, and callers send it nothing
)

type Fuse

type Fuse struct {
	RatingA float64
	Phase   [3]fuse.Phase
	Damage  [3]float64
	Blown   [3]bool
}

Fuse is a gG main fuse (IEC 60269) on each phase, as srcfl/device-simulator's fuse package models it: the thermal model the site rig judges Core by, so both simulators share one fuse. A phase starts cold in a 25 °C cabinet; Preheat starts it warm. Damage and Blown mirror each phase after a step.

func (*Fuse) AnyBlown

func (f *Fuse) AnyBlown() bool

AnyBlown reports whether any phase has blown.

func (*Fuse) Preheat

func (f *Fuse) Preheat(amps [3]float64) error

Preheat puts each phase in the steady state of amps held for hours, for a scenario that starts with the house near its limit.

type Meter

type Meter struct {
	Every    time.Duration
	Unsigned bool // phase currents as magnitudes
	// contains filtered or unexported fields
}

Meter is the site meter. It reads the boundary every Every, or every second when Every is zero.

type MeterReading

type MeterReading struct {
	W      float64
	PhaseA [3]float64
	PhaseW [3]float64
}

MeterReading is one site meter reading. Phase power keeps its sign when the currents lose theirs, as on P1.

type Plant

type Plant struct {
	Now     time.Time
	Voltage float64
	HouseW  [3]float64 // house load per phase
	PVW     float64    // three-phase PV, zero or negative
	Battery *Battery   // nil: none
	EVSE    *EVSE      // nil: none
	Car     *Car       // the car on the EVSE; nil or unplugged: none
	Meter   Meter
	Fuse    Fuse
	Events  []Event // in time order; each fires once

	A [3]float64 // physical phase currents after the last step
	// contains filtered or unexported fields
}

Plant is one site. Set its fields before the first Step and change them from events.

func New

func New(start time.Time, fuseA float64) *Plant

New returns a plant starting at start with a fuse of fuseA per phase.

func (*Plant) Offline

func (p *Plant) Offline(device string) bool

Offline reports whether device is unreachable now.

func (*Plant) Step

func (p *Plant) Step() Tick

Step advances one second: events, device responses, physics, fuse and readings, in that order.

type Tick

type Tick struct {
	Meter   *MeterReading
	Battery *BatteryReading
	EV      *EVReading
	Restart time.Duration // > 0: Core goes down now for this long
}

Tick is what one second produced. A nil reading means the device sent nothing this second.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL