core

package
v0.0.0-...-4b6ff7e Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: MIT Imports: 36 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GridTariff    = "grid"
	FeedinTariff  = "feedin"
	PlannerTariff = "planner"
)

Variables

View Source
var ErrBatteryNotConfigured = errors.New("battery not configured")
View Source
var (

	// Voltage global value
	Voltage float64
)

Functions

func NewCircuitFromConfig

func NewCircuitFromConfig(log *util.Logger, other map[string]interface{}) (api.Circuit, error)

NewCircuitFromConfig creates a new Circuit

Types

type Circuit

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

the circuit instances to control the load

func NewCircuit

func NewCircuit(log *util.Logger, title string, maxCurrent, maxPower float64, meter api.Meter) (*Circuit, error)

NewCircuit creates a circuit

func (*Circuit) GetChargePower

func (c *Circuit) GetChargePower() float64

GetChargePower returns the actual power

func (*Circuit) GetMaxCurrent

func (c *Circuit) GetMaxCurrent() float64

GetMaxCurrent returns the max current setting

func (*Circuit) GetMaxPhaseCurrent

func (c *Circuit) GetMaxPhaseCurrent() float64

GetMaxPhaseCurrent returns the actual current

func (*Circuit) GetMaxPower

func (c *Circuit) GetMaxPower() float64

GetMaxPower returns the max power setting

func (*Circuit) GetParent

func (c *Circuit) GetParent() api.Circuit

GetParent returns the parent circuit

func (*Circuit) GetTitle

func (c *Circuit) GetTitle() string

func (*Circuit) HasMeter

func (c *Circuit) HasMeter() bool

HasMeter returns the max power setting

func (*Circuit) RegisterChild

func (c *Circuit) RegisterChild(child api.Circuit)

RegisterChild registers child circuit

func (*Circuit) SetMaxCurrent

func (c *Circuit) SetMaxCurrent(current float64)

SetMaxCurrent sets the max current

func (*Circuit) SetMaxPower

func (c *Circuit) SetMaxPower(power float64)

SetMaxPower sets the max power

func (*Circuit) SetParent

func (c *Circuit) SetParent(parent api.Circuit)

SetParent set parent circuit

func (*Circuit) SetTitle

func (c *Circuit) SetTitle(title string)

func (*Circuit) Update

func (c *Circuit) Update(loadpoints []api.CircuitLoad) (err error)

func (*Circuit) ValidateCurrent

func (c *Circuit) ValidateCurrent(old, new float64) (res float64)

ValidateCurrent validates current request

func (*Circuit) ValidatePower

func (c *Circuit) ValidatePower(old, new float64) float64

ValidatePower validates power request

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 NewEnergyMetrics

func NewEnergyMetrics() *EnergyMetrics

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 Health

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

Health is a health checker that needs regular updates to stay healthy

func NewHealth

func NewHealth(timeout time.Duration) *Health

NewHealth creates new health checker

func (*Health) Healthy

func (health *Health) Healthy() bool

Healthy returns health status based on last update timestamp

func (*Health) Update

func (health *Health) Update()

Update updates the health timer on each loadpoint update

type Loadpoint

type Loadpoint struct {

	// exposed public configuration
	sync.RWMutex // guard status

	Mode_ api.ChargeMode `mapstructure:"mode"` // Default charge mode, used for disconnect

	Title_          string `mapstructure:"title"`    // UI title
	Priority_       int    `mapstructure:"priority"` // Priority
	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             SocConfig
	Enable, Disable ThresholdConfig

	// TODO deprecated
	GuardDuration_    time.Duration `mapstructure:"guardduration"` // charger enable/disable minimum holding time
	ConfiguredPhases_ int           `mapstructure:"phases"`
	MinCurrent_       float64       `mapstructure:"minCurrent"`
	MaxCurrent_       float64       `mapstructure:"maxCurrent"`
	// 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) *Loadpoint

NewLoadpoint creates a Loadpoint with sane defaults

func NewLoadpointFromConfig

func NewLoadpointFromConfig(log *util.Logger, settings *Settings, other map[string]interface{}) (*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) EffectiveMaxPower

func (lp *Loadpoint) EffectiveMaxPower() float64

EffectiveMaxPower returns the effective max power taking vehicle capabilities and phase scaling into account

func (*Loadpoint) EffectiveMinPower

func (lp *Loadpoint) EffectiveMinPower() float64

EffectiveMinPower returns the effective min power for a single phase

func (*Loadpoint) EffectivePlanSoc

func (lp *Loadpoint) EffectivePlanSoc() int

EffectivePlanSoc returns the soc target for the current plan

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) GetChargePower

func (lp *Loadpoint) GetChargePower() float64

GetChargePower returns the current charge power

func (*Loadpoint) GetChargePowerFlexibility

func (lp *Loadpoint) GetChargePowerFlexibility() float64

GetChargePowerFlexibility returns the flexible amount of current charging power

func (*Loadpoint) GetCircuit

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

GetCircuit returns the assigned circuit

func (*Loadpoint) GetDisableThreshold

func (lp *Loadpoint) GetDisableThreshold() float64

GetDisableThreshold gets the loadpoint enable threshold

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 current charge power

func (*Loadpoint) GetMaxPower

func (lp *Loadpoint) GetMaxPower() float64

GetMaxPower returns the max loadpoint power taking vehicle capabilities and phase scaling into account

func (*Loadpoint) GetMinCurrent

func (lp *Loadpoint) GetMinCurrent() float64

GetMinCurrent returns the min loadpoint current

func (*Loadpoint) GetMinPower

func (lp *Loadpoint) GetMinPower() float64

GetMinPower returns the min loadpoint power for a single phase

func (*Loadpoint) GetMode

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

GetMode returns loadpoint charge mode

