rasProject_01 / weSweetHome  R. 116 2026-05-14
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 ballast loading (LiFePo4).
#define BAT_KEEP_PWM
 Battery keep alive PWM setting (LiFePo4).
#define BAT_LDBAL_STR_PWM
 PWM start value for ballast loading.
#define BAT_LDBAL_TIM
 Maximum time for battery loading as ballast.
#define BAT_LDMX_PWM
 Battery maximum load PWM setting (LiFePo4).
#define BAT_LOAD_PWM
 Value for permanent loading.
#define BAT_LOD_END_MAX_POW
 Battery controlled load end phase maximum power.
#define BAT_LOD_END_MIN_POW
 Battery controlled load end phase minimum power.
#define BAT_LOD_NRM_MAX_POW
 Battery controlled load maximum power.
#define BAT_LOD_NRM_MIN_POW
 Battery controlled load maximum power.
#define BAT_NOLD_PWM
 Battery no load no keep setting (LiFePo4).
#define BAT_TNUM
 Battery type number.
#define BAT_TYPE
 Battery type.
#define BATkeepInhByCmd
 Inhibit battery keep loading after battery Off command.
#define BATkeepInhContLoad
 Inhibit battery keep loading after controlled loading.
#define BATkeepInhUnload
 Inhibit battery keep loading after unloading.
#define BATmaxUNLODtime
 Upper time limit (s) to stop discharging (LiFePo4).
#define BATVOLT_LO_LIM_UNLD
 Voltage limit to start unload.
#define BATVOLT_LO_LIM_UNLD400
 Voltage limit to start unload after ballast load.
#define BATVOLT_LO_STP_UNLD
 Lower voltage limit to stop discharging (LiFePo4).
#define BATVOLT_MX_STRT_LOAD
 Upper voltage limit with no load to start ballast loading (LiFePo4).
#define BATVOLT_UP_LIM_LOAD
 Upper voltage limit to stop loading.
#define ESP_U_CORR
 Correction factor for ESP battery voltmeter.
#define PDEL_MINP_INV
 Minimum power from public electricity for discharge inverter start.
#define PDEL_MINP_UNL
 Minimum power from public electricity supplier to start discharging.
#define PDEL_STOP_UNL
 Minimum power from public electricity to stop discharging.
#define PINV_MIN_ON
 Minimum discharge power to consider discharge inverter on.

Variables

uint16_t hundredsV
 The battery voltage in 0.01V units.

Detailed Description

Common types and values for buffer battery handling.

Revision history

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 far below, due to the age and principal limits of lead acid accumulators.

In August 2024 all were replaced by one, since February 2025 two and since November 2025 three parallel 12,8V 100Ah ECO-WORTHY LiFePo4 accumulators. Compared to lead acid, all loading, keeping and unloading constants and procedures had to be changed. The effective capacity is about 1.8 kWh with some (safe) reserve in both directions.

Battery voltage is measured at the battery clamps by an own MQTT device (using this include, mqttHome.h and 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

◆ 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. Both types are 12V and for a fixed nominal capacity.
LeadAcid batteries were dumped as not fit for PV buffering. Type (1 = LeadAcid, 12V) isn't implemented any more.

◆ 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 (controlled, batUnloadStatChg) unloading shall not be started respectively inhibited. The current value is 300 W.
Rationale: Battery power shall not flow into public power grid or be used to heat domestic hot water.
See also: PDEL_MINP_INV
Used in: batUnloadStatChg

◆ 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).
The current value is 130 W.
Used in: batUnloadStatChg

◆ PINV_MIN_ON

#define PINV_MIN_ON

Minimum discharge power to consider discharge inverter on.

The current value is 53W.
Used in: batUnloadStatChg

◆ 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 all 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.
Used in: batUnloadStatChg

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_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 13h (since 22.01.2026).
Since 26.08.2025 this limit was 8h and before, especially with lead acid accumulators, it was much lower. Currently we have 3 * 100 aH * 12V LiFePo4 batteries. For currently 160 W discharging from 90 to 10% (SoC) would take 18h. 13h should be quite save if other end criteria fail.

Contrary to lead acid batteries LiFePo4 accumulators come with well defined discharging curves / tables. The voltage yields a reliable end criterion, here. Hence, this end time feature - the live belt for lead acid - is not critical.
Used in: batUnloadStatChg

◆ 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.
Hint: The "inhibit keep timer" starts battery keeping when running out.
The current value is 3 hours.
Used in: batUnloadStatChg

◆ BATkeepInhContLoad

#define BATkeepInhContLoad

Inhibit battery keep loading after controlled loading.

The current value is 30 minutes.
Used in: batCntLodStatChg

See also
BATkeepInhUnload BATkeepInhByCmd batKeepInh

