Files
esphome-yambms/packages/base/device_base_fault_registry.yaml
Sleeper85 281d39ac18 New inverter brand select drives the CAN and RS485 protocol
BREAKING CHANGE: both inverter link selects are renamed, so their stored value is
reset. The link stays inactive until an inverter brand is selected. See
documents/README/changelog/Changelog_Inverter_brand_and_protocol.md

New `Inverter brand` select (16 brands) and reworked `Protocol` select, now
defaulting to `Automatic`. Selecting the brand is enough, the protocol follows;
an explicit protocol still takes priority over the brand.

The protocol is resolved once, at boot and on every select change, into
`canbus${canbus_id}_active_protocol` / `rs485${rs485_id}_active_protocol`.
Everything else reads that integer instead of dispatching on `active_index()`,
where `== 5` meant LuxPower purely by convention of the option order.

New shared `yambms_inverter_registry.yaml`: protocol dictionary (`YB_PROTO_*`),
brand to protocol mapping, and the battery mode and note of each couple.

Removed the `YamBMS name` select: the manufacturer name sent on CAN frame 0x35E
now derives from the protocol in use, which is what `Automatic` already did.

Removed the `canbus_extended_ack` substitution: both the 11-bit and the 29-bit
ACK triggers are registered, so the Schneider XW Pro needs no configuration.

Renamed CAN `PYLON 1.2` to `PYLON V1` and RS485 `Pylontech` to `PYLON`.

New per-link diagnostics `Inverter link protocol`, `Inverter battery mode` and
`Note`, with a markdown card in the dashboards, alongside a system fault card.

Telemetry: `comm_bus` / `comm_protocol` replaced by `inverter_brand`,
`inverter_bus`, `inverter_protocol` and `inverter_protocol_source`, one slot per
declared link instead of a single value overwritten by the last one.

RS485 packages split: `yambms_rs485.yaml` is the entry point carrying the selects,
`yambms_rs485_pylon.yaml` the protocol implementation. The baud rate is applied
with `set_baud_rate()` + `load_settings()` instead of extending the uart
component, so boards using a UART expander no longer need their own include.

Fixes:
- the CAN bus kept re-emitting the last frame every 100 ms when the protocol was
  set to `Disabled` at runtime
- the RS485 link kept answering the inverter with stale data on `Disabled`, the
  proxy sensors it reads are now invalidated
- a `Disabled` link no longer lights the fault LED, it is unregistered from the
  fault registry instead of being reported as failing
- the reported bus and protocol were overwritten when a node declares several
  inverter links
- changing the protocol restarts the CAN frames immediately instead of waiting up
  to 30 s for the next retry tick
2026-11-08 23:08:33 +01:00

250 lines
8.6 KiB
YAML

