core

package
v0.0.0-...-e77efc7 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: MIT Imports: 57 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OptimizerAutomaticOff     = "off"
	OptimizerAutomaticBattery = "battery" // home battery only
	OptimizerAutomaticFull    = "full"    // home battery and loadpoints
)

optimizer automatic levels: what the optimizer controls instead of only advising

View Source
const (
	OPTIMIZER_URI = "https://optimizer.evcc.io"
)

Variables

View Source
var (
	ErrBatteryNotConfigured             = errors.New("battery not configured")
	ErrBatteryControlNotAvailable       = errors.New("battery control not available")
	ErrBatteryGridDischargeNotAvailable = errors.New("battery grid discharge not available")

	// ErrOptimizerAutomatic marks settings the optimizer decides on its own
	ErrOptimizerAutomatic = errors.New("not available in automatic mode")
)

Functions

func DefaultDemandPredictor

func DefaultDemandPredictor(charger any) string

DefaultDemandPredictor returns the demand predictor a heating charger declares via its predictor feature

func OptimizerAutomatic

func OptimizerAutomatic() string

OptimizerAutomatic returns the configured optimizer automatic level

Types

type EnergyMetrics

type EnergyMetrics struct {
	// contains filtered or unexported fields
}

EnergyMetrics calculates stats about the charged energy and gives you details about price or co2s

func (*EnergyMetrics) Co2PerKWh

func (em *EnergyMetrics) Co2PerKWh() *float64

Co2PerKWh returns the average co2 emissions per kWh

func (*EnergyMetrics) Price

func (em *EnergyMetrics) Price() *float64

Price returns the total energy price in Currency

func (*EnergyMetrics) PricePerKWh

func (em *EnergyMetrics) PricePerKWh() *float64

PricePerKWh returns the average energy price in Currency

func (*EnergyMetrics) Publish

func (em *EnergyMetrics) Publish(prefix string, p publisher)

Publish publishes metrics with a given prefix

func (*EnergyMetrics) Reset

func (em *EnergyMetrics) Reset()

Reset sets all calculations to initial values

func (*EnergyMetrics) SetEnvironment

func (em *EnergyMetrics) SetEnvironment(greenShare float64, effPrice, effCo2 *float64)

SetEnvironment updates site information like solar share, price, co2 for use in later calculations

func (*EnergyMetrics) SolarPercentage

func (em *EnergyMetrics) SolarPercentage() float64

SolarPercentage returns the share of self-produced energy in percent

func (*EnergyMetrics) TotalWh

func (em *EnergyMetrics) TotalWh() float64

TotalWh returns the total energy in Wh

func (*EnergyMetrics) Update

func (em *EnergyMetrics) Update(chargedKWh float64) (float64, float64)

Update sets the a new value for the total amount of charged energy and updated metrics based on environment values. It returns the added total and green energy.

type Explanation

type Explanation struct {
	Text    string    `json:"explanation"`
	Created time.Time `json:"created"`
	Plan    time.Time `json:"plan"` // updated time of the explained plan
}

Explanation is a plan explanation, when the optimizer service wrote it and the plan it explains. It is published as evopt-explanation, so every client shows the last one.

func (Explanation) MarshalBytes

func (e Explanation) MarshalBytes() ([]byte, error)

MarshalBytes publishes the explanation as one message, like evopt

type Loadpoint

type Loadpoint struct {
	sync.RWMutex // guard status

	// exposed public configuration
	CircuitRef string `mapstructure:"circuit"` // Circuit reference
	ChargerRef string `mapstructure:"charger"` // Charger reference
	VehicleRef string `mapstructure:"vehicle"` // Vehicle reference
	MeterRef   string `mapstructure:"meter"`   // Charge meter reference

	Soc             loadpoint.SocConfig
	Enable, Disable loadpoint.ThresholdConfig
	Ui              loadpoint.UIConfig // display-only, not used in control logic

	// from yaml
	DefaultMode     api.ChargeMode `mapstructure:"mode"`            // Default charge mode, used for disconnect
	Title           string         `mapstructure:"title"`           // UI title
	Priority        int            `mapstructure:"priority"`        // Priority
	DemandPredictor string         `mapstructure:"demandPredictor"` // Heating demand predictor, empty: charger default

	// from yaml, deprecated
	GuardDuration_ time.Duration `mapstructure:"guardduration"` // ignored, present for compatibility
	Phases_        int           `mapstructure:"phases"`        // ignored, present for compatibility
	MinCurrent_    float64       `mapstructure:"minCurrent"`    // ignored, present for compatibility
	MaxCurrent_    float64       `mapstructure:"maxCurrent"`    // ignored, present for compatibility
	// contains filtered or unexported fields
}

Loadpoint is responsible for controlling charge depending on Soc needs and power availability.

func NewLoadpoint

func NewLoadpoint(log *util.Logger, settings settings.Settings) *Loadpoint

NewLoadpoint creates a Loadpoint with sane defaults

func NewLoadpointFromConfig