◆ BATkeepInhByCmd

#define BATkeepInhByCmd

Inhibit battery keep loading after battery Off command.

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

◆ 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.21V (30% on the "books" idle curve).
Used in: batUnloadStatChg

See also
BATVOLT_LO_STP_UNLD

◆ BATVOLT_LO_LIM_UNLD400

#define BATVOLT_LO_LIM_UNLD400

Voltage limit to start unload after ballast load.

This is the minimal voltage to allow starting an unload sequence directly after ballast loading when receiving public grid power <= 400V.
Current value 13.22V (40% on the "books" idle curve).

Used in: batCntBalStatChg

See also
BATVOLT_LO_STP_UNLD BATVOLT_LO_STP_UNLD PDEL_BALEND

◆ 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.85 V (10% on "book" idle curve).

Used in: batCntBalStatChg batUnloadStatChg

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. The current value is 13 hours.
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.

Used in: batCntBalStatChg

See also
loadModUlookup

◆ BAT_LDBAL_STR_PWM

#define BAT_LDBAL_STR_PWM

PWM start value for ballast loading.

The current value is 135 (pwm = 13.88V) to have a quick start.

Used in: batCntBalStatChg

See also
loadModUlookup

◆ 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. current value 50.

Used in: switchBatToStepUp changeBatLoadPWM

See also
BATVOLT_LO_STP_UNLD loadModUlookup batUnloadStatChg batCntBalStatChg batCntLodStatChg

◆ 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_KEEP_PWM

#define BAT_KEEP_PWM

Battery keep alive PWM setting (LiFePo4).

This is the PWM setting for the battery load module for permanently keeping the battery at live by preventing self discharge and by feeding the (low) permanent loads. The value is 68 (13.20V).

See also
loadModUlookup

◆ BAT_LDMX_PWM

#define BAT_LDMX_PWM

Battery maximum load PWM setting (LiFePo4).

N.b.: The value 14.6V is the value for full loading. Without load current the voltage will rise by the 0.4V drop of the (parallel) Schottky diodes. Hence monitoring BATVOLT_UP_LIM_LOAD is essential.
Current value 235 (14.6V).

◆ BATVOLT_MX_STRT_LOAD

#define BATVOLT_MX_STRT_LOAD

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

When without load worth speaking of, say 24W / 2A for capacity >= 200Ah, the battery voltage is above this limit the start of ballast loading 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 on the BatteryFinds.com table. The EcoWorthy "book" delivered with the batteries is higher. BATVOLT_MX_STRT_LOAD is applied to ballast loading, only.

◆ BAT_BAL_STRT_PWM

#define BAT_BAL_STRT_PWM

Start value for ballast loading (LiFePo4).

The value is 81 (= 13.37V).

◆ BAT_LOAD_PWM

#define BAT_LOAD_PWM

Value for permanent loading.

The value was 63 (= 13.12V = 25% "book") and is reduced to 46 (12,85V = 25% "BatteryFinds.com).

See also
BAT_BAL_STRT_PWM

◆ BAT_LOD_NRM_MAX_POW

#define BAT_LOD_NRM_MAX_POW

Battery controlled load maximum power.

For controlled (resp. ordered unconditional) battery charging this value is the maximum power. If higher the output of the charging module will be reduced.
This condition can be checked when an actual charging power measurement is available. As water heating and battery charging use the same power meter heating would spoil the value; see batLoadPowValid.

The current value is 144.4 W.

See also
BAT_LOD_NRM_MIN_POW BAT_LOD_END_MAX_POW BAT_LOD_END_MIN_POW

◆ BAT_LOD_NRM_MIN_POW

#define BAT_LOD_NRM_MIN_POW

Battery controlled load maximum power.

For controlled (resp. ordered unconditional) battery charging this value is the minimum power; see BAT_LOD_NRM_MAX_POW.
The current value is 84.4 W.

◆ BAT_LOD_END_MAX_POW

#define BAT_LOD_END_MAX_POW

Battery controlled load end phase maximum power.

When the end criteria for controlled load are reached a low charging power end or keep fresh phase is entered.
Note: This feature is inherited from the quite complex handling of lead acid accumulator and may be removed.

The current value is 68.4 W.

See also
BAT_LOD_NRM_MAX_POW BAT_LOD_END_MIN_POW

◆ BAT_LOD_END_MIN_POW

#define BAT_LOD_END_MIN_POW

Battery controlled load end phase minimum power.

The current value is 31.4 W.

See also
BAT_LOD_END_MAX_POW

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 integer value will be kept "forever".
It is preset with 1289 (12.89 V) to avoid "battery low" status 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

to format as "12.89" without trailing zero.

See also
formFixed16 valFilVal batVoltValid