# Updated : 2026.09.02
# Version : 1.1.4
# 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>.
substitutions:
# --- CATEGORY DICTIONARY ---
# Use these human-readable names in component yaml substitutions, up to 16 categories
CAT_SYSTEM: "0"
CAT_BMS: "1"
CAT_INV_CAN_BUS: "2"
CAT_INV_RS485: "3"
CAT_SHUNT: "4"
CAT_BALANCER: "5"
CAT_NETWORK: "6"
enable_health_logging: 'false' # Set to true to see if component health for all component instances, logged every 60 seconds
globals:
# Tracks True/False fault status for every component instance
# Structure: [Component Category (0-15)] -> [Specific Instance ID (0-N)]
# 0 = Healthy, 1 = Fault, 2 = Unregistered
- id: global_instance_faults
type: std::vector<std::vector<uint8_t>>
initial_value: std::vector<std::vector<uint8_t>>(16)
restore_value: false
# Component Fault Bitmask: A 16-bit summary of the component instance health.
# If Bit 4 is "1", it means "At least one instance in Category 4 is failing."
- id: global_system_fault_mask
type: uint16_t
initial_value: '0'
restore_value: false
# -------------------------------------------------------
# Global Function: Update Fault Sensor
# -------------------------------------------------------
- id: global_update_health_sensor
type: "std::function<void()>"
initial_value: |-
[]() {
std::string json = "[";
for (int cat = 0; cat < 16; cat++) {
auto &faults = id(global_instance_faults)[cat];
if (cat > 0) json += ",";
json += "[";
for (size_t i = 0; i < faults.size(); i++) {
if (i > 0) json += ",";
// 0 = Healthy, 1= Fault, 2 = Unregistered
json += to_string(faults[i]);
}
json += "]";
}
json += "]";
id(sys_fault_data).publish_state(json);
}
# ---------------------------------------------------------
# Global Function: Update Fault Status
# ---------------------------------------------------------
- id: global_update_fault
type: std::function<void(int, int, bool)>
initial_value: |-
[](int category, int instance, bool is_failing) {
int computer_instance = instance - 1;
if (category < 0 || category >= 16 || computer_instance < 0) return;
auto &faults = id(global_instance_faults)[category];
// Resize with default value '2' (Unregistered).
if (computer_instance >= faults.size()) {
faults.resize(computer_instance + 1, 2);
}
// Convert input boolean to integer
// Input false (Healthy) -> 0
// Input true (Fault) -> 1
uint8_t new_state = is_failing ? 1 : 0;
// Update only if state changed
if (faults[computer_instance] != new_state) {
faults[computer_instance] = new_state;
id(global_update_health_sensor)();
// Update Master Mask
// State 2 (unregistered) is ignored
bool cat_has_fault = false;
for(uint8_t f : faults) {
if(f == 1) {
cat_has_fault = true;
break;
}
}
if(cat_has_fault) {
id(global_system_fault_mask) |= (1 << category);
} else {
id(global_system_fault_mask) &= ~(1 << category);
}
}
}
# ---------------------------------------------------------
# Global Function: Unregister an instance
# ---------------------------------------------------------
# Sets the instance back to state '2' (Unregistered), which the master mask
# and the health report both ignore. Use it for a device the user has
# deliberately turned off, such as an inverter link whose protocol select is
# on `Disabled`: it is neither healthy nor faulty, it is simply not expected
# to communicate. Marking it healthy would report [ OK ] for a link that
# sends nothing.
- id: global_unregister_fault
type: std::function<void(int, int)>
initial_value: |-
[](int category, int instance) {
int computer_instance = instance - 1;
if (category < 0 || category >= 16 || computer_instance < 0) return;
auto &faults = id(global_instance_faults)[category];
// Resize with default value '2' (Unregistered).
if (computer_instance >= faults.size()) {
faults.resize(computer_instance + 1, 2);
}
// Update only if state changed
if (faults[computer_instance] != 2) {
faults[computer_instance] = 2;
id(global_update_health_sensor)();
// Update Master Mask
// State 2 (unregistered) is ignored
bool cat_has_fault = false;
for(uint8_t f : faults) {
if(f == 1) {
cat_has_fault = true;
break;
}
}
if(cat_has_fault) {
id(global_system_fault_mask) |= (1 << category);
} else {
id(global_system_fault_mask) &= ~(1 << category);
}
}
}
interval:
- interval: 60s
then:
- lambda: |-
// Check if logging is enabled
if (!${enable_health_logging}) return;
ESP_LOGI("health_rpt", "┌──────────────────────────────┐");
ESP_LOGI("health_rpt", "│ SYSTEM HEALTH REPORT │");
ESP_LOGI("health_rpt", "└──────────────────────────────┘");
bool system_clean = true;
// Iterate through all 16 Categories
for (int cat = 0; cat < 16; cat++) {
auto &faults = id(global_instance_faults)[cat];
if (faults.empty()) continue;
// Define Category Names
std::string cat_name;
switch(cat) {
case 0: cat_name = "API / MQTT "; break;
case 1: cat_name = "BMS "; break;
case 2: cat_name = "CAN->INV "; break;
case 3: cat_name = "RS485->INV "; break;
case 4: cat_name = "SHUNT "; break;
case 5: cat_name = "BALANCER "; break;
case 6: cat_name = "NETWORK "; break;
default: cat_name = "CAT_" + to_string(cat) + " "; break;
}
std::string status_line = "";
bool cat_has_fault = false;
bool cat_has_real_devices = false;
// Determine status
for (size_t i = 0; i < faults.size(); i++) {
uint8_t state = faults[i];
if (state == 0) {
// Healthy
status_line += "[ OK ] ";
cat_has_real_devices = true;
}
else if (state == 1) {
// Fault
status_line += "[FAIL] ";
cat_has_fault = true;
cat_has_real_devices = true;
system_clean = false;
}
else {
// Unregistered devices
status_line += "[ -- ] ";
}
}
// Log the component if instances exist
if (cat_has_real_devices) {
if (cat_has_fault) {
// Set to WARN if fault
ESP_LOGW("health_rpt", ">> %s: %s", cat_name.c_str(), status_line.c_str());
} else {
// Set to INFO if healthy
ESP_LOGI("health_rpt", " %s: %s", cat_name.c_str(), status_line.c_str());
}
}
}
// Footer
if (system_clean) {
ESP_LOGI("health_rpt", ">> ALL SYSTEMS NORMAL");
}
ESP_LOGI("health_rpt", "--------------------------------");
text_sensor:
# JSON sensor representing system fault data, use with markdown card in Home Assistant
- platform: template
name: "System Fault Data"
id: sys_fault_data
device_id: ${board_id}
entity_category: diagnostic