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.
160 lines
5.4 KiB
YAML
160 lines
5.4 KiB
YAML
# Updated : 2026.08.29
|
|
# Version : 1.2.8
|
|
# GitHub : https://github.com/Sleeper85/esphome-yambms
|
|
|
|
# YamBMS ( Yet another multi-BMS Merging Solution )
|
|
|
|
# This YAML is free software: you can redistribute it and/or
|
|
# modify it under the terms of the GNU General Public License
|
|
# as published by the Free Software Foundation, either version 3
|
|
# of the License, or (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
# See the GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/gpl.html>.
|
|
|
|
packages:
|
|
device_base_esphome: !include device_base_esphome.yaml
|
|
sub_device: !include device_base_sub_device.yaml
|
|
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
|
|
board_fault_device_id: "1"
|
|
|
|
esphome:
|
|
on_boot:
|
|
- priority: 600.0
|
|
then:
|
|
- lambda: |-
|
|
// Register System
|
|
id(global_register_led)(${CAT_SYSTEM}, ${board_fault_device_id}, id(${board_status_led_id}));
|
|
|
|
time:
|
|
# https://esphome.io/components/time/homeassistant
|
|
# https://esphome.io/components/time/sntp
|
|
- platform: sntp # homeassistant
|
|
id: my_time
|
|
|
|
button:
|
|
# https://esphome.io/components/button/restart
|
|
- platform: restart
|
|
name: Restart
|
|
id: esp32_restart_button
|
|
device_id: ${board_id}
|
|
entity_category: config
|
|
# https://esphome.io/components/button/factory_reset
|
|
- platform: factory_reset
|
|
name: Factory reset
|
|
id: esp32_factory_reset_button
|
|
device_id: ${board_id}
|
|
entity_category: config
|
|
|
|
binary_sensor:
|
|
# https://esphome.io/components/binary_sensor/status
|
|
- platform: status
|
|
name: Online status
|
|
id: esp32_online_status
|
|
device_id: ${board_id}
|
|
entity_category: diagnostic
|
|
trigger_on_initial_state: true
|
|
on_state:
|
|
then:
|
|
- lambda: |-
|
|
// Pass the current state to the update function
|
|
id(global_update_fault)(${CAT_SYSTEM}, ${board_fault_device_id}, !x);
|
|
|
|
sensor:
|
|
# https://esphome.io/components/sensor/uptime
|
|
- platform: uptime
|
|
id: esp32_uptime_sec
|
|
device_id: ${board_id}
|
|
update_interval: 10s
|
|
|
|
# https://esphome.io/components/sensor/internal_temperature
|
|
- platform: internal_temperature
|
|
name: Internal temperature
|
|
id: esp32_internal_temperature
|
|
device_id: ${board_id}
|
|
update_interval: 10s
|
|
entity_category: diagnostic
|
|
|
|
text_sensor:
|
|
# Uptime Human Readable
|
|
- platform: template
|
|
name: Uptime
|
|
id: esp32_uptime
|
|
device_id: ${board_id}
|
|
update_interval: 10s
|
|
icon: mdi:clock-start
|
|
entity_category: diagnostic
|
|
lambda: |-
|
|
int uptime_sec = id(esp32_uptime_sec).state;
|
|
int days = uptime_sec / 86400;
|
|
int hours = (uptime_sec % 86400) / 3600;
|
|
int minutes = (uptime_sec % 3600) / 60;
|
|
int seconds = uptime_sec % 60;
|
|
return {
|
|
(
|
|
(days ? std::to_string(days) +"d " : "") +
|
|
(hours ? std::to_string(hours) +"h " : "") +
|
|
(minutes ? std::to_string(minutes) +"m " : "") +
|
|
(std::to_string(seconds) +"s")
|
|
).c_str()
|
|
};
|
|
|
|
# Now date and time
|
|
- platform: template
|
|
id: esp32_date_time_now
|
|
device_id: ${board_id}
|
|
update_interval: 10s
|
|
icon: mdi:clock-start
|
|
entity_category: diagnostic
|
|
lambda: return id(my_time).now().strftime("%Y-%m-%d %H:%M:%S");
|
|
|
|
# https://esphome.io/components/text_sensor/version
|
|
- platform: version
|
|
name: ESPHome version
|
|
id: esp32_esphome_version
|
|
device_id: ${board_id}
|
|
hide_timestamp: false #true
|
|
entity_category: diagnostic |