func NewLoadpointFromConfig(log *util.Logger, settings settings.Settings, collector *metrics.Collector, other map[string]any) (*Loadpoint, error)

NewLoadpointFromConfig creates a new loadpoint

func (*Loadpoint) ActivePhases

func (lp *Loadpoint) ActivePhases() int

ActivePhases returns the number of expectedly active phases for the meter. If unknown for 1p3p chargers during startup it will assume 3p.

func (*Loadpoint) ClearPlanLock

func (lp *Loadpoint) ClearPlanLock()

ClearPlanLock clears the locked plan goal

func (*Loadpoint) EffectiveLimitSoc

func (lp *Loadpoint) EffectiveLimitSoc() int

EffectiveLimitSoc returns the effective session limit soc

func (*Loadpoint) EffectiveMaxPower

func (lp *Loadpoint) EffectiveMaxPower() float64

EffectiveMaxPower returns the effective max power taking vehicle capabilities, phase scaling and load management power limits into account

func (*Loadpoint) EffectiveMinPower

func (lp *Loadpoint) EffectiveMinPower() float64

EffectiveMinPower returns the effective min power for the minimum active phases

func (*Loadpoint) EffectiveMinSoc

func (lp *Loadpoint) EffectiveMinSoc() int

EffectiveMinSoc returns the effective min soc (heating: min temperature)

func (*Loadpoint) EffectivePlan

func (lp *Loadpoint) EffectivePlan(planTime time.Time, requiredDuration time.Duration, strategy api.PlanStrategy) (api.Rates, float64, bool)

EffectivePlan returns the charging plan in effect. While in control the optimizer schedules the plan itself, returned with its average power and true. Everything else is the planner's.

func (*Loadpoint) EffectivePlanId

func (lp *Loadpoint) EffectivePlanId() int

EffectivePlanId returns the id for the current plan

func (*Loadpoint) EffectivePlanSoc

func (lp *Loadpoint) EffectivePlanSoc() int

EffectivePlanSoc returns the soc target for the current plan

func (*Loadpoint) EffectivePlanStrategy

func (lp *Loadpoint) EffectivePlanStrategy() api.PlanStrategy

EffectivePlanStrategy returns the effective plan strategy

func (*Loadpoint) EffectivePlanTime

func (lp *Loadpoint) EffectivePlanTime() time.Time

EffectivePlanTime returns the effective plan time

func (*Loadpoint) EffectivePriority

func (lp *Loadpoint) EffectivePriority() int

EffectivePriority returns the effective priority

func (*Loadpoint) EffectiveStepPower

func (lp *Loadpoint) EffectiveStepPower() float64

EffectiveStepPower returns the effective step power for the currently active phases

func (*Loadpoint) GetAlwaysCharge

func (lp *Loadpoint) GetAlwaysCharge() api.AlwaysCharge

GetAlwaysCharge returns the always charge state

func (*Loadpoint) GetBatteryBoost

func (lp *Loadpoint) GetBatteryBoost() int

GetBatteryBoost returns the battery boost

func (*Loadpoint) GetBatteryBoostLimit

func (lp *Loadpoint) GetBatteryBoostLimit() int

GetBatteryBoostLimit returns the battery boost soc limit

func (*Loadpoint) GetChargePower

func (lp *Loadpoint) GetChargePower() float64

GetChargePower returns the current charge power

func (*Loadpoint) GetChargePowerFlexibility

func (lp *Loadpoint) GetChargePowerFlexibility(rates api.Rates) float64

GetChargePowerFlexibility returns the flexible amount of current charging power

func (*Loadpoint) GetChargedEnergy

func (lp *Loadpoint) GetChargedEnergy() float64

GetChargedEnergy returns session charge energy in Wh

func (*Loadpoint) GetChargerRef

func (lp *Loadpoint) GetChargerRef() string

GetChargerRef returns the loadpoint charger

func (*Loadpoint) GetCircuit

func (lp *Loadpoint) GetCircuit() api.Circuit

GetCircuit returns the assigned circuit

func (*Loadpoint) GetCircuitRef

func (lp *Loadpoint) GetCircuitRef() string

GetCircuitName returns the loadpoint circuit

func (*Loadpoint) GetDefaultMode

func (lp *Loadpoint) GetDefaultMode() api.ChargeMode

GetDefaultMode returns the default charge mode

func (*Loadpoint) GetDefaultVehicleRef

func (lp *Loadpoint) GetDefaultVehicleRef() string

GetDefaultVehicleRef returns the loadpoint default vehicle

func (*Loadpoint) GetDemandPredictor

func (lp *Loadpoint) GetDemandPredictor() string

GetDemandPredictor returns the configured demand predictor, empty for the charger default

func (*Loadpoint) GetDisableDelay

func (lp *Loadpoint) GetDisableDelay() time.Duration

GetDisableDelay gets the loadpoint enable delay

func (*Loadpoint) GetDisableThreshold

func (lp *Loadpoint) GetDisableThreshold() float64

GetDisableThreshold gets the loadpoint enable threshold

func (*Loadpoint) GetEnableDelay

