rasProject_01 / weSweetHome  R. 102 2025-10-31
process control       /     RasPi software         by   weinert-automation
Loading...
Searching...
No Matches
weBatt.h File Reference

Common types and values for buffer battery handling. More...

#include "basicTyCo.h"

Macros

#define BAT_BAL_STRT_PWM
 Start value for loading (LiFePo4). More...
 
#define BAT_KEEP_PWM
 Battery keep alive PWM setting (LiFePo4). More...
 
#define BAT_LD8H_PWM
 Battery maximum load for 8 hours PWM setting (LiFePo4). More...
 
#define BAT_LDBAL_STR_PWM
 PWM start value for ballast loading. More...
 
#define BAT_LDBAL_TIM
 Maximum time for battery loading as ballast. More...
 
#define BAT_LDMX_PWM
 Battery maximum load PWM setting (LiFePo4). More...
 
#define BAT_LDTEST_MAX_PWM
 Battery maximum test PWM setting (LiFePo4). More...
 
#define BAT_LOAD_PWM
 Value for permanent loading. More...
 
#define BAT_MXBL_PWM
 Battery maximum ballast load for PWM setting (LiFePo4). More...
 
#define BAT_NOLD_PWM
 Battery no load no keep setting (LiFePo4). More...
 
#define BAT_TNUM
 Battery type number. More...
 
#define BAT_TYPE
 Battery type. More...
 
#define BATkeepInhByCmd
 Inhibit battery keep loading after battery Off command. More...
 
#define BATkeepInhContLoad
 Inhibit battery keep loading after controlled loading. More...
 
#define BATkeepInhUnload
 Inhibit battery keep loading after unloading. More...
 
#define BATmaxUNLODtime
 Upper time limit (s) to stop discharging (LiFePo4). More...
 
#define BATVOLT_LO_LIM_UNLD
 Voltage limit to start unload. More...
 
#define BATVOLT_LO_STP_UNLD
 Lower voltage limit to stop discharging (LiFePo4). More...
 
#define BATVOLT_MX_STRT_LOAD
 Upper voltage limit with no load to start loading (LiFePo4). More...
 
#define BATVOLT_UP_LIM_LOAD
 Upper voltage limit to stop loading. More...
 
#define ESP_U_CORR
 Correction factor for ESP battery voltmeter. More...
 
#define PDEL_MINP_INV
 Minimum power from public electricity for discharge inverter start. More...
 
#define PDEL_MINP_UNL
 Minimum power from public electricity supplier to start discharging. More...
 
#define PDEL_STOP_UNL
 Minimum power from public electricity to stop discharging. More...
 
#define PINV_MIN_ON
 Minimum discharge power to consider discharge inverter on. More...
 

Variables

uint16_t hundredsV
 The battery voltage in 0.01V units. More...
 

Detailed Description

Common types and values for buffer battery handling.

Copyright (c) 2018, 2025 Albrecht Weinert
weinert-automation.de a-weinert.de
/ / /\
/ /___ / \ |
\ /____\ /____\ | _|__
\ /\ / \ / \| |
\/ \/ \__/ \__/|_

Revision history