func (*Loadpoint) GetPhases

func (lp *Loadpoint) GetPhases() int

GetPhases returns loadpoint enabled phases

func (*Loadpoint) GetPlan

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

GetPlan creates a charging plan for given time and duration

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) GetPlanRequiredDuration

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

GetPlanRequiredDuration is the estimated total charging duration

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 Wh

func (*Loadpoint) GetSmartCostLimit

func (lp *Loadpoint) GetSmartCostLimit() float64

GetSmartCostLimit gets the smart cost limit

func (*Loadpoint) GetStatus

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

GetStatus returns the charging status

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) Prepare

func (lp *Loadpoint) Prepare(uiChan chan<- util.Param, pushChan chan<- push.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) RemoteControl

func (lp *Loadpoint) RemoteControl(source string, demand loadpoint.RemoteDemand)

RemoteControl sets remote status demand

func (*Loadpoint) SetDisableThreshold

func (lp *Loadpoint) SetDisableThreshold(threshold float64)

SetDisableThreshold sets loadpoint disable threshold

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) SetMinCurrent

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

SetMinCurrent sets the min loadpoint current

func (*Loadpoint) SetMode

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

SetMode sets loadpoint charge mode

func (*Loadpoint) SetPhases

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

SetPhases sets loadpoint enabled phases

func (*Loadpoint) SetPlanEnergy

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

SetPlanEnergy sets plan target energy

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 Wh

func (*Loadpoint) SetSmartCostLimit

func (lp *Loadpoint) SetSmartCostLimit(val float64)

SetSmartCostLimit sets the smart cost limit

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) Title

func (lp *Loadpoint) Title() string

Title returns the human-readable loadpoint title

func (*Loadpoint) Update

func (lp *Loadpoint) Update(sitePower float64, autoCharge, batteryBuffered, batteryStart bool, greenShare float64, effPrice, effCo2 *float64)

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

func (*Loadpoint) UpdateChargePowerAndCurrents

func (lp *Loadpoint) UpdateChargePowerAndCurrents()

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
	AuxMetersRef     []string `mapstructure:"aux"`     // Auxiliary meters
}

MetersConfig contains the loadpoint's meter configuration

type PollConfig

type PollConfig struct {
	Mode     string        `mapstructure:"mode"`     // polling mode charging (default), connected, always
	Interval time.Duration `mapstructure:"interval"` // interval when not charging
}

PollConfig defines the vehicle polling mode and interval

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 Settings

type Settings struct {
	Key string
}

func (*Settings) Bool

func (s *Settings) Bool(key string) (bool, error)

func (*Settings) Float

func (s *Settings) Float(key string) (float64, error)

func (*Settings) Int

func (s *Settings) Int(key string) (int64, error)

func (*Settings) SetBool

func (s *Settings) SetBool(key string, val bool)

func (*Settings) SetFloat

func (s *Settings) SetFloat(key string, val float64)

func (*Settings) SetInt

func (s *Settings) SetInt(key string, val int64)

func (*Settings) SetString

func (s *Settings) SetString(key string, val string)

func (*Settings) SetTime

func (s *Settings) SetTime(key string, val time.Time)

func (*Settings) String

func (s *Settings) String(key string) (string, error)

func (*Settings) Time

func (s *Settings) Time(key string) (time.Time, error)

type Site

type Site struct {
	*Health

	sync.RWMutex

	// configuration
	Title         string       `mapstructure:"title"`         // UI title
	Voltage       float64      `mapstructure:"voltage"`       // Operating voltage. 230V for Germany.
	ResidualPower float64      `mapstructure:"residualPower"` // PV meter only: household usage. Grid meter: household safety margin
	Meters        MetersConfig `mapstructure:"meters"`        // Meter references
	CircuitRef    string       `mapstructure:"circuit"`       // Circuit reference

	MaxGridSupplyWhileBatteryCharging float64 `mapstructure:"maxGridSupplyWhileBatteryCharging"` // ignore battery charging if AC consumption is above this value
	// 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(
	log *util.Logger,
	other map[string]interface{},
	loadpoints []*Loadpoint,
	tariffs *tariff.Tariffs,
) (*Site, error)

NewSiteFromConfig creates a new site

func (*Site) DumpConfig

func (site *Site) DumpConfig()

DumpConfig site configuration

func (*Site) GetAuxMeterRefs

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

GetAuxMeterRefs returns the AuxMeterRef

func (*Site) GetBatteryDischargeControl

func (site *Site) GetBatteryDischargeControl() bool

GetBatteryControl returns the battery control mode

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) 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 circuit

func (*Site) GetGridMeterRef

func (site *Site) GetGridMeterRef() string

GetGridMeterRef returns the GridMeterRef

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) GetResidualPower

func (site *Site) GetResidualPower() float64

GetResidualPower returns the ResidualPower

func (*Site) GetTariff

func (site *Site) GetTariff(tariff string) 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) Loadpoints

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

Loadpoints returns the loadpoints as api interfaces

func (*Site) Prepare

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

Prepare attaches communication channels to site and loadpoints

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

SetBatteryControl sets the battery control mode

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) 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) SetGridMeterRef

func (site *Site) SetGridMeterRef(ref string)

SetGridMeterRef sets the GridMeterRef

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) SetResidualPower

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

SetResidualPower sets the ResidualPower

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 SocConfig

type SocConfig struct {
	Poll     PollConfig `mapstructure:"poll"`
	Estimate *bool      `mapstructure:"estimate"`
}

SocConfig defines soc settings, estimation and update behavior

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 ThresholdConfig

type ThresholdConfig struct {
	Delay     time.Duration
	Threshold float64
}

ThresholdConfig defines enable/disable hysteresis parameters

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) Expired

func (m *Timer) Expired() bool

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

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

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