Update is the main control function. It reevaluates meters and charger state
(sitePower, batteryBoostPower float64, consumption, feedin api.Rates, batteryBuffered, batteryStart bool, greenShare float64, effPrice, effCo2 *float64, dim *bool)
| 1987 | |
| 1988 | // Update is the main control function. It reevaluates meters and charger state |
| 1989 | func (lp *Loadpoint) Update(sitePower, batteryBoostPower float64, consumption, feedin api.Rates, batteryBuffered, batteryStart bool, greenShare float64, effPrice, effCo2 *float64, dim *bool) { |
| 1990 | // auto-disable battery boost when SOC drops below limit |
| 1991 | if lp.GetBatteryBoost() != boostDisabled { |
| 1992 | if limit := lp.GetBatteryBoostLimit(); limit < 100 { |
| 1993 | if batterySoc := lp.site.GetBatterySoc(); batterySoc < float64(limit) { |
| 1994 | lp.log.DEBUG.Printf("battery boost disabled: soc below limit (%.0f%% < %d%%)", batterySoc, limit) |
| 1995 | |
| 1996 | if err := lp.SetBatteryBoost(false); err != nil { |
| 1997 | lp.log.ERROR.Printf("set battery boost: %v", err) |
| 1998 | } |
| 1999 | } |
| 2000 | } |
| 2001 | } |
| 2002 | |
| 2003 | // smart cost |
| 2004 | smartCostActive, smartCostNextStart := lp.checkSmartLimit(lp.GetSmartCostLimit(), consumption, true) |
| 2005 | lp.publish(keys.SmartCostActive, smartCostActive) |
| 2006 | lp.publish(keys.SmartCostNextStart, smartCostNextStart) |
| 2007 | |
| 2008 | smartFeedInPriorityActive, smartFeedInPriorityNextStart := lp.checkSmartLimit(lp.GetSmartFeedInPriorityLimit(), feedin, false) |
| 2009 | lp.publish(keys.SmartFeedInPriorityActive, smartFeedInPriorityActive) |
| 2010 | lp.publish(keys.SmartFeedInPriorityNextStart, smartFeedInPriorityNextStart) |
| 2011 | |
| 2012 | // long-running tasks |
| 2013 | lp.processTasks() |
| 2014 | |
| 2015 | // read and publish meters first- charge power and currents have already been updated by the site |
| 2016 | lp.updateChargeVoltages() |
| 2017 | lp.phasesFromChargeCurrents() |
| 2018 | |
| 2019 | lp.energyMetrics.SetEnvironment(greenShare, effPrice, effCo2) |
| 2020 | |
| 2021 | // update ChargeRater here to make sure initial meter update is caught |
| 2022 | lp.bus.Publish(evChargeCurrent, lp.offeredCurrent) |
| 2023 | lp.bus.Publish(evChargePower, lp.chargePower) |
| 2024 | |
| 2025 | // update progress and soc before status is updated |
| 2026 | lp.publishChargeProgress() |
| 2027 | lp.PublishEffectiveValues() |
| 2028 | |
| 2029 | // §14a |
| 2030 | if dimmer, ok := api.Cap[api.Dimmer](lp.charger); ok { |
| 2031 | dimmed, err := dimmer.Dimmed() |
| 2032 | if err != nil { |
| 2033 | lp.log.ERROR.Printf("dimmed: %v", err) |
| 2034 | return |
| 2035 | } |
| 2036 | |
| 2037 | if dim != nil { |
| 2038 | if *dim != dimmed { |
| 2039 | if err := dimmer.Dim(*dim); err != nil { |
| 2040 | lp.log.ERROR.Printf("dim: %v", err) |
| 2041 | return |
| 2042 | } |
| 2043 | |
| 2044 | lp.publish(keys.Dimmed, *dim) |
| 2045 | lp.log.INFO.Printf("§14a dim: %t", *dim) |
| 2046 | } |