Rev. 96 14.10.2025
Rev. 159 04.07.2018 : new
Rev. 191 15.02.2019 : comment text changes; upper ballast limit reduced
Rev. 200 16.04.2019 : battery keep inhibit until low stress
Rev. 223 24.04.2020 : comment clarifications, voltage adjustments
Rev. 259 04.08.2022 : battery changed to ECO-WORTHY 12.8V 100Ah LiFePO4 accu
Rev. 260 06.08.2024 : correct LiFePO4 accumulator values (hopefully)
Rev. 263 06.10.2024 : lead acid put to include file, better LiFePo limits
Rev. 266 10.10.2024 : battery unload TO increased from 4 to 5h
Rev. 268 15.10.2024 : ESP_U_CORR introduced to correct ESP voltmeter
Rev. 75 25.02.2025 : lead acid batteries ("type 1") cancelled
Rev. 79 21.03.2025 : values changed due to "unload experiences", keep 36
Rev. 83 30.05.2025 : BATVOLT_MX_STRT_LOAD new start loading limit (80%)
Rev. 88 05.07.2025 : battery unload limit Ubat++, Psuppl++, etc
Rev. 89 21.07.2025 : typos, battery unload limit 11.9V,
26.07.2025 : ESP_U_CORR for 13,4 <-- 13,26 discrepancy
Rev. 91 10.08.2025 : values for new load module 0..24V 20A
Rev. 92 26.08.2025 : load unload values and SFCs (Rev. 92..94, 02.09.)
Rev. 94 24.09.2025 : charge module settings changed, hence pwm settings &c.
Rev. 96 12.10.2025 : BATVOLT_LO_STP_UNLD 12.49
#define BATVOLT_MX_STRT_LOAD
Upper voltage limit with no load to start loading (LiFePo4).
Definition: weBatt.h:333
#define BATVOLT_LO_STP_UNLD
Lower voltage limit to stop discharging (LiFePo4).
Definition: weBatt.h:211
#define ESP_U_CORR
Correction factor for ESP battery voltmeter.
Definition: weBatt.h:128

In the smart home buffer batteries are used.

Originally, we had an array of parallel 12V (6 cell) lead acid batteries. It summed up to about 200Ah and should allow buffering 1 kWh. The usable capacity of the batteries formerly used in cars and glider starting winches was much less, due to the age and principal limits of lead acid accumulators.

In August 2024 all were replaced by one and since February 2025 two 12,8V 100Ah LiPoFe accumulators (by ECO-WORTHY). In consequence all loading, keeping and unloading constants and procedures had to be changed. Their 200Ah now allow 1 real kWh and sometimes more.

Battery voltage is measured at the battery clamps by an own MQTT device (using this software mqttHome.h, sweetHome2.c). It uses WLAN and has a 12V supply. It just "lives" directly on the battery at an own fuse needing no extra hardware.

Macro Definition Documentation

◆ PDEL_MINP_UNL

#define PDEL_MINP_UNL

Minimum power from public electricity supplier to start discharging.

If public power consumption is below this limit battery unloading shall not be started respectively inhibited. The current value is 200 W.
Rationale: Battery power shall not flow into public power grid or be used to heat domestic hot water. See also PDEL_MINP_INV

◆ PDEL_MINP_INV

#define PDEL_MINP_INV

Minimum power from public electricity for discharge inverter start.

This is the lower equivalent to PDEL_MINP_UNL. If public power consumption is fallen below this value while waiting for the inverter to start discharging we consider the pre-condition gone.
This event is not quite probable. So this feature may be removed (after not seeing "noCons" for a year in the log).

◆ PINV_MIN_ON

#define PINV_MIN_ON

Minimum discharge power to consider discharge inverter on.

The current value is 53W.

◆ PDEL_STOP_UNL

#define PDEL_STOP_UNL

Minimum power from public electricity to stop discharging.

We inhibit all power delivery to the public grid. Especially we do not discharge the batteries when not consuming battery power. As we can't control discharge power and re-starting discharge takes long (thanks to VDE-AR-N 4105, a German "unique selling point") we allow very low negative power hardly / not fully measured by Ferraris counters biased to start on minimal positive values. See also PDEL_MINP_INV PDEL_MINP_UNL

◆ ESP_U_CORR

#define ESP_U_CORR

Correction factor for ESP battery voltmeter.

Due to tolerances the value delivered via MQTT is a bit too low. This factor is a good average correction and may be put into the ESP voltmeter ¶ęC some day.
On the other hand changing this factor on Pi C Eclipse ... environment is loads more easy and less (hardware) error prone than handling an ESP.

◆ BAT_TNUM

#define BAT_TNUM

Battery type number.

The battery type as integer number co-responding to the text, see BAT_TYPE. LiFePo4 has number 2 and LeadAcid has 1.
LeadAcid batteries were dumped as not fit for PV buffering. That type (1 = LeadAcid, 12V, 200Ah) isn't implemented any more.