func (lp *Loadpoint) GetEnableDelay() time.Duration

GetEnableDelay gets the loadpoint enable delay

func (*Loadpoint) GetEnableThreshold

func (lp *Loadpoint) GetEnableThreshold() float64

GetEnableThreshold gets the loadpoint enable threshold

func (*Loadpoint) GetLimitEnergy

func (lp *Loadpoint) GetLimitEnergy() float64

GetLimitEnergy returns the session limit energy

func (*Loadpoint) GetLimitSoc

func (lp *Loadpoint) GetLimitSoc() int

GetLimitSoc returns the session limit soc

func (*Loadpoint) GetMaxCurrent

func (lp *Loadpoint) GetMaxCurrent() float64

GetMaxCurrent returns the max loadpoint current

func (*Loadpoint) GetMaxPhaseCurrent

func (lp *Loadpoint) GetMaxPhaseCurrent() float64

GetMaxPhaseCurrent returns the maximum charge current per phase or- if not available- the offered current from either charger or charge meter

func (*Loadpoint) GetMeasuredPhases

func (lp *Loadpoint) GetMeasuredPhases() int

GetMeasuredPhases provides synchronized access to measuredPhases

func (*Loadpoint) GetMeterRef

func (lp *Loadpoint) GetMeterRef() string

GetMeter returns the loadpoint meter

func (*Loadpoint) GetMinCurrent

func (lp *Loadpoint) GetMinCurrent() float64

GetMinCurrent returns the min loadpoint current

func (*Loadpoint) GetMinSoc

func (lp *Loadpoint) GetMinSoc() int

GetMinSoc returns the loadpoint min soc (heating: min temperature)

func (*Loadpoint) GetMode

func (lp *Loadpoint) GetMode() api.ChargeMode

GetMode returns loadpoint charge mode

func (*Loadpoint) GetPhases

func (lp *Loadpoint) GetPhases() int

GetPhases returns the enabled phases

func (*Loadpoint) GetPhasesConfigured

func (lp *Loadpoint) GetPhasesConfigured() int

GetPhasesConfigured returns the configured phases

func (*Loadpoint) GetPlan

func (lp *Loadpoint) GetPlan(targetTime time.Time, requiredDuration, precondition time.Duration, continuous bool) api.Rates

GetPlan creates a charging plan for given time and duration The plan is sorted by time

func (*Loadpoint) GetPlanEnergy

func (lp *Loadpoint) GetPlanEnergy() (time.Time, float64)

GetPlanEnergy returns plan target energy

func (*Loadpoint) GetPlanGoal

func (lp *Loadpoint) GetPlanGoal() (float64, bool)

GetPlanGoal returns the plan goal in %, true or kWh, false

func (*Loadpoint) GetPlanRemainingEnergy

func (lp *Loadpoint) GetPlanRemainingEnergy() float64

GetPlanRemainingEnergy returns the energy plan's missing energy in kWh

func (*Loadpoint) GetPlanRequiredDuration

func (lp *Loadpoint) GetPlanRequiredDuration(goal, maxPower float64) time.Duration

GetPlanRequiredDuration is the estimated total charging duration

func (*Loadpoint) GetPlanStrategy

func (lp *Loadpoint) GetPlanStrategy() api.PlanStrategy

GetPlanStrategy returns the plan strategy

func (*Loadpoint) GetPriority

func (lp *Loadpoint) GetPriority() int

GetPriority returns the loadpoint priority

func (*Loadpoint) GetRemainingDuration

func (lp *Loadpoint) GetRemainingDuration() time.Duration

GetRemainingDuration is the estimated remaining charging duration

func (*Loadpoint) GetRemainingEnergy

func (lp *Loadpoint) GetRemainingEnergy() float64

GetRemainingEnergy is the remaining charge energy in kWh

func (*Loadpoint) GetSmartCostLimit

func (lp *Loadpoint) GetSmartCostLimit() *float64

GetSmartCostLimit gets the smart cost limit. The optimizer replaces it in automatic mode, so it reads as unset and none of its consumers apply it.

func (*Loadpoint) GetSmartFeedInPriorityLimit

func (lp *Loadpoint) GetSmartFeedInPriorityLimit() *float64

GetSmartFeedInPriorityLimit gets the smart feed-in limit. The optimizer replaces it in automatic mode, so it reads as unset.

func (*Loadpoint) GetSoc

func (lp *Loadpoint) GetSoc() float64

GetSoc returns the estimated vehicle soc in %

func (*Loadpoint) GetSocConfig

func (lp *Loadpoint) GetSocConfig() loadpoint.SocConfig

GetSoc returns the PV mode threshold settings

func (*Loadpoint) GetSocPlanGoals

func (lp *Loadpoint) GetSocPlanGoals() []loadpoint.PlanGoal

GetSocPlanGoals returns the soc goals of all vehicle plans, repeating plans for each occurrence within a week. Unlike nextVehiclePlan it includes later and already reached plans.

func (*Loadpoint) GetSolarShare

