From c55ff7d9aea581e45c754ae06dbdad5f281418a4 Mon Sep 17 00:00:00 2001 From: Bernhard Kirchen Date: Wed, 30 Oct 2024 21:44:07 +0100 Subject: [PATCH] Feature: add HASS autodiscovery for JBD BMS --- src/MqttHandleBatteryHass.cpp | 37 +++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/MqttHandleBatteryHass.cpp b/src/MqttHandleBatteryHass.cpp index b2af9e66b..6adfd0a66 100644 --- a/src/MqttHandleBatteryHass.cpp +++ b/src/MqttHandleBatteryHass.cpp @@ -214,6 +214,43 @@ void MqttHandleBatteryHassClass::loop() publishBinarySensor("Charge enabled", "mdi:battery-arrow-up", "charging/chargeEnabled", "1", "0"); publishBinarySensor("Discharge enabled", "mdi:battery-arrow-down", "charging/dischargeEnabled", "1", "0"); + break; + case 6: // JBD BMS + // caption icon topic dev. class state class unit + publishSensor("Voltage", "mdi:battery-charging", "voltage", "voltage", "measurement", "V"); + publishSensor("Current", "mdi:current-dc", "current", "current", "measurement", "A"); + publishSensor("Cell Min Voltage", NULL, "CellMinMilliVolt", "voltage", "measurement", "mV"); + publishSensor("Cell Average Voltage", NULL, "CellAvgMilliVolt", "voltage", "measurement", "mV"); + publishSensor("Cell Max Voltage", NULL, "CellMaxMilliVolt", "voltage", "measurement", "mV"); + publishSensor("Cell Voltage Diff", "mdi:battery-alert", "CellDiffMilliVolt", "voltage", "measurement", "mV"); + publishSensor("Battery Temperature 1", "mdi:thermometer", "BatteryTempOneCelsius", "temperature", "measurement", "°C"); + publishSensor("Battery Temperature 2", "mdi:thermometer", "BatteryTempTwoCelsius", "temperature", "measurement", "°C"); + publishSensor("Alarms Bitmask", NULL, "AlarmsBitmask"); + publishSensor("Charge Cycles", "mdi:counter", "BatteryCycles"); + publishSensor("Available Capacity", NULL, "ActualBatteryCapacityAmpHours"); + + publishBinarySensor("Charging enabled", "mdi:battery-arrow-up", "BatteryChargeEnabled", "yes", "no"); + publishBinarySensor("Discharging enabled", "mdi:battery-arrow-down", "BatteryDischargeEnabled", "yes", "no"); + publishBinarySensor("Balancing enabled", "mdi:scale-balance", "BatteryBalancingEnabled", "yes", "no"); + +#define PBS(a, b, c) publishBinarySensor("Alarm: " a, "mdi:" b, "alarms/" c, "1", "0") + PBS("Cell Overvoltage", "battery-alert", "CellOverVoltage"); + PBS("Cell Undervoltage", "battery-alert", "CellUnderVoltage"); + PBS("Pack Overvoltage", "fuse-alert", "PackOverVoltage"); + PBS("Pack Undervoltage", "fuse-alert", "PackUnderVoltage"); + PBS("Charging Overtemperature", "thermometer-alert", "ChargingOverTemperature"); + PBS("Charging Undertemperature", "thermometer-alert", "ChargingLowTemperature"); + PBS("Discharging Overtemperature", "thermometer-alert", "DischargingOverTemperature"); + PBS("Discharging Undertemperature", "thermometer-alert", "DischargingLowTemperature"); + PBS("Charging Overcurrent", "fuse-alert", "ChargingOverCurrent"); + PBS("Discharging Overcurrent", "fuse-alert", "DischargeOverCurrent"); + PBS("Short Circuit", "fuse-alert", "ShortCircuit"); + PBS("IC Frontend Error", "battery-alert-variant-outline", "IcFrontEndError"); + PBS("MOS Software Lock", "battery-alert-variant-outline", "MosSoftwareLock"); + PBS("Reserved 1", "battery-alert-variant-outline", "Reserved1"); + PBS("Reserved 2", "battery-alert-variant-outline", "Reserved2"); + PBS("Reserved 3", "battery-alert-variant-outline", "Reserved3"); +#undef PBS break; }