◆ BAT_TYPE

#define BAT_TYPE

Battery type.

The battery type as text, like LiFePo4 or LeadAcid.
As C's macro handling is too stupid to compare strings we have a co-responding integer type number BAT_TNUM 2.

◆ BATmaxUNLODtime

#define BATmaxUNLODtime

Upper time limit (s) to stop discharging (LiFePo4).

The normal discharge end condition in the unload SFC would be battery voltage (BATVOLT_LO_STP_UNLD). Additionally there is this time limit of currently 8h (as of 26.08.2025).

◆ BATkeepInhUnload

#define BATkeepInhUnload

Inhibit battery keep loading after unloading.

Start battery keeping immediately after unloading would most probably be unnecessary charging as we are on the discharge curve. As we have ample reserve we may consider the base load 10..20W as mildly unloading.
The current value is 6h20min.

◆ BATkeepInhContLoad

#define BATkeepInhContLoad

Inhibit battery keep loading after controlled loading.

The current value is 2 hours.

◆ BATkeepInhByCmd

#define BATkeepInhByCmd

Inhibit battery keep loading after battery Off command.

The current value is 20 minutes from now. If the inhibit timer is running already its end time will eventually be prolonged but not shortened.

◆ BATVOLT_LO_LIM_UNLD

#define BATVOLT_LO_LIM_UNLD

Voltage limit to start unload.

This is the minimal voltage to allow starting an unload sequence.
Current value 13.06V (20% on the idle curve).

See also
BATVOLT_LO_STP_UNLD

◆ BATVOLT_LO_STP_UNLD

#define BATVOLT_LO_STP_UNLD

Lower voltage limit to stop discharging (LiFePo4).

This is the minimal voltage, measured under 5..10% cap unload, to stop a running unload sequence for providing buffer capacity needed.