func (lp *Loadpoint) GetSolarShare() float64

GetSolarShare gets the solar share

func (*Loadpoint) GetStatus

func (lp *Loadpoint) GetStatus() api.ChargeStatus

GetStatus returns the charging status

func (*Loadpoint) GetThresholds

func (lp *Loadpoint) GetThresholds() loadpoint.ThresholdsConfig

GetThresholds returns the PV mode threshold settings

func (*Loadpoint) GetTitle

func (lp *Loadpoint) GetTitle() string

GetTitle returns the loadpoint title

func (*Loadpoint) GetUI

func (lp *Loadpoint) GetUI() loadpoint.UIConfig

GetUI returns the display-only ui settings

func (*Loadpoint) GetVehicle

func (lp *Loadpoint) GetVehicle() api.Vehicle

GetVehicle gets the active vehicle

func (*Loadpoint) HasChargeMeter

func (lp *Loadpoint) HasChargeMeter() bool

HasChargeMeter determines if a physical charge meter is attached

func (*Loadpoint) IsFastChargingActive

func (lp *Loadpoint) IsFastChargingActive() bool

IsFastChargingActive indicates if fast charging with maximum power is active

func (*Loadpoint) LimitEnergyReached

func (lp *Loadpoint) LimitEnergyReached() bool

LimitEnergyReached checks if target is configured and reached

func (*Loadpoint) LimitSocReached

func (lp *Loadpoint) LimitSocReached() bool

LimitSocReached returns true if the effective limit has been reached

func (*Loadpoint) Lock

func (lp *Loadpoint) Lock()

func (*Loadpoint) MaxActivePhases

func (lp *Loadpoint) MaxActivePhases() int

MaxActivePhases returns the maximum number of active phases for the loadpoint.

func (*Loadpoint) MinActivePhases

func (lp *Loadpoint) MinActivePhases() int

MinActivePhases returns the minimum number of active phases for the loadpoint.

func (*Loadpoint) OptimizerPlan

func (lp *Loadpoint) OptimizerPlan(planTime time.Time) (api.Rates, float64)

OptimizerPlan returns the optimizer's remaining charging schedule up to the plan time and its average power, nil if the optimizer is not in charge. Later slots serve surplus, not the plan.

func (*Loadpoint) Prepare

func (lp *Loadpoint) Prepare(site site.API, uiChan chan<- util.Param, pushChan chan<- messenger.Event, lpChan chan<- *Loadpoint)

Prepare loadpoint configuration by adding missing helper elements

func (*Loadpoint) PublishEffectiveValues

func (lp *Loadpoint) PublishEffectiveValues()

PublishEffectiveValues publishes all effective values

func (*Loadpoint) PvChargeStarting

func (lp *Loadpoint) PvChargeStarting() bool

PvChargeStarting reports a PV loadpoint that claimed surplus via a running enable timer but is not yet drawing it and has not reached its goal. See #31194, #31684.

func (*Loadpoint) RLock

func (lp *Loadpoint) RLock()

func (*Loadpoint) RUnlock

func (lp *Loadpoint) RUnlock()

func (*Loadpoint) RequestUpdate

func (lp *Loadpoint) RequestUpdate()

RequestUpdate requests site to update this loadpoint

func (*Loadpoint) ResetMeasuredPhases

func (lp *Loadpoint) ResetMeasuredPhases()

ResetMeasuredPhases resets measured phases to unknown on vehicle disconnect, phase switch or phase api call

func (*Loadpoint) SetAlwaysCharge

func (lp *Loadpoint) SetAlwaysCharge(ac api.AlwaysCharge) error

SetAlwaysCharge sets the always charge state

func (*Loadpoint) SetBatteryBoost

func (lp *Loadpoint) SetBatteryBoost(enable bool) error

SetBatteryBoost sets the battery boost

func (*Loadpoint) SetBatteryBoostLimit

func (lp *Loadpoint) SetBatteryBoostLimit(limit int)

SetBatteryBoostLimit sets the battery boost soc limit. Relaxing the limit resumes a boost held by it, 100 disables the feature and ends an active boost.

func (*Loadpoint) SetChargerRef

func (lp *Loadpoint) SetChargerRef(ref string)

SetChargerRef sets the loadpoint charger

func (*Loadpoint) SetCircuitRef

func (lp *Loadpoint) SetCircuitRef(ref string)

SetCircuitRef sets the loadpoint circuit

func (*Loadpoint) SetDefaultMode

func (lp *Loadpoint) SetDefaultMode(mode api.ChargeMode)

SetDefaultMode sets the default charge mode

func (*Loadpoint) SetDefaultVehicleRef

func (lp *Loadpoint) SetDefaultVehicleRef(ref string)

SetDefaultVehicleRef returns the loadpoint default vehicle

func (*Loadpoint) SetDemandPredictor

func (lp *Loadpoint) SetDemandPredictor(predictor string)

SetDemandPredictor sets the demand predictor ("daily", "weekday", "temperature" or empty for the charger default), other values are ignored

func (*Loadpoint) SetDisableDelay

