Charging cycles published 0 instead of NaN when no BMS is combined
bms_base_charging_cycles.yaml coerced a NaN raw reading to 0 before adding
the user offset, instead of letting NaN propagate like the sensors fixed
in dee203e4 ("Sensors published to NAN when no BMS is combined"). *_raw is
NaN until the first trusted BMS frame arrives after a reboot, so both
`charging cycles` and `total charging cycle capacity` published a literal
0 during that transient - with `state_class: total`, that 0 also landed
in Home Assistant's long-term statistics.
Fix is to drop the two `if (isnan(...)) = 0;` coercions and let
`NaN + offset == NaN` propagate, so both sensors go unavailable through
the transient instead of reporting 0.
Both sensors also moved from `or: [throttle: 10s, delta: 1]` to the
NaN-safe rate-limit filter already used throughout yambms_core.yaml, since
the built-in `delta` filter drops a NaN transition without updating its
reference and would otherwise freeze the sensor on its last value for up
to 10s.
That filter is extracted from yambms_core.yaml into
packages/base/device_base.yaml, which every node loads via its board_*.yaml
regardless of whether it runs the YamBMS engine - unlike yambms_core.yaml,
which is absent from a multi-node Modbus-server node that only exposes
BMS/Shunt packages. Renamed yambms_rate_limit_filter to rate_limit_filter
now that it is no longer engine-specific.
This commit is contained in:
1 parent
9dd22fa56b
commit
7d00721dfe
3 files changed
+84
-82
No files matched your search
@@ -1,5 +1,5 @@
|
||||
# Updated : 2026.03.23
|
||||
# Version : 1.2.7
|
||||
# Updated : 2026.08.29
|
||||
# Version : 1.2.8
|
||||
# GitHub : https://github.com/Sleeper85/esphome-yambms
|
||||
|
||||
# YamBMS ( Yet another multi-BMS Merging Solution )
|
||||
@@ -23,6 +23,39 @@ packages:
|
||||
fault_registry: !include device_base_fault_registry.yaml
|
||||
|
||||
substitutions:
|
||||
# +----------------------------------------------------------------------+
|
||||
# | Rate-limit filter - NaN-safe replacement for `or: throttle + delta` |
|
||||
# +----------------------------------------------------------------------+
|
||||
# ESPHome's `delta` filter rejects a NaN without updating its internal
|
||||
# reference, so a sensor that publishes NaN stays frozen on its previous
|
||||
# value until `throttle` fires (up to 10s). YamBMS publishes NaN on purpose
|
||||
# to mean "no data", so the NaN <-> value transition must count as a change,
|
||||
# in both directions - including a return to the very same value.
|
||||
# Defined here (rather than in yambms_core.yaml) so it is reachable from a
|
||||
# node that only loads BMS/Shunt packages, without the YamBMS engine (e.g.
|
||||
# a multi-node Modbus server) - every node loads a board_*.yaml, which
|
||||
# always includes this file.
|
||||
# Usage: declare `const float delta` (delta threshold) then expand it.
|
||||
# filters:
|
||||
# - lambda: |-
|
||||
# const float delta = 1.0f; # delta: 1
|
||||
# ${rate_limit_filter} # improved `throttle: 10s`
|
||||
# Must stay capture-free: a filter lambda is compiled to a plain function
|
||||
# pointer (StatelessLambdaFilter), so no id() reference is allowed here.
|
||||
rate_limit_filter_ms: '10000' # 10s
|
||||
rate_limit_filter: |-
|
||||
static float last = NAN;
|
||||
static uint32_t last_ms = 0;
|
||||
const uint32_t now = millis();
|
||||
if ((std::isnan(x) != std::isnan(last)) ||
|
||||
(!std::isnan(x) && fabsf(x - last) >= delta) ||
|
||||
((now - last_ms) >= ${rate_limit_filter_ms}))
|
||||
{
|
||||
last = x;
|
||||
last_ms = now;
|
||||
return x;
|
||||
}
|
||||
return {};
|
||||
# The ID of the LED on your board used for this component
|
||||
board_status_led_id: "esp_light"
|
||||
# ID for this component instance for fault registry
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# Updated : 2025.12.22
|
||||
# Version : 1.1.3
|
||||
# Updated : 2026.08.29
|
||||
# Version : 1.1.4
|
||||
# GitHub : https://github.com/Sleeper85/esphome-yambms
|
||||
|
||||
# YamBMS ( Yet another multi-BMS Merging Solution )
|
||||
@@ -46,14 +46,13 @@ sensor:
|
||||
state_class: total
|
||||
icon: mdi:counter
|
||||
accuracy_decimals: 0
|
||||
filters:
|
||||
- or:
|
||||
- throttle: 10s
|
||||
- delta: 1
|
||||
lambda: |-
|
||||
float cycles_raw = id(bms${bms_id}_charging_cycles_raw).state;
|
||||
if (isnan(cycles_raw)) cycles_raw = 0;
|
||||
return cycles_raw + id(bms${bms_id}_charging_cycles_offset).state;
|
||||
return id(bms${bms_id}_charging_cycles_raw).state +
|
||||
id(bms${bms_id}_charging_cycles_offset).state;
|
||||
filters:
|
||||
- lambda: |-
|
||||
const float delta = 1.0f;
|
||||
${rate_limit_filter}
|
||||
|
||||
# +--------------------------------------+
|
||||
# | Charging Cycle Capacity |
|
||||
@@ -67,13 +66,11 @@ sensor:
|
||||
state_class: total
|
||||
icon: mdi:car-battery
|
||||
accuracy_decimals: 0
|
||||
filters:
|
||||
- or:
|
||||
- throttle: 10s
|
||||
- delta: 1
|
||||
lambda: |-
|
||||
float capacity_raw = id(bms${bms_id}_cycle_capacity_raw).state;
|
||||
if (isnan(capacity_raw)) capacity_raw = 0;
|
||||
return capacity_raw +
|
||||
return id(bms${bms_id}_cycle_capacity_raw).state +
|
||||
id(bms${bms_id}_charging_cycles_offset).state *
|
||||
id(bms${bms_id}_battery_capacity).state;
|
||||
filters:
|
||||
- lambda: |-
|
||||
const float delta = 1.0f;
|
||||
${rate_limit_filter}
|
||||
@@ -1,4 +1,4 @@
|
||||
# Updated : 2026.08.21
|
||||
# Updated : 2026.08.29
|
||||
# Version : 1.8.0
|
||||
# GitHub : https://github.com/Sleeper85/esphome-yambms
|
||||
|
||||
@@ -27,34 +27,6 @@ substitutions:
|
||||
# Custom CCL/DCL Derating Reason
|
||||
yambms_custom_ccl_derating_reason: 'Custom CCL Derating'
|
||||
yambms_custom_dcl_derating_reason: 'Custom DCL Derating'
|
||||
# +----------------------------------------------------------------------+
|
||||
# | Rate-limit filter - NaN-safe replacement for `or: throttle + delta` |
|
||||
# +----------------------------------------------------------------------+
|
||||
# ESPHome's `delta` filter rejects a NaN without updating its internal
|
||||
# reference, so a sensor that publishes NaN stays frozen on its previous
|
||||
# value until `throttle` fires (up to 10s). YamBMS publishes NaN on purpose
|
||||
# to mean "no data", so the NaN <-> value transition must count as a change,
|
||||
# in both directions - including a return to the very same value.
|
||||
# Usage: declare `const float delta` (delta threshold) then expand it.
|
||||
# filters:
|
||||
# - lambda: |-
|
||||
# const float delta = 1.0f; # delta: 1
|
||||
# ${yambms_rate_limit_filter} # improved `throttle: 10s`
|
||||
# Must stay capture-free: a filter lambda is compiled to a plain function
|
||||
# pointer (StatelessLambdaFilter), so no id() reference is allowed here.
|
||||
yambms_rate_limit_filter_ms: '10000' # 10s
|
||||
yambms_rate_limit_filter: |-
|
||||
static float last = NAN;
|
||||
static uint32_t last_ms = 0;
|
||||
const uint32_t now = millis();
|
||||
if ((std::isnan(x) != std::isnan(last)) ||
|
||||
(!std::isnan(x) && fabsf(x - last) >= delta) ||
|
||||
((now - last_ms) >= ${yambms_rate_limit_filter_ms})) {
|
||||
last = x;
|
||||
last_ms = now;
|
||||
return x;
|
||||
}
|
||||
return {};
|
||||
|
||||
globals:
|
||||
# BMS
|
||||
@@ -1723,7 +1695,7 @@ sensor:
|
||||
filters:
|
||||
- lambda: |-
|
||||
const float delta = 1.0f;
|
||||
${yambms_rate_limit_filter}
|
||||
${rate_limit_filter}
|
||||
|
||||
# max_discharge_current SUM
|
||||
- platform: template
|
||||
@@ -1739,7 +1711,7 @@ sensor:
|
||||
filters:
|
||||
- lambda: |-
|
||||
const float delta = 1.0f;
|
||||
${yambms_rate_limit_filter}
|
||||
${rate_limit_filter}
|
||||
|
||||
# cell_count
|
||||
- platform: template
|
||||
@@ -1752,7 +1724,7 @@ sensor:
|
||||
filters:
|
||||
- lambda: |-
|
||||
const float delta = 1.0f;
|
||||
${yambms_rate_limit_filter}
|
||||
${rate_limit_filter}
|
||||
lambda: return ${yambms_cell_count};
|
||||
|
||||
# min_voltage_cell MIN
|
||||
@@ -1767,7 +1739,7 @@ sensor:
|
||||
filters:
|
||||
- lambda: |-
|
||||
const float delta = 1.0f;
|
||||
${yambms_rate_limit_filter}
|
||||
${rate_limit_filter}
|
||||
|
||||
# max_voltage_cell MAX
|
||||
- platform: template
|
||||
@@ -1781,7 +1753,7 @@ sensor:
|
||||
filters:
|
||||
- lambda: |-
|
||||
const float delta = 1.0f;
|
||||
${yambms_rate_limit_filter}
|
||||
${rate_limit_filter}
|
||||
|
||||
# min_cell_voltage MIN
|
||||
- platform: template
|
||||
@@ -1796,7 +1768,7 @@ sensor:
|
||||
filters:
|
||||
- lambda: |-
|
||||
const float delta = 0.001f;
|
||||
${yambms_rate_limit_filter}
|
||||
${rate_limit_filter}
|
||||
|
||||
# max_cell_voltage MAX
|
||||
- platform: template
|
||||
@@ -1811,7 +1783,7 @@ sensor:
|
||||
filters:
|
||||
- lambda: |-
|
||||
const float delta = 0.001f;
|
||||
${yambms_rate_limit_filter}
|
||||
${rate_limit_filter}
|
||||
|
||||
# delta_cell_voltage
|
||||
- platform: template
|
||||
@@ -1826,7 +1798,7 @@ sensor:
|
||||
filters:
|
||||
- lambda: |-
|
||||
const float delta = 0.001f;
|
||||
${yambms_rate_limit_filter}
|
||||
${rate_limit_filter}
|
||||
|
||||
# total_voltage MEAN
|
||||
- platform: template
|
||||
@@ -1841,7 +1813,7 @@ sensor:
|
||||
filters:
|
||||
- lambda: |-
|
||||
const float delta = 0.01f;
|
||||
${yambms_rate_limit_filter}
|
||||
${rate_limit_filter}
|
||||
|
||||
# current SUM
|
||||
- platform: template
|
||||
@@ -1856,7 +1828,7 @@ sensor:
|
||||
filters:
|
||||
- lambda: |-
|
||||
const float delta = 0.1f;
|
||||
${yambms_rate_limit_filter}
|
||||
${rate_limit_filter}
|
||||
|
||||
# power SUM
|
||||
- platform: template
|
||||
@@ -1871,7 +1843,7 @@ sensor:
|
||||
filters:
|
||||
- lambda: |-
|
||||
const float delta = 1.0f;
|
||||
${yambms_rate_limit_filter}
|
||||
${rate_limit_filter}
|
||||
|
||||
# battery_soc MEAN
|
||||
- platform: template
|
||||
@@ -1886,7 +1858,7 @@ sensor:
|
||||
filters:
|
||||
- lambda: |-
|
||||
const float delta = 1.0f;
|
||||
${yambms_rate_limit_filter}
|
||||
${rate_limit_filter}
|
||||
|
||||
# battery_soh MEAN
|
||||
- platform: template
|
||||
@@ -1901,7 +1873,7 @@ sensor:
|
||||
filters:
|
||||
- lambda: |-
|
||||
const float delta = 1.0f;
|
||||
${yambms_rate_limit_filter}
|
||||
${rate_limit_filter}
|
||||
|
||||
# installed_battery_capacity SUM
|
||||
- platform: template
|
||||
@@ -1916,7 +1888,7 @@ sensor:
|
||||
filters:
|
||||
- lambda: |-
|
||||
const float delta = 1.0f;
|
||||
${yambms_rate_limit_filter}
|
||||
${rate_limit_filter}
|
||||
lambda: return id(yambms${yambms_id}_var_total_installed_battery_capacity);
|
||||
|
||||
# battery_capacity SUM
|
||||
@@ -1932,7 +1904,7 @@ sensor:
|
||||
filters:
|
||||
- lambda: |-
|
||||
const float delta = 1.0f;
|
||||
${yambms_rate_limit_filter}
|
||||
${rate_limit_filter}
|
||||
|
||||
# battery_capacity_remaining SUM
|
||||
- platform: template
|
||||
@@ -1947,7 +1919,7 @@ sensor:
|
||||
filters:
|
||||
- lambda: |-
|
||||
const float delta = 1.0f;
|
||||
${yambms_rate_limit_filter}
|
||||
${rate_limit_filter}
|
||||
|
||||
# cell_ovp MIN (Auto CCL)
|
||||
- platform: template
|
||||
@@ -1962,7 +1934,7 @@ sensor:
|
||||
filters:
|
||||
- lambda: |-
|
||||
const float delta = 0.001f;
|
||||
${yambms_rate_limit_filter}
|
||||
${rate_limit_filter}
|
||||
|
||||
# cell_uvp MAX (Auto DCL and MAX Discharge Voltage)
|
||||
- platform: template
|
||||
@@ -1977,7 +1949,7 @@ sensor:
|
||||
filters:
|
||||
- lambda: |-
|
||||
const float delta = 0.001f;
|
||||
${yambms_rate_limit_filter}
|
||||
${rate_limit_filter}
|
||||
|
||||
# balance_trigger_voltage MAX (Auto CVL)
|
||||
- platform: template
|
||||
@@ -1992,7 +1964,7 @@ sensor:
|
||||
filters:
|
||||
- lambda: |-
|
||||
const float delta = 0.001f;
|
||||
${yambms_rate_limit_filter}
|
||||
${rate_limit_filter}
|
||||
|
||||
# MIN temperature
|
||||
- platform: template
|
||||
@@ -2034,7 +2006,7 @@ sensor:
|
||||
filters:
|
||||
- lambda: |-
|
||||
const float delta = 1.0f;
|
||||
${yambms_rate_limit_filter}
|
||||
${rate_limit_filter}
|
||||
|
||||
# MAX temperature
|
||||
- platform: template
|
||||
@@ -2076,7 +2048,7 @@ sensor:
|
||||
filters:
|
||||
- lambda: |-
|
||||
const float delta = 1.0f;
|
||||
${yambms_rate_limit_filter}
|
||||
${rate_limit_filter}
|
||||
|
||||
# charging_cycles MEAN
|
||||
- platform: template
|
||||
@@ -2090,7 +2062,7 @@ sensor:
|
||||
filters:
|
||||
- lambda: |-
|
||||
const float delta = 1.0f;
|
||||
${yambms_rate_limit_filter}
|
||||
${rate_limit_filter}
|
||||
|
||||
# Alarm - errors_bitmask bitwise AND (16bit)
|
||||
- platform: template
|
||||
@@ -2104,7 +2076,7 @@ sensor:
|
||||
filters:
|
||||
- lambda: |-
|
||||
const float delta = 1.0f;
|
||||
${yambms_rate_limit_filter}
|
||||
${rate_limit_filter}
|
||||
|
||||
# Warning - errors_bitmask bitwise OR (16bit)
|
||||
- platform: template
|
||||
@@ -2118,7 +2090,7 @@ sensor:
|
||||
filters:
|
||||
- lambda: |-
|
||||
const float delta = 1.0f;
|
||||
${yambms_rate_limit_filter}
|
||||
${rate_limit_filter}
|
||||
|
||||
# BMS in alarm (errors_bitmask_counter)
|
||||
- platform: template
|
||||
@@ -2132,7 +2104,7 @@ sensor:
|
||||
filters:
|
||||
- lambda: |-
|
||||
const float delta = 1.0f;
|
||||
${yambms_rate_limit_filter}
|
||||
${rate_limit_filter}
|
||||
|
||||
# BMS count
|
||||
- platform: template
|
||||
@@ -2146,7 +2118,7 @@ sensor:
|
||||
filters:
|
||||
- lambda: |-
|
||||
const float delta = 1.0f;
|
||||
${yambms_rate_limit_filter}
|
||||
${rate_limit_filter}
|
||||
|
||||
# BMS combined
|
||||
- platform: template
|
||||
@@ -2160,7 +2132,7 @@ sensor:
|
||||
filters:
|
||||
- lambda: |-
|
||||
const float delta = 1.0f;
|
||||
${yambms_rate_limit_filter}
|
||||
${rate_limit_filter}
|
||||
|
||||
# BMS blocking charge
|
||||
- platform: template
|
||||
@@ -2174,7 +2146,7 @@ sensor:
|
||||
filters:
|
||||
- lambda: |-
|
||||
const float delta = 1.0f;
|
||||
${yambms_rate_limit_filter}
|
||||
${rate_limit_filter}
|
||||
|
||||
# BMS blocking discharge
|
||||
- platform: template
|
||||
@@ -2188,7 +2160,7 @@ sensor:
|
||||
filters:
|
||||
- lambda: |-
|
||||
const float delta = 1.0f;
|
||||
${yambms_rate_limit_filter}
|
||||
${rate_limit_filter}
|
||||
|
||||
# Shunt count
|
||||
- platform: template
|
||||
@@ -2202,7 +2174,7 @@ sensor:
|
||||
filters:
|
||||
- lambda: |-
|
||||
const float delta = 1.0f;
|
||||
${yambms_rate_limit_filter}
|
||||
${rate_limit_filter}
|
||||
|
||||
# Shunt combined
|
||||
- platform: template
|
||||
@@ -2216,7 +2188,7 @@ sensor:
|
||||
filters:
|
||||
- lambda: |-
|
||||
const float delta = 1.0f;
|
||||
${yambms_rate_limit_filter}
|
||||
${rate_limit_filter}
|
||||
|
||||
# Battery Charging Power
|
||||
- platform: template
|
||||
@@ -2282,7 +2254,7 @@ sensor:
|
||||
filters:
|
||||
- lambda: |-
|
||||
const float delta = 0.1f;
|
||||
${yambms_rate_limit_filter}
|
||||
${rate_limit_filter}
|
||||
|
||||
# +--------------------------------------+
|
||||
# | Requested Discharge Voltage (DVL) |
|
||||
@@ -2300,7 +2272,7 @@ sensor:
|
||||
filters:
|
||||
- lambda: |-
|
||||
const float delta = 0.1f;
|
||||
${yambms_rate_limit_filter}
|
||||
${rate_limit_filter}
|
||||
|
||||
# +--------------------------------------+
|
||||
# | Requested Charge Current (CCL) |
|
||||
@@ -2318,7 +2290,7 @@ sensor:
|
||||
filters:
|
||||
- lambda: |-
|
||||
const float delta = 1.0f;
|
||||
${yambms_rate_limit_filter}
|
||||
${rate_limit_filter}
|
||||
# No on_value update of the derating reason here: this fires after STEP 3 has
|
||||
# reset the auto vars. The reason is updated from STEP 3, before that reset.
|
||||
|
||||
@@ -2338,7 +2310,7 @@ sensor:
|
||||
filters:
|
||||
- lambda: |-
|
||||
const float delta = 1.0f;
|
||||
${yambms_rate_limit_filter}
|
||||
${rate_limit_filter}
|
||||
# No on_value update of the derating reason here: this fires after STEP 3 has
|
||||
# reset the auto vars. The reason is updated from STEP 3, before that reset.
|
||||
|
||||
|
||||
Reference in new issue
Block a user