This is a critical value. Choosing a value too high reduces the usable buffer capacity (the battery's purpose in life). A value too low endangers the battery.

To allow for permanent loads without being forced to load within the next 24 hours we intend to stop in the range 30..20%.
The current value is 12.49 (less than 10% on idle curve).

See also
BATVOLT_LO_LIM_UNLD BAT_KEEP_PWM

◆ BAT_LDBAL_TIM

#define BAT_LDBAL_TIM

Maximum time for battery loading as ballast.

This time limit is the last resort to stop overloading as ballast for surplus power.
This feature is not necessary as the LiPoFe batteries protect themselves against over charging and the current loading module max. voltage of 14.75V (+ 0.4V for the Schottky diodes 15.15V) is within the limits.

◆ BAT_LDBAL_STR_PWM

#define BAT_LDBAL_STR_PWM

PWM start value for ballast loading.

The current value 233 to have a quick start. See also BAT_LDTEST_MAX_PWM

◆ BAT_LDTEST_MAX_PWM

#define BAT_LDTEST_MAX_PWM

Battery maximum test PWM setting (LiFePo4).

Max. PWM for battery charging module. The current module allows 255 = 100% = 14.75V (+0.4V when the Schottky voltage drop disappears at very low current) is well within the batteries operating range.

See also BAT_LDTEST_MAX_PWM, BAT_LDTEST_MIN_PWM, BAT_LDTEST_UPS_PWM, BAT_LDTEST_DWN_PWM, setBatLoadPWM

◆ BAT_NOLD_PWM

#define BAT_NOLD_PWM

Battery no load no keep setting (LiFePo4).

This is the PWM setting for neither charging nor keeping. Until August 2024 it was 0 for the array of old lead acid starter batteries.

"LiFePO4 battery cells have a maximum discharge depth of 98% to 100%. This is longer than any other battery technology currently in the market. This means that you can safely discharge these batteries to their full capacity. However, most manufacturers recommend still using a 80% depth of discharge for these batteries to prolong their lifespan. Even if you occasionally use 100% of the battery capacity, the battery will not get harmed." cited from [https://ecotreelithium.co.uk/news/lifepo4-battery-depth-of-discharge/]

For neither keeping or loading we permanently back the battery with 12.5V (+0.4V on no current) to keep about 10%. The relation between BATVOLT_LO_STP_UNLD and BAT_NOLD_PWM shall not lead to start keeping immediately after unloading. Check regularly.

See also
BATVOLT_LO_STP_UNLD loadModUlookup

◆ BATVOLT_UP_LIM_LOAD

#define BATVOLT_UP_LIM_LOAD

Upper voltage limit to stop loading.

The battery loading SFCs would stop when this voltage is reached. Full loading would require 14.6 V and for safety reasons one should be more below, perhaps. 14.88V is overcharge protection and 14.4V is the cell equalising start voltage. On the other hand EcoWorth's LiFePo4 12V 100Ah has a built in battery management system (BSM), which would cut of at overvoltage.

See also
BAT_LDMX_PWM BAT_LD8H_PWM

◆ BAT_KEEP_PWM

#define BAT_KEEP_PWM

Battery keep alive PWM setting (LiFePo4).

This is the PWM setting for the battery load module, see loadModUlookup, for permanently keeping the battery at live by preventing self discharge and feeding low permanent loads.
Value since 24.09.2025, 111 LiFePo4: 12.85V = 10%

◆ BAT_LDMX_PWM

#define BAT_LDMX_PWM

Battery maximum load PWM setting (LiFePo4).

Intended charger max. voltage 14.25V
Note: The value 14.6 for pwm 255 is the value for full loading. Without load current the voltage will be at least by the 0.4V drop for of the Schottky diodes higher. Hence monitoring BATVOLT_UP_LIM_LOAD is essential and this value, probably should be lower than the current (14.9.25) value.
See also BAT_LD8H_PWM, BAT_LDMX_PWM for future adjustments

◆ BAT_LD8H_PWM

#define BAT_LD8H_PWM

Battery maximum load for 8 hours PWM setting (LiFePo4).

The current value is the same as BAT_LDMX_PWM. Having different constant constant macros was for the sake of (past) lead acid batteries.

◆ BAT_MXBL_PWM

#define BAT_MXBL_PWM

Battery maximum ballast load for PWM setting (LiFePo4).

Intended charger max. voltage is 14.2V for ballast loading. This is the 80% voltage on the LiFePo charging curve.

◆ BATVOLT_MX_STRT_LOAD

#define BATVOLT_MX_STRT_LOAD

Upper voltage limit with no load to start loading (LiFePo4).

When without load worth speaking of, say 24W / 2A for 200Ah capacity, the battery voltage is above this limit the start of any load sequence is inhibited. The value is not used for stopping a load process as the allowed voltages on the LiFePo4 loading curve are significantly higher.
Note: The current no load value of 13.35V is 80% capacity on the idle curve. A running load process may load to a higher capacity rate, but we won't start loading over 80%.

◆ BAT_BAL_STRT_PWM

#define BAT_BAL_STRT_PWM

Start value for loading (LiFePo4).

The value is 81 (= 13.37V).

◆ BAT_LOAD_PWM

#define BAT_LOAD_PWM

Value for permanent loading.

The value is 63 (= 13.12V = 25%).
See also BAT_BAL_STRT_PWM

Variable Documentation

◆ hundredsV

uint16_t hundredsV
extern

The battery voltage in 0.01V units.

This is just an integer value consistent to the last valid battery voltage measurement valFilVal.batVolt. Contrary to valFilVal.batVolt which is set to -0.9 to indicate invalidity after 2.4s without new (MQTT) measurements, this value will be kept (forever).
It is preset with 1289 (12.89 V) lest have battery low before the first valid MQTT measurement / message.
Receiving a good MQTT message from the battery voltmeter will set valFilVal.batVolt, batVoltValid and this value.
Use formFixed16(&textStart, hundredsV, 2) to format as "12.89" without trailing zero.

See also
formFixed16 valFilVal batVoltValid