func (lp *Loadpoint) SetDisableDelay(delay time.Duration)

SetDisableDelay sets loadpoint disable delay

func (*Loadpoint) SetDisableThreshold

func (lp *Loadpoint) SetDisableThreshold(threshold float64)

SetDisableThreshold sets loadpoint disable threshold

func (*Loadpoint) SetEnableDelay

func (lp *Loadpoint) SetEnableDelay(delay time.Duration)

SetEnableDelay sets loadpoint enable delay

func (*Loadpoint) SetEnableThreshold

func (lp *Loadpoint) SetEnableThreshold(threshold float64)

SetEnableThreshold sets loadpoint enable threshold

func (*Loadpoint) SetLimitEnergy

func (lp *Loadpoint) SetLimitEnergy(energy float64)

SetLimitEnergy sets the session energy limit

func (*Loadpoint) SetLimitSoc

func (lp *Loadpoint) SetLimitSoc(soc int)

SetLimitSoc sets the session soc limit

func (*Loadpoint) SetMaxCurrent

func (lp *Loadpoint) SetMaxCurrent(current float64) error

SetMaxCurrent sets the max loadpoint current

func (*Loadpoint) SetMeterRef

func (lp *Loadpoint) SetMeterRef(ref string)

SetMeter sets the loadpoint meter

func (*Loadpoint) SetMinCurrent

func (lp *Loadpoint) SetMinCurrent(current float64) error

SetMinCurrent sets the min loadpoint current

func (*Loadpoint) SetMinSoc

func (lp *Loadpoint) SetMinSoc(soc int)

SetMinSoc sets the loadpoint min soc (heating: min temperature)

func (*Loadpoint) SetMode

func (lp *Loadpoint) SetMode(mode api.ChargeMode)

SetMode sets loadpoint charge mode

func (*Loadpoint) SetPhases

func (lp *Loadpoint) SetPhases(phases int)

SetPhases sets the number of enabled phases without modifying the charger

func (*Loadpoint) SetPhasesConfigured

func (lp *Loadpoint) SetPhasesConfigured(phases int) error

SetPhasesConfigured sets the configured phases

func (*Loadpoint) SetPlanEnergy

func (lp *Loadpoint) SetPlanEnergy(finishAt time.Time, energy float64) error

SetPlanEnergy sets plan target energy

func (*Loadpoint) SetPlanStrategy

func (lp *Loadpoint) SetPlanStrategy(strategy api.PlanStrategy) error

SetPlanStrategy sets the plan strategy

func (*Loadpoint) SetPriority

func (lp *Loadpoint) SetPriority(prio int)

SetPriority sets the loadpoint priority

func (*Loadpoint) SetRemainingDuration

func (lp *Loadpoint) SetRemainingDuration(chargeRemainingDuration time.Duration)

SetRemainingDuration sets the estimated remaining charging duration

func (*Loadpoint) SetRemainingEnergy

func (lp *Loadpoint) SetRemainingEnergy(chargeRemainingEnergy float64)

SetRemainingEnergy sets the remaining charge energy in kWh

func (*Loadpoint) SetSmartCostLimit

func (lp *Loadpoint) SetSmartCostLimit(val *float64) error

SetSmartCostLimit sets the smart cost limit

func (*Loadpoint) SetSmartFeedInPriorityLimit

func (lp *Loadpoint) SetSmartFeedInPriorityLimit(val *float64) error

SetSmartFeedInPriorityLimit sets the smart cost feed-in

func (*Loadpoint) SetSocConfig

func (lp *Loadpoint) SetSocConfig(soc loadpoint.SocConfig)

SetSoc sets the PV mode threshold settings

func (*Loadpoint) SetSolarShare

func (lp *Loadpoint) SetSolarShare(val float64)

SetSolarShare sets the solar share

func (*Loadpoint) SetThresholds

func (lp *Loadpoint) SetThresholds(thresholds loadpoint.ThresholdsConfig)

SetThresholds sets the PV mode threshold settings

func (*Loadpoint) SetTitle

func (lp *Loadpoint) SetTitle(title string)

SetTitle sets the loadpoint title

func (*Loadpoint) SetUI

func (lp *Loadpoint) SetUI(ui loadpoint.UIConfig)

SetUI sets the display-only ui settings. Not used in control logic.

func (*Loadpoint) SetVehicle

func (lp *Loadpoint) SetVehicle(vehicle api.Vehicle)

SetVehicle sets the active vehicle

func (*Loadpoint) SocBasedPlanning

func (lp *Loadpoint) SocBasedPlanning() bool

SocBasedPlanning returns true if soc based planning is enabled

func (*Loadpoint) StartVehicleDetection

func (lp *Loadpoint) StartVehicleDetection()

StartVehicleDetection allows triggering vehicle detection for debugging purposes

func (*Loadpoint) Unlock

func (lp *Loadpoint) Unlock()

func (*Loadpoint) Update

