core

package
v0.0.0-...-175a4df Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2023 License: MIT Imports: 32 Imported by: 0

Documentation

Index

Constants

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

Variables

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 *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.Mutex // guard status

	Mode api.ChargeMode `mapstructure:"mode"` // Charge mode, guarded by mutex

	Title_            string   `mapstructure:"title"`    // UI title
	Priority_         int      `mapstructure:"priority"` // Priority
	ConfiguredPhases  int      `mapstructure:"phases"`   // Charger configured phase mode 0/1/3
	ChargerRef        string   `mapstructure:"charger"`  // Charger reference
	VehicleRef        string   `mapstructure:"vehicle"`  // Vehicle reference
	VehiclesRef_      []string `mapstructure:"vehicles"` // TODO deprecated
	MeterRef          string   `mapstructure:"meter"`    // Charge meter reference
	Soc               SocConfig
	Enable, Disable   ThresholdConfig
	ResetOnDisconnect bool `mapstructure:"resetOnDisconnect"`

	MinCurrent    float64       // PV mode: start current	Min+PV mode: min current
	MaxCurrent    float64       // Max allowed current. Physically ensured by the charger
	GuardDuration time.Duration // charger enable/disable minimum holding time
	// 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) *Loadpoint

NewLoadpoint creates a Loadpoint with sane defaults

func NewLoadpointFromConfig

func NewLoadpointFromConfig(log *util.Logger, other map[string]interface{}) (*Loadpoint, error)

NewLoadpointFromConfig creates a new loadpoint

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

func (lp *Loadpoint) GetMaxCurrent() float64

GetMaxCurrent returns the max loadpoint current

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

func (lp *Loadpoint) GetMinSoc() int

GetMinSoc returns loadpoint charge minimum soc

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, maxPower float64) (time.Duration, api.Rates, error)

GetPlan creates a charging plan

Results: - required total charging duration - actual charging plan as rate table

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

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

GetStatus returns the charging status

func (*Loadpoint) GetTargetEnergy

func (lp *Loadpoint) GetTargetEnergy() float64

GetTargetEnergy returns loadpoint charge target energy

func (*Loadpoint) GetTargetSoc

func (lp *Loadpoint) GetTargetSoc() int

GetTargetSoc returns loadpoint charge target soc

func (*Loadpoint) GetTargetTime

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

GetTargetTime returns the target time

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

func (lp *Loadpoint) SetMaxCurrent(current float64)

SetMaxCurrent sets the max loadpoint current

func (*Loadpoint) SetMinCurrent

func (lp *Loadpoint) SetMinCurrent(current float64)

SetMinCurrent sets the min loadpoint current

func (*Loadpoint) SetMinSoc

func (lp *Loadpoint) SetMinSoc(soc int)

SetMinSoc sets loadpoint charge minimum soc

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

func (lp *Loadpoint) SetTargetEnergy(energy float64)

SetTargetEnergy sets loadpoint charge target energy

func (*Loadpoint) SetTargetSoc

func (lp *Loadpoint) SetTargetSoc(soc int)

SetTargetSoc sets loadpoint charge target soc

func (*Loadpoint) SetTargetTime

func (lp *Loadpoint) SetTargetTime(finishAt time.Time) error

SetTargetTime sets the charge target time

func (*Loadpoint) SetVehicle

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

SetVehicle sets the active vehicle

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

func (lp *Loadpoint) UpdateChargePower()

UpdateChargePower updates charge meter power

type MetersConfig

type MetersConfig struct {
	GridMeterRef      string   `mapstructure:"grid"`      // Grid usage meter
	PVMetersRef       []string `mapstructure:"pv"`        // PV meter
	PVMetersRef_      []string `mapstructure:"pvs"`       // TODO deprecated
	BatteryMetersRef  []string `mapstructure:"battery"`   // Battery charging meter
	BatteryMetersRef_ []string `mapstructure:"batteries"` // TODO deprecated
	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 Site

type Site struct {
	*Health

	sync.Mutex

	// 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 // Meter references
	PrioritySoc                       float64      `mapstructure:"prioritySoc"`                       // prefer battery up to this Soc
	BufferSoc                         float64      `mapstructure:"bufferSoc"`                         // continue charging on battery above this Soc
	BufferStartSoc                    float64      `mapstructure:"bufferStartSoc"`                    // start charging on battery above this Soc
	MaxGridSupplyWhileBatteryCharging float64      `mapstructure:"maxGridSupplyWhileBatteryCharging"` // ignore battery charging if AC consumption is above this value
	SmartCostLimit                    float64      `mapstructure:"smartCostLimit"`                    // always charge if cost is below 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) GetBufferSoc

func (site *Site) GetBufferSoc() float64

GetBufferSoc returns the BufferSoc

func (*Site) GetBufferStartSoc

func (site *Site) GetBufferStartSoc() float64

GetBufferStartSoc returns the BufferStartSoc

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

func (site *Site) GetSmartCostLimit() float64

GetSmartCostLimit returns the SmartCostLimit

func (*Site) GetTariff

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

GetTariff returns the respective tariff if configured or nil

func (*Site) GetVehicles

func (site *Site) GetVehicles() []api.Vehicle

GetVehicles is the list of vehicles

func (*Site) Loadpoints

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

Loadpoints returns the array of associated loadpoints

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

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

SetSmartCostLimit sets the SmartCostLimit

type SocConfig

type SocConfig struct {
	Poll     PollConfig `mapstructure:"poll"`
	Estimate *bool      `mapstructure:"estimate"`
	Min_     int        `mapstructure:"min"`    // TODO deprecated
	Target_  int        `mapstructure:"target"` // TODO deprecated
	// contains filtered or unexported fields
}

SocConfig defines soc settings, estimation and update behaviour

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

type Updater

type Updater interface {
	loadpoint.API
	Update(availablePower float64, autoCharge, batteryBuffered, batteryStart bool, greenShare float64, effectivePrice, effectiveCo2 *float64)
}

Updater abstracts the Loadpoint implementation for testing

Directories

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

Jump to

Keyboard shortcuts

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