From d01de31f7a23822839a64318bb4e6fac39669184 Mon Sep 17 00:00:00 2001 From: Andrew Rankin Date: Tue, 9 Sep 2025 10:08:32 -0400 Subject: [PATCH] Adding EG4 LLV2 BMS (#85) --- .../LP_BMS_example_EG4_LLV2_RS485_Modbus.yaml | 54 + .../RP_BMS_example_EG4_LLV2_RS485_Modbus.yaml | 56 ++ .../bms_combine_EG4_LLV2_RS485_bms_full.yaml | 26 + .../bms/bms_combine_EG4_RS485_modbus.yaml | 39 + ..._errors_bitmask_EG4_LLV2_RS485_Modbus.yaml | 105 ++ .../bms_modbus_EG4_LLV2_RS485_bms_full.yaml | 26 + .../bms_sensors_EG4_LLV2_RS485_bms_full.yaml | 950 ++++++++++++++++++ 7 files changed, 1256 insertions(+) create mode 100644 examples/single-node/LP_BMS_example_EG4_LLV2_RS485_Modbus.yaml create mode 100644 examples/single-node/RP_BMS_example_EG4_LLV2_RS485_Modbus.yaml create mode 100644 packages/bms/bms_combine_EG4_LLV2_RS485_bms_full.yaml create mode 100644 packages/bms/bms_combine_EG4_RS485_modbus.yaml create mode 100644 packages/bms/bms_errors_bitmask_EG4_LLV2_RS485_Modbus.yaml create mode 100644 packages/bms/bms_modbus_EG4_LLV2_RS485_bms_full.yaml create mode 100644 packages/bms/bms_sensors_EG4_LLV2_RS485_bms_full.yaml diff --git a/examples/single-node/LP_BMS_example_EG4_LLV2_RS485_Modbus.yaml b/examples/single-node/LP_BMS_example_EG4_LLV2_RS485_Modbus.yaml new file mode 100644 index 0000000..d1bc5c1 --- /dev/null +++ b/examples/single-node/LP_BMS_example_EG4_LLV2_RS485_Modbus.yaml @@ -0,0 +1,54 @@ +# Updated : 2025.07.27 +# Version : 1.1.1 +# 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 . + +############################ Local Packages Example ############################ + +# This is not a working YAML but just code ready to copy into your main YAML. + +################################################################################ + +packages: + + eg4_modbus: !include + file: packages/bms/bms_combine_EG4_RS485_modbus.yaml + vars: + eg4_modbus_uart_id: 'uart_esp_1' + eg4_modbus_baud_rate: '9600' + + bms1: !include + file: packages/bms/bms_combine_EG4_LLV2_RS485_bms_full.yaml + vars: + bms_id: '1' # must be a number + bms_name: 'BMS 1' + ## BMS address must start at 2 with EG4 LLV2, ID 1 is a special case and has different output. + bms_address: 2 # BMS 1 DIP switch + + bms2: !include + file: packages/bms/bms_combine_EG4_LLV2_RS485_bms_full.yaml + vars: + bms_id: '2' # must be a number + bms_name: 'BMS 2' + bms_address: 3 # BMS 2 DIP switch + + bms3: !include + file: packages/bms/bms_combine_EG4_LLV2_RS485_bms_full.yaml + vars: + bms_id: '3' # must be a number + bms_name: 'BMS 3' + bms_address: 4 # BMS 3 DIP switch diff --git a/examples/single-node/RP_BMS_example_EG4_LLV2_RS485_Modbus.yaml b/examples/single-node/RP_BMS_example_EG4_LLV2_RS485_Modbus.yaml new file mode 100644 index 0000000..07f3761 --- /dev/null +++ b/examples/single-node/RP_BMS_example_EG4_LLV2_RS485_Modbus.yaml @@ -0,0 +1,56 @@ +# Updated : 2025.07.27 +# Version : 1.1.1 +# 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 . + +############################ Remote Packages Example ########################### + +# This is not a working YAML but just code ready to copy into your main YAML. + +################################################################################ + +packages: + + bms: + url: https://github.com/Sleeper85/esphome-yambms + ref: main + refresh: 0s + files: + # EG4 Modbus + - path: 'packages/bms/bms_combine_EG4_RS485_modbus.yaml' + vars: + eg4_modbus_uart_id: 'uart_esp_1' + eg4_modbus_baud_rate: '9600' + # BMS 1 + - path: 'packages/bms/bms_combine_EG4_LLV2_RS485_bms_full.yaml' + vars: + bms_id: '1' # must be a number + bms_name: 'BMS 1' + ## BMS address must start at 2 with EG4 LLV2, ID 1 is a special case and has different output. + bms_address: 2 # BMS 1 DIP switch + # BMS 2 + - path: 'packages/bms/bms_combine_EG4_LLV2_RS485_bms_full.yaml' + vars: + bms_id: '2' # must be a number + bms_name: 'BMS 2' + bms_address: 3 # BMS 2 DIP switch + # BMS 3 + - path: 'packages/bms/bms_combine_EG4_LLV2_RS485_bms_full.yaml' + vars: + bms_id: '2' # must be a number + bms_name: 'BMS 3' + bms_address: 4 # BMS 3 DIP switch diff --git a/packages/bms/bms_combine_EG4_LLV2_RS485_bms_full.yaml b/packages/bms/bms_combine_EG4_LLV2_RS485_bms_full.yaml new file mode 100644 index 0000000..e1d3337 --- /dev/null +++ b/packages/bms/bms_combine_EG4_LLV2_RS485_bms_full.yaml @@ -0,0 +1,26 @@ +# Updated : 2025.07.24 +# Version : 1.1.1 +# GitHub : https://github.com/syssi/esphome-seplos-bms + +# 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 . + +substitutions: + bms_model: "EG4 LLV2" + bms_protocol: "RS485" + +packages: + bms_combine: !include bms_combine.yaml + bms_sensors: !include bms_sensors_EG4_LLV2_RS485_bms_full.yaml diff --git a/packages/bms/bms_combine_EG4_RS485_modbus.yaml b/packages/bms/bms_combine_EG4_RS485_modbus.yaml new file mode 100644 index 0000000..f15ac4d --- /dev/null +++ b/packages/bms/bms_combine_EG4_RS485_modbus.yaml @@ -0,0 +1,39 @@ +# Updated : 2025.07.24 +# Version : 1.1.1 +# 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 . + +substitutions: + # BMS + bms_model: "EG4 LLV2" + bms_protocol: "RS485" + # Modbus + eg4_modbus_id: modbus_eg4 + eg4_modbus_send_wait_time: 250ms # time in milliseconds before the next ModBUS command is sent if an answer from a previous command is pending + # Modbus Controller + eg4_modbus_update_interval: '5s' # frequency with which BMS modbus servers are queried + eg4_modbus_command_throttle: '0ms' # minimum time in between 2 requests to the device + +uart: + - id: !extend ${eg4_modbus_uart_id} + baud_rate: ${eg4_modbus_baud_rate} + +modbus: + - uart_id: ${eg4_modbus_uart_id} + id: ${eg4_modbus_id} + role: client + send_wait_time: ${eg4_modbus_send_wait_time} diff --git a/packages/bms/bms_errors_bitmask_EG4_LLV2_RS485_Modbus.yaml b/packages/bms/bms_errors_bitmask_EG4_LLV2_RS485_Modbus.yaml new file mode 100644 index 0000000..0254f7e --- /dev/null +++ b/packages/bms/bms_errors_bitmask_EG4_LLV2_RS485_Modbus.yaml @@ -0,0 +1,105 @@ +# 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 . + + # +----------------------------------------+ + # | EG4 LLV2 Modbus Errors Bitmask (16bit) | + # +----------------------------------------+ + + # Bit 0 Voltage Error 0000 0000 0000 0001 0x0001 + # Bit 1 Temperature Error 0000 0000 0000 0010 0x0002 + # Bit 2 Current Flow Error 0000 0000 0000 0100 0x0004 + # Bit 4 Cell Unbalance 0000 0000 0001 0000 0x0010 + + # +--------------------------------------------+ + # | EG4 LLV2 Modbus Protection Bitmask (16bit) | + # +--------------------------------------------+ + + # Bit 0 Pack Over Volt 0000 0000 0000 0001 0x0001 + # Bit 1 Cell Over Volt 0000 0000 0000 0010 0x0002 + # Bit 2 Pack Under Volt 0000 0000 0000 0100 0x0004 + # Bit 3 Cell Under Vold 0000 0000 0000 1000 0x0008 + # Bit 4 Charge Over Current 0000 0000 0001 0000 0x0010 + # Bit 5 Discharge Over Current 0000 0000 0010 0000 0x0020 + # Bit 6 Abnormal Ambient Temp 0000 0000 0100 0000 0x0040 + # Bit 7 MOS Overheating 0000 0000 1000 0000 0x0080 + # Bit 8 Charge Over Temp 0000 0001 0000 0000 0x0100 + # Bit 9 Discharge Over Temp 0000 0010 0000 0000 0x0200 + # Bit 10 Charge Under Temp 0000 0100 0000 0000 0x0400 + # Bit 11 Discharge Under Temp 0000 1000 0000 0000 0x0800 + # Bit 12 Low Capacity 0001 0000 0000 0000 0x1000 + # Bit 13 Discharge SC 0010 0000 0000 0000 0x2000 + + # +--------------------------------------+ + # | YamBMS Errors Bitmask (16bit) | + # +--------------------------------------+ + + # Bit 0 General alarm 0000 0000 0000 0001 0x0001 + # Bit 1 Battery high voltage alarm 0000 0000 0000 0010 0x0002 + # Bit 2 Battery low voltage alarm 0000 0000 0000 0100 0x0004 + # Bit 3 Battery high temperature alarm 0000 0000 0000 1000 0x0008 + # Bit 4 Battery low temperature alarm 0000 0000 0001 0000 0x0010 + # Bit 5 Battery high temperature charge alarm 0000 0000 0010 0000 0x0020 + # Bit 6 Battery low temperature charge alarm 0000 0000 0100 0000 0x0040 + # Bit 7 Battery high discharge current alarm 0000 0000 1000 0000 0x0080 + # Bit 8 Battery high charge current alarm 0000 0001 0000 0000 0x0100 + # Bit 9 Contactor alarm 0000 0010 0000 0000 0x0200 + # Bit 10 Short circuit alarm 0000 0100 0000 0000 0x0400 + # Bit 11 BMS internal alarm 0000 1000 0000 0000 0x0800 + # Bit 12 Cell imbalance alarm 0001 0000 0000 0000 0x1000 + # Bit 13 Reserved 0010 0000 0000 0000 0x2000 + # Bit 14 Reserved 0100 0000 0000 0000 0x4000 + # Bit 15 Reserved 1000 0000 0000 0000 0x8000 + +sensor: + - platform: template + id: bms${bms_id}_yambms_errors_bitmask + name: "${name} ${bms_name} YamBMS Errors Bitmask" + update_interval: ${bms_update_interval} + accuracy_decimals: 0 + icon: mdi:alert-circle-outline + filters: + - or: + - throttle: 10s + - delta: 1 + lambda: |- + uint32_t bms_errors_bitmask = id(bms${bms_id}_errors_bitmask).state; + uint32_t bms_protection_bitmask = id(bms${bms_id}_protection_bitmask).state; + uint16_t yambms_errors_bitmask = 0; + + if (bms_errors_bitmask > 0) + { + if (bms_errors_bitmask & 0x0001) yambms_errors_bitmask |= 0x0001; + if (bms_errors_bitmask & 0x0002) yambms_errors_bitmask |= 0x0001; + if (bms_errors_bitmask & 0x0004) yambms_errors_bitmask |= 0x0001; + if (bms_errors_bitmask & 0x0010) yambms_errors_bitmask |= 0x1000; + } + + if (bms_protection_bitmask > 0) + { + if (bms_protection_bitmask & 0x0001) yambms_errors_bitmask |= 0x0002; + if (bms_protection_bitmask & 0x0002) yambms_errors_bitmask |= 0x0002; + if (bms_protection_bitmask & 0x0004) yambms_errors_bitmask |= 0x0004; + if (bms_protection_bitmask & 0x0008) yambms_errors_bitmask |= 0x0004; + if (bms_protection_bitmask & 0x0010) yambms_errors_bitmask |= 0x0100; + if (bms_protection_bitmask & 0x0020) yambms_errors_bitmask |= 0x0080; + if (bms_protection_bitmask & 0x0100) yambms_errors_bitmask |= 0x0020; + if (bms_protection_bitmask & 0x0400) yambms_errors_bitmask |= 0x0040; + if (bms_protection_bitmask & 0x2000) yambms_errors_bitmask |= 0x0400; + if (bms_protection_bitmask & 0x0040) yambms_errors_bitmask |= 0x0001; + if (bms_protection_bitmask & 0x0080) yambms_errors_bitmask |= 0x0001; + if (bms_protection_bitmask & 0x1000) yambms_errors_bitmask |= 0x0001; + } + + return yambms_errors_bitmask; diff --git a/packages/bms/bms_modbus_EG4_LLV2_RS485_bms_full.yaml b/packages/bms/bms_modbus_EG4_LLV2_RS485_bms_full.yaml new file mode 100644 index 0000000..be8e18f --- /dev/null +++ b/packages/bms/bms_modbus_EG4_LLV2_RS485_bms_full.yaml @@ -0,0 +1,26 @@ +# Updated : 2025.06.11 +# Version : 1.1.2 +# GitHub : https://github.com/syssi/esphome-jk-bms + +# 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 . + +substitutions: + bms_model: "EG4 LLV2" + bms_protocol: "RS485" + +packages: + bms_sensors: !include bms_sensors_EG4_LLV2_RS485_bms_full.yaml + bms_combine: !include bms_modbus_server.yaml diff --git a/packages/bms/bms_sensors_EG4_LLV2_RS485_bms_full.yaml b/packages/bms/bms_sensors_EG4_LLV2_RS485_bms_full.yaml new file mode 100644 index 0000000..424c269 --- /dev/null +++ b/packages/bms/bms_sensors_EG4_LLV2_RS485_bms_full.yaml @@ -0,0 +1,950 @@ +# 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 . + +packages: + bms_base: !include bms_base.yaml + bms_temperature_sensor: !include bms_temperature_sensor_6.yaml + bms_errors_bitmask: !include bms_errors_bitmask_EG4_LLV2_RS485_Modbus.yaml + +# +--------------------------------------+ +# | Component settings | +# +--------------------------------------+ + +modbus_controller: + - id: modbus_controller_bms${bms_id} + address: ${bms_address} + modbus_id: ${eg4_modbus_id} + command_throttle: ${eg4_modbus_command_throttle} + update_interval: ${eg4_modbus_update_interval} + on_online: + then: + - logger.log: + format: "EG4 BMS ${bms_id} back online !" + level: INFO + on_offline: + then: + - logger.log: + format: "EG4 BMS ${bms_id} goes offline !" + level: INFO + - lambda: |- + id(bms${bms_id}_online_status).publish_state(false); + id(bms${bms_id}_charging_allowed).publish_state(false); + id(bms${bms_id}_discharging_allowed).publish_state(false); + id(bms${bms_id}_equalizing).publish_state(false); + id(bms${bms_id}_total_voltage).publish_state(0); + id(bms${bms_id}_current).publish_state(0); + id(bms${bms_id}_power).publish_state(0); + id(bms${bms_id}_battery_soc).publish_state(0); + id(bms${bms_id}_battery_capacity).publish_state(0); + id(bms${bms_id}_capacity_remaining_ah).publish_state(0); + id(bms${bms_id}_charging_cycles).publish_state(0); + id(bms${bms_id}_max_charge_current).publish_state(0); + id(bms${bms_id}_max_discharge_current).publish_state(0); + id(bms${bms_id}_max_cell_voltage).publish_state(0); + id(bms${bms_id}_max_voltage_cell).publish_state(0); + id(bms${bms_id}_min_cell_voltage).publish_state(0); + id(bms${bms_id}_min_voltage_cell).publish_state(0); + id(bms${bms_id}_min_temperature).publish_state(0); + id(bms${bms_id}_min_temperature_sensor).publish_state(0); + id(bms${bms_id}_max_temperature).publish_state(0); + id(bms${bms_id}_max_temperature_sensor).publish_state(0); + id(bms${bms_id}_cell_ovp).publish_state(0); + id(bms${bms_id}_cell_uvp).publish_state(0); + id(bms${bms_id}_balance_trigger_voltage).publish_state(0); + id(bms${bms_id}_charging_power).publish_state(0); + id(bms${bms_id}_discharging_power).publish_state(0); + id(bms${bms_id}_battery_soh).publish_state(0); + +# +--------------------------------------+ +# | Component entities | +# +--------------------------------------+ + +binary_sensor: + # online_status + - platform: template + id: bms${bms_id}_online_status + name: "${name} ${bms_name} online status" + lambda: |- + if (id(bms${bms_id}_total_voltage).state > 0) + return true; + else + return false; + + # bms_switch_charging + - platform: template + id: bms${bms_id}_charging_allowed + name: "${name} ${bms_name} charging" + lambda: + if (id(bms${bms_id}_errors_bitmask).state == 0) + return true; + else + return false; + + # bms_switch_discharging + - platform: template + id: bms${bms_id}_discharging_allowed + name: "${name} ${bms_name} discharging" + lambda: + if (id(bms${bms_id}_errors_bitmask).state == 0) + return true; + else + return false; + + # status heating + - platform: template + id: bms${bms_id}_status_heating + name: "${name} ${bms_name} status heating" + + - platform: modbus_controller + modbus_controller_id: modbus_controller_bms${bms_id} + name: "${name} ${bms_name} float stopped" + register_type: holding + bitmask: 0x2000 + address: 26 + +## Balancer Status + - platform: modbus_controller + modbus_controller_id: modbus_controller_bms${bms_id} + name: "${name} ${bms_name} balancing" + id: "bms${bms_id}_equalizing" + register_type: holding + address: 38 + + - platform: modbus_controller + modbus_controller_id: modbus_controller_bms${bms_id} + name: "${name} ${bms_name} cell 01 balancing" + id: "bms${bms_id}_cell_1_balancing" + register_type: holding + bitmask: 0x0001 + address: 38 + + - platform: modbus_controller + modbus_controller_id: modbus_controller_bms${bms_id} + name: "${name} ${bms_name} cell 02 balancing" + id: "bms${bms_id}_cell_2_balancing" + register_type: holding + bitmask: 0x0002 + address: 38 + + - platform: modbus_controller + modbus_controller_id: modbus_controller_bms${bms_id} + name: "${name} ${bms_name} cell 03 balancing" + id: "bms${bms_id}_cell_3_balancing" + register_type: holding + bitmask: 0x0004 + address: 38 + + - platform: modbus_controller + modbus_controller_id: modbus_controller_bms${bms_id} + name: "${name} ${bms_name} cell 04 balancing" + id: "bms${bms_id}_cell_4_balancing" + register_type: holding + bitmask: 0x0008 + address: 38 + + - platform: modbus_controller + modbus_controller_id: modbus_controller_bms${bms_id} + name: "${name} ${bms_name} cell 05 balancing" + id: "bms${bms_id}_cell_5_balancing" + register_type: holding + bitmask: 0x0010 + address: 38 + + - platform: modbus_controller + modbus_controller_id: modbus_controller_bms${bms_id} + name: "${name} ${bms_name} cell 06 balancing" + id: "bms${bms_id}_cell_6_balancing" + register_type: holding + bitmask: 0x0020 + address: 38 + + - platform: modbus_controller + modbus_controller_id: modbus_controller_bms${bms_id} + name: "${name} ${bms_name} cell 07 balancing" + id: "bms${bms_id}_cell_7_balancing" + register_type: holding + bitmask: 0x0040 + address: 38 + + - platform: modbus_controller + modbus_controller_id: modbus_controller_bms${bms_id} + name: "${name} ${bms_name} cell 08 balancing" + id: "bms${bms_id}_cell_8_balancing" + register_type: holding + bitmask: 0x0080 + address: 38 + + - platform: modbus_controller + modbus_controller_id: modbus_controller_bms${bms_id} + name: "${name} ${bms_name} cell 09 balancing" + id: "bms${bms_id}_cell_9_balancing" + register_type: holding + bitmask: 0x0100 + address: 38 + + - platform: modbus_controller + modbus_controller_id: modbus_controller_bms${bms_id} + name: "${name} ${bms_name} cell 10 balancing" + id: "bms${bms_id}_cell_10_balancing" + register_type: holding + bitmask: 0x0200 + address: 38 + + - platform: modbus_controller + modbus_controller_id: modbus_controller_bms${bms_id} + name: "${name} ${bms_name} cell 11 balancing" + id: "bms${bms_id}_cell_11_balancing" + register_type: holding + bitmask: 0x0400 + address: 38 + + - platform: modbus_controller + modbus_controller_id: modbus_controller_bms${bms_id} + name: "${name} ${bms_name} cell 12 balancing" + id: "bms${bms_id}_cell_12_balancing" + register_type: holding + bitmask: 0x0800 + address: 38 + + - platform: modbus_controller + modbus_controller_id: modbus_controller_bms${bms_id} + name: "${name} ${bms_name} cell 13 balancing" + id: "bms${bms_id}_cell_13_balancing" + register_type: holding + bitmask: 0x1000 + address: 38 + + - platform: modbus_controller + modbus_controller_id: modbus_controller_bms${bms_id} + name: "${name} ${bms_name} cell 14 balancing" + id: "bms${bms_id}_cell_14_balancing" + register_type: holding + bitmask: 0x2000 + address: 38 + + - platform: modbus_controller + modbus_controller_id: modbus_controller_bms${bms_id} + name: "${name} ${bms_name} cell 15 balancing" + id: "bms${bms_id}_cell_15_balancing" + register_type: holding + bitmask: 0x4000 + address: 38 + + - platform: modbus_controller + modbus_controller_id: modbus_controller_bms${bms_id} + name: "${name} ${bms_name} cell 16 balancing" + id: "bms${bms_id}_cell_16_balancing" + register_type: holding + bitmask: 0x8000 + address: 38 + + - platform: modbus_controller + modbus_controller_id: modbus_controller_bms${bms_id} + name: "${name} ${bms_name} voltage error" + register_type: holding + address: 28 + bitmask: 0x0001 + + - platform: modbus_controller + modbus_controller_id: modbus_controller_bms${bms_id} + name: "${name} ${bms_name} temperature error" + register_type: holding + address: 28 + bitmask: 0x0002 + + - platform: modbus_controller + modbus_controller_id: modbus_controller_bms${bms_id} + name: "${name} ${bms_name} current flow error" + register_type: holding + address: 28 + bitmask: 0x0004 + + - platform: modbus_controller + modbus_controller_id: modbus_controller_bms${bms_id} + name: "${name} ${bms_name} cell imbalance" + register_type: holding + address: 28 + bitmask: 0x0010 + +sensor: + - platform: modbus_controller + modbus_controller_id: modbus_controller_bms${bms_id} + id: bms${bms_id}_total_voltage + name: "${name} ${bms_name} total voltage" + register_type: holding + address: 0 + unit_of_measurement: "V" + device_class: voltage + state_class: measurement + accuracy_decimals: 2 + filters: + - multiply: 0.01 + + - platform: modbus_controller + modbus_controller_id: modbus_controller_bms${bms_id} + id: bms${bms_id}_current + name: "${name} ${bms_name} current" + register_type: holding + address: 1 + unit_of_measurement: "A" + state_class: measurement + device_class: 'current' + value_type: S_WORD + accuracy_decimals: 2 + filters: + - multiply: 0.01 + + - platform: modbus_controller + modbus_controller_id: modbus_controller_bms${bms_id} + id: bms${bms_id}_capacity_remaining_ah + name: "${name} ${bms_name} remaining capacity" + register_type: holding + address: 21 + unit_of_measurement: "Ah" + state_class: measurement + accuracy_decimals: 0 + + - platform: modbus_controller + modbus_controller_id: modbus_controller_bms${bms_id} + id: bms${bms_id}_max_charge_current + name: "${name} ${bms_name} max charging current" + register_type: holding + address: 22 + unit_of_measurement: "A" + state_class: measurement + device_class: 'current' + accuracy_decimals: 0 + + - platform: modbus_controller + modbus_controller_id: modbus_controller_bms${bms_id} + id: bms${bms_id}_battery_soh + name: "${name} ${bms_name} state of health" + register_type: holding + address: 23 + unit_of_measurement: "%" + state_class: measurement + accuracy_decimals: 0 + + - platform: modbus_controller + modbus_controller_id: modbus_controller_bms${bms_id} + id: bms${bms_id}_state_of_charge + name: "${name} ${bms_name} state of charge" + register_type: holding + address: 24 + unit_of_measurement: "%" + state_class: measurement + accuracy_decimals: 0 + + - platform: modbus_controller + modbus_controller_id: modbus_controller_bms${bms_id} + name: "${name} ${bms_name} warning internal" + internal: true + register_type: holding + address: 26 + + - platform: modbus_controller + modbus_controller_id: modbus_controller_bms${bms_id} + id: bms${bms_id}_protection_bitmask + name: "${name} ${bms_name} protection bitmask" + internal: true + register_type: holding + address: 27 + + - platform: modbus_controller + modbus_controller_id: modbus_controller_bms${bms_id} + id: bms${bms_id}_errors_bitmask + name: "${name} ${bms_name} errors bitmask" + register_type: holding + internal: true + address: 28 + + - platform: modbus_controller + modbus_controller_id: modbus_controller_bms${bms_id} + id: bms${bms_id}_charging_cycles_raw + name: "${name} ${bms_name} cycle" + register_type: holding + address: 29 + unit_of_measurement: "" + state_class: measurement + accuracy_decimals: 0 + value_type: U_DWORD + + - platform: modbus_controller + modbus_controller_id: modbus_controller_bms${bms_id} + id: bms${bms_id}_battery_capacity + name: "${name} ${bms_name} total capacity" + register_type: holding + address: 37 + unit_of_measurement: "Ah" + state_class: measurement + accuracy_decimals: 0 + filters: + - multiply: 0.1 + +## Temps + - platform: modbus_controller + modbus_controller_id: modbus_controller_bms${bms_id} + id: bms${bms_id}_temperature_sensor_1 + name: "${name} ${bms_name} cell temperature 1" + register_type: holding + address: 33 + unit_of_measurement: "°C" + device_class: temperature + state_class: measurement + lambda: |- + return "%d", data[0]; + - platform: modbus_controller + modbus_controller_id: modbus_controller_bms${bms_id} + id: bms${bms_id}_temperature_sensor_2 + name: "${name} ${bms_name} cell temperature 2" + register_type: holding + address: 33 + unit_of_measurement: "°C" + device_class: temperature + state_class: measurement + lambda: |- + return "%d", data[1]; + - platform: modbus_controller + modbus_controller_id: modbus_controller_bms${bms_id} + id: bms${bms_id}_temperature_sensor_3 + name: "${name} ${bms_name} cell temperature 3" + register_type: holding + address: 34 + unit_of_measurement: "°C" + device_class: temperature + state_class: measurement + lambda: |- + return "%d", data[0]; + - platform: modbus_controller + modbus_controller_id: modbus_controller_bms${bms_id} + id: bms${bms_id}_temperature_sensor_4 + name: "${name} ${bms_name} cell temperature 4" + register_type: holding + address: 34 + unit_of_measurement: "°C" + device_class: temperature + state_class: measurement + lambda: |- + return "%d", data[1]; + - platform: modbus_controller + modbus_controller_id: modbus_controller_bms${bms_id} + id: bms${bms_id}_temperature_sensor_5 + name: "${name} ${bms_name} cell temperature 5" + register_type: holding + address: 35 + unit_of_measurement: "°C" + device_class: temperature + state_class: measurement + lambda: |- + return "%d", data[0]; + - platform: modbus_controller + modbus_controller_id: modbus_controller_bms${bms_id} + id: bms${bms_id}_temperature_sensor_6 + name: "${name} ${bms_name} cell temperature 6" + register_type: holding + address: 35 + unit_of_measurement: "°C" + device_class: temperature + state_class: measurement + lambda: |- + return "%d", data[1]; + + - platform: modbus_controller + modbus_controller_id: modbus_controller_bms${bms_id} + name: "${name} ${bms_name} max cell temperature" + register_type: holding + address: 20 + unit_of_measurement: "°C" + device_class: temperature + state_class: measurement + value_type: S_WORD + accuracy_decimals: 0 + + - platform: modbus_controller + modbus_controller_id: modbus_controller_bms${bms_id} + name: "${name} ${bms_name} average cell temperature" + register_type: holding + address: 19 + unit_of_measurement: "°C" + device_class: temperature + state_class: measurement + value_type: S_WORD + accuracy_decimals: 0 + + - platform: modbus_controller + modbus_controller_id: modbus_controller_bms${bms_id} + name: "${name} ${bms_name} mosfet temperature" + register_type: holding + address: 18 + unit_of_measurement: "°C" + device_class: temperature + state_class: measurement + value_type: S_WORD + accuracy_decimals: 0 + +## Cell Voltages + - platform: modbus_controller + modbus_controller_id: modbus_controller_bms${bms_id} + name: "${name} ${bms_name} cell voltage 01" + id: "bms${bms_id}_cell_voltage_1" + register_type: holding + address: 2 + unit_of_measurement: "V" + state_class: measurement + device_class: 'voltage' + accuracy_decimals: 3 + filters: + - multiply: 0.001 + + - platform: modbus_controller + modbus_controller_id: modbus_controller_bms${bms_id} + name: "${name} ${bms_name} cell voltage 02" + id: "bms${bms_id}_cell_voltage_2" + register_type: holding + address: 3 + unit_of_measurement: "V" + state_class: measurement + device_class: 'voltage' + accuracy_decimals: 3 + filters: + - multiply: 0.001 + + - platform: modbus_controller + modbus_controller_id: modbus_controller_bms${bms_id} + name: "${name} ${bms_name} cell voltage 03" + id: "bms${bms_id}_cell_voltage_3" + register_type: holding + address: 4 + unit_of_measurement: "V" + state_class: measurement + device_class: 'voltage' + accuracy_decimals: 3 + filters: + - multiply: 0.001 + + - platform: modbus_controller + modbus_controller_id: modbus_controller_bms${bms_id} + name: "${name} ${bms_name} cell voltage 04" + id: "bms${bms_id}_cell_voltage_4" + register_type: holding + address: 5 + unit_of_measurement: "V" + state_class: measurement + device_class: 'voltage' + accuracy_decimals: 3 + filters: + - multiply: 0.001 + + - platform: modbus_controller + modbus_controller_id: modbus_controller_bms${bms_id} + name: "${name} ${bms_name} cell voltage 05" + id: "bms${bms_id}_cell_voltage_5" + register_type: holding + address: 6 + unit_of_measurement: "V" + state_class: measurement + device_class: 'voltage' + accuracy_decimals: 3 + filters: + - multiply: 0.001 + + - platform: modbus_controller + modbus_controller_id: modbus_controller_bms${bms_id} + name: "${name} ${bms_name} cell voltage 06" + id: "bms${bms_id}_cell_voltage_6" + register_type: holding + address: 7 + unit_of_measurement: "V" + state_class: measurement + device_class: 'voltage' + accuracy_decimals: 3 + filters: + - multiply: 0.001 + + - platform: modbus_controller + modbus_controller_id: modbus_controller_bms${bms_id} + name: "${name} ${bms_name} cell voltage 07" + id: "bms${bms_id}_cell_voltage_7" + register_type: holding + address: 8 + unit_of_measurement: "V" + state_class: measurement + device_class: 'voltage' + accuracy_decimals: 3 + filters: + - multiply: 0.001 + + - platform: modbus_controller + modbus_controller_id: modbus_controller_bms${bms_id} + name: "${name} ${bms_name} cell voltage 08" + id: "bms${bms_id}_cell_voltage_8" + register_type: holding + address: 9 + unit_of_measurement: "V" + state_class: measurement + device_class: 'voltage' + accuracy_decimals: 3 + filters: + - multiply: 0.001 + + - platform: modbus_controller + modbus_controller_id: modbus_controller_bms${bms_id} + name: "${name} ${bms_name} cell voltage 09" + id: "bms${bms_id}_cell_voltage_9" + register_type: holding + address: 10 + unit_of_measurement: "V" + state_class: measurement + device_class: 'voltage' + accuracy_decimals: 3 + filters: + - multiply: 0.001 + + - platform: modbus_controller + modbus_controller_id: modbus_controller_bms${bms_id} + name: "${name} ${bms_name} cell voltage 10" + id: "bms${bms_id}_cell_voltage_10" + register_type: holding + address: 11 + unit_of_measurement: "V" + state_class: measurement + device_class: 'voltage' + accuracy_decimals: 3 + filters: + - multiply: 0.001 + + - platform: modbus_controller + modbus_controller_id: modbus_controller_bms${bms_id} + name: "${name} ${bms_name} cell voltage 11" + id: "bms${bms_id}_cell_voltage_11" + register_type: holding + address: 12 + unit_of_measurement: "V" + state_class: measurement + device_class: 'voltage' + accuracy_decimals: 3 + filters: + - multiply: 0.001 + + - platform: modbus_controller + modbus_controller_id: modbus_controller_bms${bms_id} + name: "${name} ${bms_name} cell voltage 12" + id: "bms${bms_id}_cell_voltage_12" + register_type: holding + address: 13 + unit_of_measurement: "V" + state_class: measurement + device_class: 'voltage' + accuracy_decimals: 3 + filters: + - multiply: 0.001 + + - platform: modbus_controller + modbus_controller_id: modbus_controller_bms${bms_id} + name: "${name} ${bms_name} cell voltage 13" + id: "bms${bms_id}_cell_voltage_13" + register_type: holding + address: 14 + unit_of_measurement: "V" + state_class: measurement + device_class: 'voltage' + accuracy_decimals: 3 + filters: + - multiply: 0.001 + + - platform: modbus_controller + modbus_controller_id: modbus_controller_bms${bms_id} + name: "${name} ${bms_name} cell voltage 14" + id: "bms${bms_id}_cell_voltage_14" + register_type: holding + address: 15 + unit_of_measurement: "V" + state_class: measurement + device_class: 'voltage' + accuracy_decimals: 3 + filters: + - multiply: 0.001 + + - platform: modbus_controller + modbus_controller_id: modbus_controller_bms${bms_id} + name: "${name} ${bms_name} cell voltage 15" + id: "bms${bms_id}_cell_voltage_15" + register_type: holding + address: 16 + unit_of_measurement: "V" + state_class: measurement + device_class: 'voltage' + accuracy_decimals: 3 + filters: + - multiply: 0.001 + + - platform: modbus_controller + modbus_controller_id: modbus_controller_bms${bms_id} + name: "${name} ${bms_name} cell voltage 16" + id: "bms${bms_id}_cell_voltage_16" + register_type: holding + address: 17 + unit_of_measurement: "V" + state_class: measurement + device_class: 'voltage' + accuracy_decimals: 3 + filters: + - multiply: 0.001 + + # Min. cell voltage + - platform: template + name: "${name} ${bms_name} min cell voltage" + id: "bms${bms_id}_min_cell_voltage" + unit_of_measurement: 'V' + device_class: 'voltage' + state_class: 'measurement' + accuracy_decimals: 3 + lambda: |- + float v_min = NAN; + float v_max = NAN; + float c_min = NAN; + float c_max = NAN; + + float cells[16] = { + id(bms${bms_id}_cell_voltage_1).state, + id(bms${bms_id}_cell_voltage_2).state, + id(bms${bms_id}_cell_voltage_3).state, + id(bms${bms_id}_cell_voltage_4).state, + id(bms${bms_id}_cell_voltage_5).state, + id(bms${bms_id}_cell_voltage_6).state, + id(bms${bms_id}_cell_voltage_7).state, + id(bms${bms_id}_cell_voltage_8).state, + id(bms${bms_id}_cell_voltage_9).state, + id(bms${bms_id}_cell_voltage_10).state, + id(bms${bms_id}_cell_voltage_11).state, + id(bms${bms_id}_cell_voltage_12).state, + id(bms${bms_id}_cell_voltage_13).state, + id(bms${bms_id}_cell_voltage_14).state, + id(bms${bms_id}_cell_voltage_15).state, + id(bms${bms_id}_cell_voltage_16).state + }; + + for (int i = 0; i <= 15; i++) { + float t_cell = cells[i]; + if (t_cell < v_min || isnan(v_min)) { + v_min = t_cell; + c_min = i+1; + } + if (t_cell > v_max || isnan(v_max)) { + v_max = t_cell; + c_max = i+1; + } + } + + id(bms${bms_id}_min_voltage_cell).publish_state(c_min); + id(bms${bms_id}_max_voltage_cell).publish_state(c_max); + id(bms${bms_id}_max_cell_voltage).publish_state(v_max); + id(bms${bms_id}_delta_cell_voltage).publish_state(v_max - v_min); + + return v_min; + + # Max. cell voltage + - platform: template + name: "${name} ${bms_name} max cell voltage" + id: "bms${bms_id}_max_cell_voltage" + unit_of_measurement: 'V' + device_class: 'voltage' + state_class: 'measurement' + accuracy_decimals: 3 + + # Delta cell voltage + - platform: template + name: "${name} ${bms_name} delta cell voltage" + id: "bms${bms_id}_delta_cell_voltage" + unit_of_measurement: 'V' + device_class: 'voltage' + state_class: 'measurement' + accuracy_decimals: 3 + + # Min. voltage cell + - platform: template + name: "${name} ${bms_name} min voltage cell" + id: "bms${bms_id}_min_voltage_cell" + accuracy_decimals: 0 + + # Max. voltage cell + - platform: template + name: "${name} ${bms_name} max voltage cell" + id: "bms${bms_id}_max_voltage_cell" + accuracy_decimals: 0 + +## Either Temp till I figure out bitmasks or unavailable from the BMS +# + - platform: template + id: bms${bms_id}_balance_trigger_voltage + name: "${name} ${bms_name} balance trigger voltage" + accuracy_decimals: 3 + unit_of_measurement: "V" + state_class: measurement + device_class: 'voltage' + lambda: return 0.030; + + - platform: template + id: bms${bms_id}_cell_ovp + name: "${name} ${bms_name} cell ovp" + accuracy_decimals: 3 + unit_of_measurement: "V" + state_class: measurement + device_class: 'voltage' + lambda: return 3.650; + + - platform: template + id: bms${bms_id}_cell_uvp + name: "${name} ${bms_name} cell uvp" + accuracy_decimals: 3 + unit_of_measurement: "V" + state_class: measurement + device_class: 'voltage' + lambda: return 2.500; + + - platform: template + id: bms${bms_id}_max_discharge_current + name: "${name} ${bms_name} max discharge current" + accuracy_decimals: 0 + unit_of_measurement: "A" + state_class: measurement + device_class: 'current' + lambda: return 200; + + # Power + - platform: template + id: bms${bms_id}_power + name: "${name} ${bms_name} Power" + update_interval: ${bms_update_interval} + unit_of_measurement: W + device_class: power + state_class: measurement + accuracy_decimals: 0 + filters: + - or: + - throttle: 10s + - delta: 1 + lambda: return id(bms${bms_id}_total_voltage).state * id(bms${bms_id}_current).state; + + # Charging Power + - platform: template + name: ${name} ${bms_name} Charging Power + id: bms${bms_id}_charging_power + update_interval: ${bms_update_interval} + unit_of_measurement: 'W' + device_class: power + state_class: measurement + accuracy_decimals: 0 + lambda: |- + if (id(bms${bms_id}_power).state > 0) + return id(bms${bms_id}_power).state; + else return 0; + + # Discharging Power + - platform: template + name: ${name} ${bms_name} Discharging Power + id: bms${bms_id}_discharging_power + update_interval: ${bms_update_interval} + unit_of_measurement: 'W' + device_class: power + state_class: measurement + accuracy_decimals: 0 + lambda: |- + if (id(bms${bms_id}_power).state <= 0) + return (id(bms${bms_id}_power).state * -1); // Must be positive energy + else return 0; + + # Charging cycle capacity + - platform: template + id: bms${bms_id}_cycle_capacity_raw + name: "${name} ${bms_name} charging cycle capacity" + update_interval: ${bms_update_interval} + unit_of_measurement: Ah + state_class: total + icon: mdi:car-battery + accuracy_decimals: 0 + internal: true + filters: + - or: + - throttle: 10s + - delta: 1 + lambda: return id(bms${bms_id}_charging_cycles_raw).state * id(bms${bms_id}_battery_capacity).state; + +## Status +#0x0000:Stand by +#0x0001:Charging +#0x0002:Discharging +#0x0004:Protect +#0x0008:Charging Lmt + +#Front Byte 0x00: Heat State-Off +#Front Byte 0x80:Heat State-On + + - platform: modbus_controller + modbus_controller_id: modbus_controller_bms${bms_id} + id: bms${bms_id}_status_internal + internal: true + name: "${name} ${bms_name} status internal" + register_type: holding + address: 25 + lambda: |- + id(bms${bms_id}_status_heating).publish_state((bool)data[item->offset]); + return data[item->offset+1]; + +## Product +text_sensor: + - platform: modbus_controller + modbus_controller_id: modbus_controller_bms${bms_id} + name: "${name} ${bms_name} model" + register_type: holding + register_count: 11 + address: 105 + response_size: 24 + raw_encode: ANSI + skip_updates: 60 + + - platform: modbus_controller + modbus_controller_id: modbus_controller_bms${bms_id} + name: "${name} ${bms_name} version" + register_type: holding + register_count: 3 + address: 117 + response_size: 6 + raw_encode: ANSI + skip_updates: 60 + + - platform: modbus_controller + modbus_controller_id: modbus_controller_bms${bms_id} + name: "${name} ${bms_name} firmware date" + register_type: holding + register_count: 8 + address: 120 + response_size: 16 + raw_encode: ANSI + skip_updates: 60 + +## Text Status + - platform: template + name: "${name} ${bms_name} status" + id: bms${bms_id}_status + lambda: |- + switch ((int)id(bms${bms_id}_status_internal).state) { + default: return std::string("Unknown"); + case 0: return std::string("Standby"); + case 1: return std::string("Charging"); + case 2: return std::string("Discharging"); + case 3: return std::string("Protect"); + case 4: return std::string("Charging Limit"); + }