func (lp *Loadpoint) Update(sitePower, batteryPower float64, consumption, feedin api.Rates, batteryBuffered, batteryStart bool, greenShare float64, effPrice, effCo2 *float64, dim *bool)

Update is the main control function. It reevaluates meters and charger state

func (*Loadpoint) UpdateChargePowerAndCurrents

func (lp *Loadpoint) UpdateChargePowerAndCurrents() float64

UpdateChargePowerAndCurrents updates charge meter power and currents for load management

type MetersConfig

type MetersConfig struct {
	GridMeterRef      string   `mapstructure:"grid"`     // Grid usage meter
	PVMetersRef       []string `mapstructure:"pv"`       // PV meter
	BatteryMetersRef  []string `mapstructure:"battery"`  // Battery charging meter
	ExtMetersRef      []string `mapstructure:"ext"`      // Meters used only for monitoring
	AuxMetersRef      []string `mapstructure:"aux"`      // Auxiliary meters
	ConsumerMetersRef []string `mapstructure:"consumer"` // Consumer meters
}

MetersConfig contains the site's meter configuration

type PlanLock

type PlanLock struct {
	Time time.Time // target time (committed goal, persists during overrun)
	Soc  int       // target soc
	Id   int       // id (0=none, 1=static, 2+=repeating), needed to highlight the plan in ui
}

PlanLock contains information about a locked plan. It caches the goal a soc-based plan has committed to, so that an overrunning plan keeps charging towards that goal instead of jumping to the next plan. The lock must be dropped whenever the goal inputs change- plan time, plan soc or the set of plans itself.

type Progress

type Progress struct {
	// contains filtered or unexported fields
}

func NewProgress

func NewProgress(min, step float64) *Progress

func (*Progress) NextStep

func (p *Progress) NextStep(value float64) bool

func (*Progress) Reset

func (p *Progress) Reset()

type Site

type Site struct {
	sync.RWMutex

	// configuration
	Title         string       `mapstructure:"title"`         // UI title
	Voltage       float64      `mapstructure:"voltage"`       // Deprecated: ignored, the nominal voltage is fixed
	ResidualPower float64      `mapstructure:"residualPower"` // PV meter only: household usage. Grid meter: household safety margin
	Meters        MetersConfig `mapstructure:"meters"`        // Meter references
	CurtailersRef []string     `mapstructure:"curtailers"`    // Curtailment device references
	// contains filtered or unexported fields
}

Site is the main configuration container. A site can host multiple loadpoints.

func NewSite

func NewSite() *Site

NewSite creates a Site with sane defaults

func NewSiteFromConfig

func NewSiteFromConfig(other map[string]any) (*Site, error)

NewSiteFromConfig creates a new site

func (*Site) ActiveLoadpoints

func (site *Site) ActiveLoadpoints() iter.Seq2[int, loadpoint.API]

ActiveLoadpoints yields enabled loadpoints with their stable index

func (*Site) Automatic

func (site *Site) Automatic() bool

Automatic returns true if the optimizer controls the home battery instead of only advising

func (*Site) AutomaticLoadpoints

func (site *Site) AutomaticLoadpoints() bool

AutomaticLoadpoints returns true if the optimizer controls the loadpoints as well

func (*Site) Boot

func (site *Site) Boot(log *util.Logger, loadpoints []*Loadpoint, tariffs *tariff.Tariffs) error

func (*Site) DumpConfig

func (site *Site) DumpConfig()

DumpConfig site configuration

func (*Site) ExplainFeedback

func (site *Site) ExplainFeedback(ctx context.Context, vote, comment string) error

ExplainFeedback votes on the last explanation: up or down, with an optional comment. The plan and the explanation go along, the optimizer service stores nothing before a vote.

func (*Site) ExplainOptimizerResult

func (site *Site) ExplainOptimizerResult(ctx context.Context, language string) error

ExplainOptimizerResult asks the optimizer service why the last plan looks the way it does. Repeated calls for the same plan and language return the previous explanation.

func (*Site) GetAuxMeterRefs

func (site *Site) GetAuxMeterRefs() []string

GetAuxMeterRefs returns the AuxMeterRef

func (*Site) GetBatteryDischargeControl

func (site *Site) GetBatteryDischargeControl() bool

GetBatteryDischargeControl returns the battery control mode (no discharge only). The optimizer replaces it in automatic mode, so it reads as disabled.

func (*Site) GetBatteryGridChargeLimit

func (site *Site) GetBatteryGridChargeLimit() *float64

The optimizer replaces the limit in automatic mode, so it reads as unset.

func (*Site) GetBatteryGridDischarge

func (site *Site) GetBatteryGridDischarge() bool

GetBatteryGridDischarge returns whether the battery may discharge to grid (experimental)

func (*Site) GetBatteryGridDischargeLimit

func (site *Site) GetBatteryGridDischargeLimit() *float64

func (*Site) GetBatteryMaxDischargePower

func (site *Site) GetBatteryMaxDischargePower() *float64

GetBatteryMaxDischargePower returns the current battery max discharge power

func (*Site) GetBatteryMeterRefs

