core

package
v0.0.0-...-aa513c4 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2024 License: MIT Imports: 38 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

This section is empty.

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 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 the minimum active phases

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

func (lp *Loadpoint) GetBatteryBoost() bool

GetBatteryBoost returns the battery boost

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

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

SetBatteryBoost sets the battery boost

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) 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, batteryBoostPower float64, rates api.Rates, 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() 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
}

MetersConfig contains the site'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
	// TODO deprecated
	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(other map[string]interface{}) (*Site, error)

NewSiteFromConfig creates a new site

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

func (*Site) GetBatteryGridChargeLimit

func (site *Site) GetBatteryGridChargeLimit() *float64

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 root 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

SetBatteryDischargeControl sets the battery control mode (no discharge only)

func (*Site) SetBatteryGridChargeLimit

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

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

func (site *Site) SetCircuit(circuit api.Circuit)

SetCircuit sets the root circuit

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