func (site *Site) GetBatteryMeterRefs() []string

GetBatteryMeterRefs returns the BatteryMeterRef

func (*Site) GetBatteryMode

func (site *Site) GetBatteryMode() api.BatteryMode

GetBatteryMode returns the battery mode

func (*Site) GetBatteryModeExternal

func (site *Site) GetBatteryModeExternal() api.BatteryMode

GetBatteryModeExternal returns the external battery mode

func (*Site) GetBatterySoc

func (site *Site) GetBatterySoc() float64

GetBatterySoc returns the current battery soc

func (*Site) GetBufferSoc

func (site *Site) GetBufferSoc() float64

GetBufferSoc returns the BufferSoc

func (*Site) GetBufferStartSoc

func (site *Site) GetBufferStartSoc() float64

GetBufferStartSoc returns the BufferStartSoc

func (*Site) GetCircuit

func (site *Site) GetCircuit() api.Circuit

GetCircuit returns the root circuit

func (*Site) GetConsumerMeterRefs

func (site *Site) GetConsumerMeterRefs() []string

GetConsumerMeterRefs returns the ConsumerMeterRef

func (*Site) GetCountry

func (site *Site) GetCountry() string

GetCountry returns the ISO 3166-1 alpha-2 country code

func (*Site) GetCurtailerRefs

func (site *Site) GetCurtailerRefs() []string

GetCurtailerRefs returns the curtailment device references

func (*Site) GetExtMeterRefs

func (site *Site) GetExtMeterRefs() []string

GetExtMeterRefs returns the ExtMeterRef

func (*Site) GetGridConnection

func (site *Site) GetGridConnection() string

GetGridConnection returns the grid connection, 3p4w (with neutral, default) or 3p3w (without neutral)

func (*Site) GetGridExportLimit

func (site *Site) GetGridExportLimit() float64

GetGridExportLimit returns the static grid export power limit in W (0 = disabled)

func (*Site) GetGridMeterRef

func (site *Site) GetGridMeterRef() string

GetGridMeterRef returns the GridMeterRef

func (*Site) GetGridPower

func (site *Site) GetGridPower() float64

GetGridPower returns the most recent grid power reading in W (positive = import)

func (*Site) GetOptimizerChargingStrategy

func (site *Site) GetOptimizerChargingStrategy() string

GetOptimizerChargingStrategy returns the optimizer grid charging strategy, falling back to the default when unset.

func (*Site) GetOptimizerRiskProfile

func (site *Site) GetOptimizerRiskProfile() *api.RiskProfile

GetOptimizerRiskProfile returns the forecast uncertainty the optimizer hedges against, nil = none

func (*Site) GetPVMeterRefs

func (site *Site) GetPVMeterRefs() []string

GetPVMeterRefs returns the PvMeterRef

func (*Site) GetPrioritySoc

func (site *Site) GetPrioritySoc() float64

GetPrioritySoc returns the PrioritySoc

func (*Site) GetProfilePercentile

func (site *Site) GetProfilePercentile() *float64

GetProfilePercentile returns the percentile of the historic energy profiles in %, nil = average

func (*Site) GetResidualPower

func (site *Site) GetResidualPower() float64

GetResidualPower returns the ResidualPower

func (*Site) GetSolarAdjusted

func (site *Site) GetSolarAdjusted() bool

GetSolarAdjusted returns if the solar forecast is adjusted to real production data

func (*Site) GetTariff

func (site *Site) GetTariff(tariff api.TariffUsage) api.Tariff

GetTariff returns the respective tariff if configured or nil

func (*Site) GetTitle

func (site *Site) GetTitle() string

GetTitle returns the title

func (*Site) IsConfigured

func (site *Site) IsConfigured() bool

func (*Site) Loadpoints

func (site *Site) Loadpoints() []loadpoint.API

Loadpoints returns the loadpoints as api interfaces. Disabled loadpoints are returned as nil to keep indexes stable.

func (*Site) Optimize

func (site *Site) Optimize()

Optimize updates the optimizer

func (*Site) Prepare

func (site *Site) Prepare(valueChan chan<- util.Param, pushChan chan<- messenger.Event)

Prepare attaches communication channels to site and loadpoints

func (*Site) Publish

func (site *Site) Publish(key string, val any)

publish sends values to UI and databases

func (*Site) Run

func (site *Site) Run(stopC chan struct{}, interval time.Duration)

Run is the main control loop. It reacts to trigger events by updating measurements and executing control logic.

func (*Site) SetAuxMeterRefs

func (site *Site) SetAuxMeterRefs(ref []string)

SetAuxMeterRefs sets the AuxMeterRef

func (*Site) SetBatteryDischargeControl

func (site *Site) SetBatteryDischargeControl(val bool) error

SetBatteryDischargeControl sets the battery control mode (no discharge only)

func (*Site) SetBatteryGridChargeLimit

func (site *Site) SetBatteryGridChargeLimit(val *float64) error

func (*Site) SetBatteryGridDischarge

func (site *Site) SetBatteryGridDischarge(val bool) error

SetBatteryGridDischarge sets whether the battery may discharge to grid (experimental)

func (*Site) SetBatteryGridDischargeLimit

func (site *Site) SetBatteryGridDischargeLimit(val *float64) error

func (*Site) SetBatteryMeterRefs

func (site *Site) SetBatteryMeterRefs(ref []string)

SetBatteryMeterRefs sets the BatteryMeterRef

func (*Site) SetBatteryMode

func (site *Site) SetBatteryMode(batMode api.BatteryMode)

SetBatteryMode sets the battery mode

func (*Site) SetBatteryModeExternal

func (site *Site) SetBatteryModeExternal(mode api.BatteryMode) error

SetBatteryModeExternal sets the external battery mode

func (*Site) SetBufferSoc

func (site *Site) SetBufferSoc(soc float64) error

SetBufferSoc sets the BufferSoc

func (*Site) SetBufferStartSoc

func (site *Site) SetBufferStartSoc(soc float64) error

SetBufferStartSoc sets the BufferStartSoc

func (*Site) SetConsumerMeterRefs

func (site *Site) SetConsumerMeterRefs(ref []string)

SetConsumerMeterRefs sets the ConsumerMeterRef

func (*Site) SetCountry

func (site *Site) SetCountry(country string)

SetCountry sets the ISO 3166-1 alpha-2 country code

func (*Site) SetCurtailerRefs

func (site *Site) SetCurtailerRefs(ref []string)

SetCurtailerRefs sets the curtailment device references

func (*Site) SetExtMeterRefs

func (site *Site) SetExtMeterRefs(ref []string)

SetExtMeterRefs sets the ExtMeterRef

func (*Site) SetGridConnection

func (site *Site) SetGridConnection(conn string)

SetGridConnection sets the grid connection and applies it to the current to power conversion

func (*Site) SetGridExportLimit

func (site *Site) SetGridExportLimit(power float64) error

SetGridExportLimit sets the static grid export power limit in W (0 = disabled)

func (*Site) SetGridMeterRef

func (site *Site) SetGridMeterRef(ref string)

SetGridMeterRef sets the GridMeterRef

func (*Site) SetHEMS

func (site *Site) SetHEMS(hems api.HEMS)

SetHEMS attaches the configured HEMS to the site and the root circuit

func (*Site) SetOptimizerChargingStrategy

func (site *Site) SetOptimizerChargingStrategy(strategy string) error

SetOptimizerChargingStrategy validates and persists the optimizer grid charging strategy and re-runs the optimizer when it changes.

func (*Site) SetOptimizerRiskProfile

func (site *Site) SetOptimizerRiskProfile(profile *api.RiskProfile) error

SetOptimizerRiskProfile sets the forecast uncertainty the optimizer hedges against, nil = none

func (*Site) SetPVMeterRefs

func (site *Site) SetPVMeterRefs(ref []string)

SetPVMeterRefs sets the PvMeterRef

func (*Site) SetPrioritySoc

func (site *Site) SetPrioritySoc(soc float64) error

SetPrioritySoc sets the PrioritySoc

func (*Site) SetProfilePercentile

func (site *Site) SetProfilePercentile(percentile *float64) error

SetProfilePercentile sets the percentile of the historic energy profiles in %, nil = average

func (*Site) SetResidualPower

func (site *Site) SetResidualPower(power float64) error

SetResidualPower sets the ResidualPower

func (*Site) SetSolarAdjusted

func (site *Site) SetSolarAdjusted(val bool)

SetSolarAdjusted sets if the solar forecast is adjusted to real production data

func (*Site) SetTitle

func (site *Site) SetTitle(title string)

SetTitle sets the title

func (*Site) Vehicles

func (site *Site) Vehicles() site.Vehicles

Vehicles returns the site vehicles

type Stats

type Stats struct {
	// contains filtered or unexported fields
}

Publishes long term charging statistics

func NewStats

func NewStats() *Stats

func (*Stats) Update

func (s *Stats) Update(p publisher)

Update publishes stats based on charging sessions

type Task

type Task = func()

Task is the task type

type Timer

type Timer struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Timer measures active time between start and stop events

func NewTimer

func NewTimer() *Timer

NewTimer creates timer that can expire

func (*Timer) Elapsed

func (m *Timer) Elapsed() WakeUpEvent

Elapsed checks if the timer has elapsed and if resets its status

func (*Timer) Running

func (m *Timer) Running() bool

func (*Timer) Start

func (m *Timer) Start()

Start starts the timer if not started already

func (*Timer) Stop

func (m *Timer) Stop()

Reset resets the timer

type WakeUpEvent

type WakeUpEvent int
const (
	WakeUpTimerInactive WakeUpEvent = iota
	WakeUpTimerElapsed
	WakeUpTimerFinished
)

Directories

Path Synopsis
Package loadpoint is a generated GoMock package.
Package loadpoint is a generated GoMock package.
Package vehicle is a generated GoMock package.
Package vehicle is a generated GoMock package.

Jump to

Keyboard shortcuts

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