From 6973cee1711691b58297bc17569229ebe68f2192 Mon Sep 17 00:00:00 2001 From: Sleeper85 Date: Thu, 27 Aug 2026 18:50:22 +0200 Subject: [PATCH] PVbrain2 board split into two DevKitC-1 pin variants MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The DevKitC-1 swapped the RGB LED between V1.0 (GPIO 48) and V1.1 (GPIO 38), and the freed pin is the one PVbrain2 uses for CAN TX. Both pins are therefore board-revision dependent and cannot stay hardcoded in a single board file. board_ESP32-S3_DevKitC-1_PVbrain2.yaml becomes the common base : - tx_pin_4 / rx_pin_4 and the LED strip pin are removed from it - esp_light now reads ${rgb_led_pin} - GPLv3 header added, which was missing Two thin wrappers provide the revision-specific pins and include the base : - board_ESP32-S3_DevKitC-1_PVbrain2_LED-48.yaml : V1.0, LED 48 / CAN TX 38 - board_ESP32-S3_DevKitC-1_PVbrain2_LED-38.yaml : V1.1, LED 38 / CAN TX 48 YamBMS_LP_PVbrain2.yaml and YamBMS_RP_PVbrain2.yaml include the LED-48 variant, the LED-38 line being commented right next to it. Same split applied to the RS485 Pylontech package : the content moves to yambms_rs485_pylon_core.yaml and yambms_rs485_pylon.yaml keeps only the uart baud_rate extend, so PVbrain2 — whose board already declares the UART — can include the core directly. PCB LED 1 / PCB LED 2 / ESP32 LED are no longer prefixed by ${name}, and the `name` substitution is added to the PVbrain2 root YAMLs. --- YamBMS_LP_PVbrain2.yaml | 8 +- YamBMS_RP_PVbrain2.yaml | 8 +- .../board_ESP32-S3_DevKitC-1_PVbrain2.yaml | 32 +- ...rd_ESP32-S3_DevKitC-1_PVbrain2_LED-38.yaml | 30 ++ ...rd_ESP32-S3_DevKitC-1_PVbrain2_LED-48.yaml | 30 ++ packages/yambms/yambms_rs485_pylon.yaml | 320 +---------------- packages/yambms/yambms_rs485_pylon_core.yaml | 331 ++++++++++++++++++ 7 files changed, 429 insertions(+), 330 deletions(-) create mode 100644 packages/board/board_ESP32-S3_DevKitC-1_PVbrain2_LED-38.yaml create mode 100644 packages/board/board_ESP32-S3_DevKitC-1_PVbrain2_LED-48.yaml create mode 100644 packages/yambms/yambms_rs485_pylon_core.yaml diff --git a/YamBMS_LP_PVbrain2.yaml b/YamBMS_LP_PVbrain2.yaml index deb9d6e..cf196f3 100644 --- a/YamBMS_LP_PVbrain2.yaml +++ b/YamBMS_LP_PVbrain2.yaml @@ -1,4 +1,4 @@ -# Updated : 2026.08.11 +# Updated : 2026.08.27 # Version : 1.8.0 # GitHub : https://github.com/Sleeper85/esphome-yambms @@ -64,6 +64,7 @@ substitutions: # This allows to group entities into logical devices that appear separately in Home Assistant. hostname: 'pvbrain2' # Name of your ESPHome node registered on the IP network (DNS name must be unique) friendly_name : 'PVbrain2' # Name of your board (prefix for board entities) + name: '' # This name can be added as a second prefix, both for the `entity display name` and the `entity id`, you can leave it blank. # +--------------------------------------+ # | YamBMS Settings | # +--------------------------------------+ @@ -173,7 +174,8 @@ substitutions: packages: board: !include - file: packages/board/board_ESP32-S3_DevKitC-1_PVbrain2.yaml + file: packages/board/board_ESP32-S3_DevKitC-1_PVbrain2_LED-48.yaml # DevKitC-1 V1.0 + # file: packages/board/board_ESP32-S3_DevKitC-1_PVbrain2_LED-38.yaml # DevKitC-1 V1.1 # vars: # server_status_led_id: 'virtual_status_light' # led used to show status. Default = esp_light, set specific led or set to 'virtual_status_light' to disable # network_status_led_id: 'virtual_status_light' # led used to show status. Default = esp_light, set specific led or set to 'virtual_status_light' to disable @@ -294,7 +296,7 @@ packages: # +------------------------------------------------------------------------------+ # rs485_pylon: !include - # file: packages/yambms/yambms_rs485_pylon.yaml # yambms_rs485_pylon_web_server.yaml + # file: packages/yambms/yambms_rs485_pylon_core.yaml # vars: # rs485_id: '1' # Must be a number # rs485_name: 'RS485 1' diff --git a/YamBMS_RP_PVbrain2.yaml b/YamBMS_RP_PVbrain2.yaml index cd97269..1eec8c0 100644 --- a/YamBMS_RP_PVbrain2.yaml +++ b/YamBMS_RP_PVbrain2.yaml @@ -1,4 +1,4 @@ -# Updated : 2026.08.11 +# Updated : 2026.08.27 # Version : 1.8.0 # GitHub : https://github.com/Sleeper85/esphome-yambms @@ -64,6 +64,7 @@ substitutions: # This allows to group entities into logical devices that appear separately in Home Assistant. hostname: 'pvbrain2' # Name of your ESPHome node registered on the IP network (DNS name must be unique) friendly_name : 'PVbrain2' # Name of your board (prefix for board entities) + name: '' # This name can be added as a second prefix, both for the `entity display name` and the `entity id`, you can leave it blank. # +--------------------------------------+ # | YamBMS Settings | # +--------------------------------------+ @@ -185,7 +186,8 @@ packages: files: # Board - - path: 'packages/board/board_ESP32-S3_DevKitC-1_PVbrain2.yaml' + - path: 'packages/board/board_ESP32-S3_DevKitC-1_PVbrain2_LED-48.yaml' # DevKitC-1 V1.0 + # - path: 'packages/board/board_ESP32-S3_DevKitC-1_PVbrain2_LED-38.yaml' # DevKitC-1 V1.1 # vars: # server_status_led_id: 'virtual_status_light' # led used to show status. Default = esp_light, set specific led or set to 'virtual_status_light' to disable # network_status_led_id: 'virtual_status_light' # led used to show status. Default = esp_light, set specific led or set to 'virtual_status_light' to disable @@ -302,7 +304,7 @@ packages: # | >>> RS485 bus to Inverter # +------------------------------------------------------------------------------+ - # - path: 'packages/yambms/yambms_rs485_pylon.yaml' # yambms_rs485_pylon_web_server.yaml + # - path: 'packages/yambms/yambms_rs485_pylon_core.yaml' # vars: # rs485_id: '1' # Must be a number # rs485_name: 'RS485 1' diff --git a/packages/board/board_ESP32-S3_DevKitC-1_PVbrain2.yaml b/packages/board/board_ESP32-S3_DevKitC-1_PVbrain2.yaml index d97b218..fb9baff 100644 --- a/packages/board/board_ESP32-S3_DevKitC-1_PVbrain2.yaml +++ b/packages/board/board_ESP32-S3_DevKitC-1_PVbrain2.yaml @@ -1,7 +1,24 @@ -# Updated : 2026.08.26 -# Version : 1.3.8 +# Updated : 2026.08.27 +# Version : 1.3.9 # GitHub : https://github.com/SeByDocKy/pvbrain2 +# 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 . + +# LED DevKitC-1 V1.0 = 48 / V1.1 = 38 + substitutions: board_chip: "ESP32-S3" board_name: "PVbrain2" @@ -15,9 +32,6 @@ substitutions: # uart_esp_3 tx_pin_3: '43' rx_pin_3: '44' - # canbus_esp32_can - tx_pin_4: '38' - rx_pin_4: '39' # SPI bus for canbus_mcp2515 spi_mosi_pin: '11' spi_miso_pin: '12' @@ -72,23 +86,23 @@ logger: light: # https://esphome.io/components/light/status_led - platform: status_led - name: ${name}_led_light_1 + name: PCB LED 1 id: led_light_1 pin: 1 entity_category: config - platform: status_led - name: ${name}_led_light_2 + name: PCB LED 2 id: led_light_2 pin: 2 entity_category: config # https://esphome.io/components/light/esp32_rmt_led_strip - platform: esp32_rmt_led_strip - name: ${name}_on_board_light_io48 + name: ESP32 LED id: esp_light channel_colors: GRB - pin: 48 + pin: ${rgb_led_pin} num_leds: 1 # rmt_channel: 0 chipset: ws2812 diff --git a/packages/board/board_ESP32-S3_DevKitC-1_PVbrain2_LED-38.yaml b/packages/board/board_ESP32-S3_DevKitC-1_PVbrain2_LED-38.yaml new file mode 100644 index 0000000..b69629f --- /dev/null +++ b/packages/board/board_ESP32-S3_DevKitC-1_PVbrain2_LED-38.yaml @@ -0,0 +1,30 @@ +# Updated : 2026.08.27 +# Version : 1.1.0 +# 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 . + +# LED DevKitC-1 V1.0 = 48 / V1.1 = 38 + +substitutions: + # canbus_esp32_can + tx_pin_4: '48' + rx_pin_4: '39' + # RGB LED + rgb_led_pin: '38' + +packages: + pvbrain2: !include board_ESP32-S3_DevKitC-1_PVbrain2.yaml diff --git a/packages/board/board_ESP32-S3_DevKitC-1_PVbrain2_LED-48.yaml b/packages/board/board_ESP32-S3_DevKitC-1_PVbrain2_LED-48.yaml new file mode 100644 index 0000000..28e29d7 --- /dev/null +++ b/packages/board/board_ESP32-S3_DevKitC-1_PVbrain2_LED-48.yaml @@ -0,0 +1,30 @@ +# Updated : 2026.08.27 +# Version : 1.1.0 +# 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 . + +# LED DevKitC-1 V1.0 = 48 / V1.1 = 38 + +substitutions: + # canbus_esp32_can + tx_pin_4: '38' + rx_pin_4: '39' + # RGB LED + rgb_led_pin: '48' + +packages: + pvbrain2: !include board_ESP32-S3_DevKitC-1_PVbrain2.yaml diff --git a/packages/yambms/yambms_rs485_pylon.yaml b/packages/yambms/yambms_rs485_pylon.yaml index bb6660a..82006f2 100644 --- a/packages/yambms/yambms_rs485_pylon.yaml +++ b/packages/yambms/yambms_rs485_pylon.yaml @@ -1,6 +1,6 @@ -# Updated : 2026.08.21 -# Version : 1.4.3 -# GitHub : https://github.com/fahmula/esphome-pylontech-rs485 +# Updated : 2026.08.27 +# Version : 1.1.0 +# GitHub : https://github.com/Sleeper85/esphome-yambms # YamBMS ( Yet another multi-BMS Merging Solution ) @@ -17,319 +17,9 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -substitutions: - # The ID of the LED on your board used for this component - rs485_status_led_id: "virtual_status_light" - -esphome: - on_boot: - - priority: 600.0 - then: - - lambda: |- - // Register System - id(global_register_led)(${CAT_INV_RS485}, ${rs485_id}, id(${rs485_status_led_id})); - // Force register fault as default, will be updated once RS485 is working - // (true = fault) - id(global_update_fault)(${CAT_INV_RS485}, ${rs485_id}, true); - - priority: -100.0 - then: - - lambda: |- - // Increment the interface counter for the `requested current` division - id(yambms${yambms_id}_var_comm_interfaces_count)++; - - // Initialise RS485 status as off - id(rs485${rs485_id}_status).publish_state(false); - - devices: - - id: rs485_${rs485_id} - name: "${yambms_name} ${rs485_name}" - -external_components: - - source: github://fahmula/esphome-pylontech-rs485@main - refresh: 0s +packages: + rs485_pylon: !include yambms_rs485_pylon_core.yaml uart: - id: !extend ${rs485_uart_id} baud_rate: ${rs485_uart_baud_rate} - -select: - - platform: template - name: "YamBMS protocol" - id: rs485${rs485_id}_protocol - device_id: rs485_${rs485_id} - options: - - "Pylontech" - - "Disabled" - restore_value: true - initial_option: "Pylontech" - optimistic: true - entity_category: config - -switch: - - platform: template - name: "Inverter Heartbeat Monitoring" - id: rs485${rs485_id}_switch_inverter_heartbeat_monitoring - device_id: rs485_${rs485_id} - restore_mode: RESTORE_DEFAULT_OFF - optimistic: true - entity_category: diagnostic - -sensor: - - platform: template - id: rs485${rs485_id}_proxy_soc - internal: true - - platform: template - id: rs485${rs485_id}_proxy_voltage - internal: true - - platform: template - id: rs485${rs485_id}_proxy_current - internal: true - - platform: template - id: rs485${rs485_id}_proxy_temperature - internal: true - - platform: template - id: rs485${rs485_id}_proxy_soh - internal: true - - platform: template - id: rs485${rs485_id}_proxy_cycle_count - internal: true - - platform: template - id: rs485${rs485_id}_proxy_max_cell_v - internal: true - - platform: template - id: rs485${rs485_id}_proxy_min_cell_v - internal: true - - platform: template - id: rs485${rs485_id}_proxy_max_temp - internal: true - - platform: template - id: rs485${rs485_id}_proxy_min_temp - internal: true - - platform: template - id: rs485${rs485_id}_proxy_max_charge_v - internal: true - - platform: template - id: rs485${rs485_id}_proxy_min_discharge_v - internal: true - - platform: template - id: rs485${rs485_id}_proxy_max_charge_i - internal: true - - platform: template - id: rs485${rs485_id}_proxy_max_discharge_i - internal: true - # --- Inverter Heartbeat --- - - platform: template - id: rs485${rs485_id}_inverter_heartbeat - device_id: rs485_${rs485_id} - name: "Inverter Heartbeat" - unit_of_measurement: ms - device_class: duration - accuracy_decimals: 0 - icon: mdi:update - entity_category: diagnostic - -binary_sensor: - # --- Passive Proxy Alarm/Protection Sensors --- - - platform: template - id: rs485${rs485_id}_proxy_total_voltage_high_alarm - internal: true - - platform: template - id: rs485${rs485_id}_proxy_total_voltage_low_alarm - internal: true - - platform: template - id: rs485${rs485_id}_proxy_cell_temp_high_alarm - internal: true - - platform: template - id: rs485${rs485_id}_proxy_cell_temp_low_alarm - internal: true - - platform: template - id: rs485${rs485_id}_proxy_charge_overcurrent_alarm - internal: true - - platform: template - id: rs485${rs485_id}_proxy_discharge_overcurrent_alarm - internal: true - - platform: template - id: rs485${rs485_id}_proxy_cell_imbalance_alarm - internal: true - - platform: template - id: rs485${rs485_id}_proxy_cell_voltage_high_alarm - internal: true - - platform: template - id: rs485${rs485_id}_proxy_cell_voltage_low_alarm - internal: true - - platform: template - id: rs485${rs485_id}_proxy_cell_overvoltage_protection - internal: true - - platform: template - id: rs485${rs485_id}_proxy_cell_undervoltage_protection - internal: true - - platform: template - id: rs485${rs485_id}_proxy_cell_overtemp_protection - internal: true - - platform: template - id: rs485${rs485_id}_proxy_cell_undertemp_protection - internal: true - - platform: template - id: rs485${rs485_id}_proxy_charge_overcurrent_protection - internal: true - - platform: template - id: rs485${rs485_id}_proxy_discharge_overcurrent_protection - internal: true - - platform: template - id: rs485${rs485_id}_proxy_system_fault_protection - internal: true - # --- RS485 Status --- - - platform: template - id: rs485${rs485_id}_status - device_id: rs485_${rs485_id} - name: "Status" - 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_INV_RS485}, ${rs485_id}, !x); - -interval: - - interval: 24h - then: - - lambda: |- - // Save RS485 options - id(yambms${yambms_id}_var_communication_bus) = "RS485"; - id(yambms${yambms_id}_var_communication_protocol) = id(rs485${rs485_id}_protocol).current_option(); - - - interval: 100ms - then: - - if: - condition: - lambda: 'return id(rs485${rs485_id}_protocol).current_option() == "Pylontech";' - then: - - lambda: !lambda |- - // Mirror RS485 status into inverter_com_status - if (id(rs485${rs485_id}_status).has_state()) id(inverter_com_status).publish_state(id(rs485${rs485_id}_status).state); - - // --- Check YamBMS initialized + BMS ONLINE/OFFLINE status --- - if ((id(yambms${yambms_id}_var_initialized) == true) && (id(yambms${yambms_id}_bms_combined).state > 0)) - { - // --- STATE 1: BMS is ONLINE --- - // Sensor Values - if (id(yambms${yambms_id}_battery_soc).has_state()) id(rs485${rs485_id}_proxy_soc).publish_state(id(yambms${yambms_id}_battery_soc).state); - if (id(yambms${yambms_id}_total_voltage).has_state()) id(rs485${rs485_id}_proxy_voltage).publish_state(id(yambms${yambms_id}_total_voltage).state); - if (id(yambms${yambms_id}_current).has_state()) id(rs485${rs485_id}_proxy_current).publish_state(id(yambms${yambms_id}_current).state); - if (id(yambms${yambms_id}_max_temperature).has_state()) id(rs485${rs485_id}_proxy_temperature).publish_state(id(yambms${yambms_id}_max_temperature).state); - if (id(yambms${yambms_id}_battery_soh).has_state()) id(rs485${rs485_id}_proxy_soh).publish_state(id(yambms${yambms_id}_battery_soh).state); - if (id(yambms${yambms_id}_charging_cycles).has_state()) id(rs485${rs485_id}_proxy_cycle_count).publish_state(id(yambms${yambms_id}_charging_cycles).state); - if (id(yambms${yambms_id}_max_cell_voltage).has_state()) id(rs485${rs485_id}_proxy_max_cell_v).publish_state(id(yambms${yambms_id}_max_cell_voltage).state); - if (id(yambms${yambms_id}_min_cell_voltage).has_state()) id(rs485${rs485_id}_proxy_min_cell_v).publish_state(id(yambms${yambms_id}_min_cell_voltage).state); - if (id(yambms${yambms_id}_max_temperature).has_state()) id(rs485${rs485_id}_proxy_max_temp).publish_state(id(yambms${yambms_id}_max_temperature).state); - if (id(yambms${yambms_id}_min_temperature).has_state()) id(rs485${rs485_id}_proxy_min_temp).publish_state(id(yambms${yambms_id}_min_temperature).state); - if (id(yambms${yambms_id}_requested_charge_voltage).has_state()) id(rs485${rs485_id}_proxy_max_charge_v).publish_state(id(yambms${yambms_id}_requested_charge_voltage).state); - if (id(yambms${yambms_id}_requested_discharge_voltage).has_state()) id(rs485${rs485_id}_proxy_min_discharge_v).publish_state(id(yambms${yambms_id}_requested_discharge_voltage).state); - if (id(yambms${yambms_id}_requested_charge_current).has_state()) id(rs485${rs485_id}_proxy_max_charge_i).publish_state(id(yambms${yambms_id}_requested_charge_current).state); - if (id(yambms${yambms_id}_requested_discharge_current).has_state()) id(rs485${rs485_id}_proxy_max_discharge_i).publish_state(id(yambms${yambms_id}_requested_discharge_current).state); - // Binary Sensors (Alarms/Protections) - if (id(yambms${yambms_id}_errors_bitmask_warning).has_state()) { - uint16_t mask = id(yambms${yambms_id}_errors_bitmask_warning).state; - id(rs485${rs485_id}_proxy_total_voltage_high_alarm).publish_state((mask & 0x0002) > 0); - id(rs485${rs485_id}_proxy_total_voltage_low_alarm).publish_state((mask & 0x0004) > 0); - id(rs485${rs485_id}_proxy_cell_temp_high_alarm).publish_state((mask & 0x0008) > 0); - id(rs485${rs485_id}_proxy_cell_temp_low_alarm).publish_state((mask & 0x0010) > 0); - id(rs485${rs485_id}_proxy_charge_overcurrent_alarm).publish_state((mask & 0x0100) > 0); - id(rs485${rs485_id}_proxy_discharge_overcurrent_alarm).publish_state((mask & 0x0080) > 0); - id(rs485${rs485_id}_proxy_cell_imbalance_alarm).publish_state((mask & 0x1000) > 0); - id(rs485${rs485_id}_proxy_cell_voltage_high_alarm).publish_state((mask & 0x0002) > 0); - id(rs485${rs485_id}_proxy_cell_voltage_low_alarm).publish_state((mask & 0x0004) > 0); - } - if (id(yambms${yambms_id}_errors_bitmask_alarm).has_state()) { - uint16_t mask = id(yambms${yambms_id}_errors_bitmask_alarm).state; - id(rs485${rs485_id}_proxy_cell_overvoltage_protection).publish_state((mask & 0x0002) > 0); - id(rs485${rs485_id}_proxy_cell_undervoltage_protection).publish_state((mask & 0x0004) > 0); - id(rs485${rs485_id}_proxy_cell_overtemp_protection).publish_state((mask & 0x0008) > 0); - id(rs485${rs485_id}_proxy_cell_undertemp_protection).publish_state((mask & 0x0010) > 0); - id(rs485${rs485_id}_proxy_charge_overcurrent_protection).publish_state((mask & 0x0100) > 0); - id(rs485${rs485_id}_proxy_discharge_overcurrent_protection).publish_state((mask & 0x0080) > 0); - id(rs485${rs485_id}_proxy_system_fault_protection).publish_state((mask & 0x0800) > 0); - } - } else { - // --- STATE 2: BMS is OFFLINE --- - // Invalidate all proxy sensors to trigger component's fail-safe. - id(rs485${rs485_id}_proxy_soc).publish_state(NAN); - id(rs485${rs485_id}_proxy_voltage).publish_state(NAN); - id(rs485${rs485_id}_proxy_current).publish_state(NAN); - id(rs485${rs485_id}_proxy_temperature).publish_state(NAN); - id(rs485${rs485_id}_proxy_soh).publish_state(NAN); - id(rs485${rs485_id}_proxy_cycle_count).publish_state(NAN); - id(rs485${rs485_id}_proxy_max_cell_v).publish_state(NAN); - id(rs485${rs485_id}_proxy_min_cell_v).publish_state(NAN); - id(rs485${rs485_id}_proxy_max_temp).publish_state(NAN); - id(rs485${rs485_id}_proxy_min_temp).publish_state(NAN); - id(rs485${rs485_id}_proxy_max_charge_v).publish_state(NAN); - id(rs485${rs485_id}_proxy_min_discharge_v).publish_state(NAN); - id(rs485${rs485_id}_proxy_max_charge_i).publish_state(NAN); - id(rs485${rs485_id}_proxy_max_discharge_i).publish_state(NAN); - - // Publish 'false' to clear any alarms/protections. - id(rs485${rs485_id}_proxy_total_voltage_high_alarm).publish_state(false); - id(rs485${rs485_id}_proxy_total_voltage_low_alarm).publish_state(false); - id(rs485${rs485_id}_proxy_cell_temp_high_alarm).publish_state(false); - id(rs485${rs485_id}_proxy_cell_temp_low_alarm).publish_state(false); - id(rs485${rs485_id}_proxy_charge_overcurrent_alarm).publish_state(false); - id(rs485${rs485_id}_proxy_discharge_overcurrent_alarm).publish_state(false); - id(rs485${rs485_id}_proxy_cell_imbalance_alarm).publish_state(false); - id(rs485${rs485_id}_proxy_cell_voltage_high_alarm).publish_state(false); - id(rs485${rs485_id}_proxy_cell_voltage_low_alarm).publish_state(false); - id(rs485${rs485_id}_proxy_cell_overvoltage_protection).publish_state(false); - id(rs485${rs485_id}_proxy_cell_undervoltage_protection).publish_state(false); - id(rs485${rs485_id}_proxy_cell_overtemp_protection).publish_state(false); - id(rs485${rs485_id}_proxy_cell_undertemp_protection).publish_state(false); - id(rs485${rs485_id}_proxy_charge_overcurrent_protection).publish_state(false); - id(rs485${rs485_id}_proxy_discharge_overcurrent_protection).publish_state(false); - id(rs485${rs485_id}_proxy_system_fault_protection).publish_state(false); - } - -pylontech_rs485: - - uart_id: ${rs485_uart_id} - update_timeout: ${rs485_update_timeout} - # --- Link to PROXY sensors --- - state_of_charge: rs485${rs485_id}_proxy_soc - voltage: rs485${rs485_id}_proxy_voltage - current: rs485${rs485_id}_proxy_current - temperature: rs485${rs485_id}_proxy_temperature - state_of_health: rs485${rs485_id}_proxy_soh - cycle_count: rs485${rs485_id}_proxy_cycle_count - max_cell_voltage: rs485${rs485_id}_proxy_max_cell_v - min_cell_voltage: rs485${rs485_id}_proxy_min_cell_v - max_temperature: rs485${rs485_id}_proxy_max_temp - min_temperature: rs485${rs485_id}_proxy_min_temp - mosfet_temperature: rs485${rs485_id}_proxy_temperature - max_mosfet_temperature: rs485${rs485_id}_proxy_max_temp - min_mosfet_temperature: rs485${rs485_id}_proxy_min_temp - bms_temperature: rs485${rs485_id}_proxy_temperature - max_bms_temperature: rs485${rs485_id}_proxy_max_temp - min_bms_temperature: rs485${rs485_id}_proxy_min_temp - total_voltage_high_alarm: rs485${rs485_id}_proxy_total_voltage_high_alarm - total_voltage_low_alarm: rs485${rs485_id}_proxy_total_voltage_low_alarm - cell_voltage_high_alarm: rs485${rs485_id}_proxy_cell_voltage_high_alarm - cell_voltage_low_alarm: rs485${rs485_id}_proxy_cell_voltage_low_alarm - cell_temp_high_alarm: rs485${rs485_id}_proxy_cell_temp_high_alarm - cell_temp_low_alarm: rs485${rs485_id}_proxy_cell_temp_low_alarm - charge_overcurrent_alarm: rs485${rs485_id}_proxy_charge_overcurrent_alarm - discharge_overcurrent_alarm: rs485${rs485_id}_proxy_discharge_overcurrent_alarm - cell_imbalance_alarm: rs485${rs485_id}_proxy_cell_imbalance_alarm - cell_overvoltage_protection: rs485${rs485_id}_proxy_cell_overvoltage_protection - cell_undervoltage_protection: rs485${rs485_id}_proxy_cell_undervoltage_protection - cell_overtemp_protection: rs485${rs485_id}_proxy_cell_overtemp_protection - cell_undertemp_protection: rs485${rs485_id}_proxy_cell_undertemp_protection - charge_overcurrent_protection: rs485${rs485_id}_proxy_charge_overcurrent_protection - discharge_overcurrent_protection: rs485${rs485_id}_proxy_discharge_overcurrent_protection - system_fault_protection: rs485${rs485_id}_proxy_system_fault_protection - max_voltage: rs485${rs485_id}_proxy_max_charge_v - min_voltage: rs485${rs485_id}_proxy_min_discharge_v - max_charge_current: rs485${rs485_id}_proxy_max_charge_i - max_discharge_current: rs485${rs485_id}_proxy_max_discharge_i - requested_force_charge: yambms${yambms_id}_requested_force_charge - # --- Inverter Heartbeat & Com Status --- - inverter_heartbeat: rs485${rs485_id}_inverter_heartbeat - rs485_status: rs485${rs485_id}_status - heartbeat_switch: rs485${rs485_id}_switch_inverter_heartbeat_monitoring diff --git a/packages/yambms/yambms_rs485_pylon_core.yaml b/packages/yambms/yambms_rs485_pylon_core.yaml new file mode 100644 index 0000000..3ed4c51 --- /dev/null +++ b/packages/yambms/yambms_rs485_pylon_core.yaml @@ -0,0 +1,331 @@ +# Updated : 2026.08.27 +# Version : 1.4.4 +# GitHub : https://github.com/fahmula/esphome-pylontech-rs485 + +# 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: + # The ID of the LED on your board used for this component + rs485_status_led_id: "virtual_status_light" + +esphome: + on_boot: + - priority: 600.0 + then: + - lambda: |- + // Register System + id(global_register_led)(${CAT_INV_RS485}, ${rs485_id}, id(${rs485_status_led_id})); + // Force register fault as default, will be updated once RS485 is working + // (true = fault) + id(global_update_fault)(${CAT_INV_RS485}, ${rs485_id}, true); + - priority: -100.0 + then: + - lambda: |- + // Increment the interface counter for the `requested current` division + id(yambms${yambms_id}_var_comm_interfaces_count)++; + + // Initialise RS485 status as off + id(rs485${rs485_id}_status).publish_state(false); + + devices: + - id: rs485_${rs485_id} + name: "${yambms_name} ${rs485_name}" + +external_components: + - source: github://fahmula/esphome-pylontech-rs485@main + refresh: 0s + +select: + - platform: template + name: "YamBMS protocol" + id: rs485${rs485_id}_protocol + device_id: rs485_${rs485_id} + options: + - "Pylontech" + - "Disabled" + restore_value: true + initial_option: "Pylontech" + optimistic: true + entity_category: config + +switch: + - platform: template + name: "Inverter Heartbeat Monitoring" + id: rs485${rs485_id}_switch_inverter_heartbeat_monitoring + device_id: rs485_${rs485_id} + restore_mode: RESTORE_DEFAULT_OFF + optimistic: true + entity_category: diagnostic + +sensor: + - platform: template + id: rs485${rs485_id}_proxy_soc + internal: true + - platform: template + id: rs485${rs485_id}_proxy_voltage + internal: true + - platform: template + id: rs485${rs485_id}_proxy_current + internal: true + - platform: template + id: rs485${rs485_id}_proxy_temperature + internal: true + - platform: template + id: rs485${rs485_id}_proxy_soh + internal: true + - platform: template + id: rs485${rs485_id}_proxy_cycle_count + internal: true + - platform: template + id: rs485${rs485_id}_proxy_max_cell_v + internal: true + - platform: template + id: rs485${rs485_id}_proxy_min_cell_v + internal: true + - platform: template + id: rs485${rs485_id}_proxy_max_temp + internal: true + - platform: template + id: rs485${rs485_id}_proxy_min_temp + internal: true + - platform: template + id: rs485${rs485_id}_proxy_max_charge_v + internal: true + - platform: template + id: rs485${rs485_id}_proxy_min_discharge_v + internal: true + - platform: template + id: rs485${rs485_id}_proxy_max_charge_i + internal: true + - platform: template + id: rs485${rs485_id}_proxy_max_discharge_i + internal: true + # --- Inverter Heartbeat --- + - platform: template + id: rs485${rs485_id}_inverter_heartbeat + device_id: rs485_${rs485_id} + name: "Inverter Heartbeat" + unit_of_measurement: ms + device_class: duration + accuracy_decimals: 0 + icon: mdi:update + entity_category: diagnostic + +binary_sensor: + # --- Passive Proxy Alarm/Protection Sensors --- + - platform: template + id: rs485${rs485_id}_proxy_total_voltage_high_alarm + internal: true + - platform: template + id: rs485${rs485_id}_proxy_total_voltage_low_alarm + internal: true + - platform: template + id: rs485${rs485_id}_proxy_cell_temp_high_alarm + internal: true + - platform: template + id: rs485${rs485_id}_proxy_cell_temp_low_alarm + internal: true + - platform: template + id: rs485${rs485_id}_proxy_charge_overcurrent_alarm + internal: true + - platform: template + id: rs485${rs485_id}_proxy_discharge_overcurrent_alarm + internal: true + - platform: template + id: rs485${rs485_id}_proxy_cell_imbalance_alarm + internal: true + - platform: template + id: rs485${rs485_id}_proxy_cell_voltage_high_alarm + internal: true + - platform: template + id: rs485${rs485_id}_proxy_cell_voltage_low_alarm + internal: true + - platform: template + id: rs485${rs485_id}_proxy_cell_overvoltage_protection + internal: true + - platform: template + id: rs485${rs485_id}_proxy_cell_undervoltage_protection + internal: true + - platform: template + id: rs485${rs485_id}_proxy_cell_overtemp_protection + internal: true + - platform: template + id: rs485${rs485_id}_proxy_cell_undertemp_protection + internal: true + - platform: template + id: rs485${rs485_id}_proxy_charge_overcurrent_protection + internal: true + - platform: template + id: rs485${rs485_id}_proxy_discharge_overcurrent_protection + internal: true + - platform: template + id: rs485${rs485_id}_proxy_system_fault_protection + internal: true + # --- RS485 Status --- + - platform: template + id: rs485${rs485_id}_status + device_id: rs485_${rs485_id} + name: "Status" + 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_INV_RS485}, ${rs485_id}, !x); + +interval: + - interval: 24h + then: + - lambda: |- + // Save RS485 options + id(yambms${yambms_id}_var_communication_bus) = "RS485"; + id(yambms${yambms_id}_var_communication_protocol) = id(rs485${rs485_id}_protocol).current_option(); + + - interval: 100ms + then: + - if: + condition: + lambda: 'return id(rs485${rs485_id}_protocol).current_option() == "Pylontech";' + then: + - lambda: !lambda |- + // Mirror RS485 status into inverter_com_status + if (id(rs485${rs485_id}_status).has_state()) id(inverter_com_status).publish_state(id(rs485${rs485_id}_status).state); + + // --- Check YamBMS initialized + BMS ONLINE/OFFLINE status --- + if ((id(yambms${yambms_id}_var_initialized) == true) && (id(yambms${yambms_id}_bms_combined).state > 0)) + { + // --- STATE 1: BMS is ONLINE --- + // Sensor Values + if (id(yambms${yambms_id}_battery_soc).has_state()) id(rs485${rs485_id}_proxy_soc).publish_state(id(yambms${yambms_id}_battery_soc).state); + if (id(yambms${yambms_id}_total_voltage).has_state()) id(rs485${rs485_id}_proxy_voltage).publish_state(id(yambms${yambms_id}_total_voltage).state); + if (id(yambms${yambms_id}_current).has_state()) id(rs485${rs485_id}_proxy_current).publish_state(id(yambms${yambms_id}_current).state); + if (id(yambms${yambms_id}_max_temperature).has_state()) id(rs485${rs485_id}_proxy_temperature).publish_state(id(yambms${yambms_id}_max_temperature).state); + if (id(yambms${yambms_id}_battery_soh).has_state()) id(rs485${rs485_id}_proxy_soh).publish_state(id(yambms${yambms_id}_battery_soh).state); + if (id(yambms${yambms_id}_charging_cycles).has_state()) id(rs485${rs485_id}_proxy_cycle_count).publish_state(id(yambms${yambms_id}_charging_cycles).state); + if (id(yambms${yambms_id}_max_cell_voltage).has_state()) id(rs485${rs485_id}_proxy_max_cell_v).publish_state(id(yambms${yambms_id}_max_cell_voltage).state); + if (id(yambms${yambms_id}_min_cell_voltage).has_state()) id(rs485${rs485_id}_proxy_min_cell_v).publish_state(id(yambms${yambms_id}_min_cell_voltage).state); + if (id(yambms${yambms_id}_max_temperature).has_state()) id(rs485${rs485_id}_proxy_max_temp).publish_state(id(yambms${yambms_id}_max_temperature).state); + if (id(yambms${yambms_id}_min_temperature).has_state()) id(rs485${rs485_id}_proxy_min_temp).publish_state(id(yambms${yambms_id}_min_temperature).state); + if (id(yambms${yambms_id}_requested_charge_voltage).has_state()) id(rs485${rs485_id}_proxy_max_charge_v).publish_state(id(yambms${yambms_id}_requested_charge_voltage).state); + if (id(yambms${yambms_id}_requested_discharge_voltage).has_state()) id(rs485${rs485_id}_proxy_min_discharge_v).publish_state(id(yambms${yambms_id}_requested_discharge_voltage).state); + if (id(yambms${yambms_id}_requested_charge_current).has_state()) id(rs485${rs485_id}_proxy_max_charge_i).publish_state(id(yambms${yambms_id}_requested_charge_current).state); + if (id(yambms${yambms_id}_requested_discharge_current).has_state()) id(rs485${rs485_id}_proxy_max_discharge_i).publish_state(id(yambms${yambms_id}_requested_discharge_current).state); + // Binary Sensors (Alarms/Protections) + if (id(yambms${yambms_id}_errors_bitmask_warning).has_state()) { + uint16_t mask = id(yambms${yambms_id}_errors_bitmask_warning).state; + id(rs485${rs485_id}_proxy_total_voltage_high_alarm).publish_state((mask & 0x0002) > 0); + id(rs485${rs485_id}_proxy_total_voltage_low_alarm).publish_state((mask & 0x0004) > 0); + id(rs485${rs485_id}_proxy_cell_temp_high_alarm).publish_state((mask & 0x0008) > 0); + id(rs485${rs485_id}_proxy_cell_temp_low_alarm).publish_state((mask & 0x0010) > 0); + id(rs485${rs485_id}_proxy_charge_overcurrent_alarm).publish_state((mask & 0x0100) > 0); + id(rs485${rs485_id}_proxy_discharge_overcurrent_alarm).publish_state((mask & 0x0080) > 0); + id(rs485${rs485_id}_proxy_cell_imbalance_alarm).publish_state((mask & 0x1000) > 0); + id(rs485${rs485_id}_proxy_cell_voltage_high_alarm).publish_state((mask & 0x0002) > 0); + id(rs485${rs485_id}_proxy_cell_voltage_low_alarm).publish_state((mask & 0x0004) > 0); + } + if (id(yambms${yambms_id}_errors_bitmask_alarm).has_state()) { + uint16_t mask = id(yambms${yambms_id}_errors_bitmask_alarm).state; + id(rs485${rs485_id}_proxy_cell_overvoltage_protection).publish_state((mask & 0x0002) > 0); + id(rs485${rs485_id}_proxy_cell_undervoltage_protection).publish_state((mask & 0x0004) > 0); + id(rs485${rs485_id}_proxy_cell_overtemp_protection).publish_state((mask & 0x0008) > 0); + id(rs485${rs485_id}_proxy_cell_undertemp_protection).publish_state((mask & 0x0010) > 0); + id(rs485${rs485_id}_proxy_charge_overcurrent_protection).publish_state((mask & 0x0100) > 0); + id(rs485${rs485_id}_proxy_discharge_overcurrent_protection).publish_state((mask & 0x0080) > 0); + id(rs485${rs485_id}_proxy_system_fault_protection).publish_state((mask & 0x0800) > 0); + } + } else { + // --- STATE 2: BMS is OFFLINE --- + // Invalidate all proxy sensors to trigger component's fail-safe. + id(rs485${rs485_id}_proxy_soc).publish_state(NAN); + id(rs485${rs485_id}_proxy_voltage).publish_state(NAN); + id(rs485${rs485_id}_proxy_current).publish_state(NAN); + id(rs485${rs485_id}_proxy_temperature).publish_state(NAN); + id(rs485${rs485_id}_proxy_soh).publish_state(NAN); + id(rs485${rs485_id}_proxy_cycle_count).publish_state(NAN); + id(rs485${rs485_id}_proxy_max_cell_v).publish_state(NAN); + id(rs485${rs485_id}_proxy_min_cell_v).publish_state(NAN); + id(rs485${rs485_id}_proxy_max_temp).publish_state(NAN); + id(rs485${rs485_id}_proxy_min_temp).publish_state(NAN); + id(rs485${rs485_id}_proxy_max_charge_v).publish_state(NAN); + id(rs485${rs485_id}_proxy_min_discharge_v).publish_state(NAN); + id(rs485${rs485_id}_proxy_max_charge_i).publish_state(NAN); + id(rs485${rs485_id}_proxy_max_discharge_i).publish_state(NAN); + + // Publish 'false' to clear any alarms/protections. + id(rs485${rs485_id}_proxy_total_voltage_high_alarm).publish_state(false); + id(rs485${rs485_id}_proxy_total_voltage_low_alarm).publish_state(false); + id(rs485${rs485_id}_proxy_cell_temp_high_alarm).publish_state(false); + id(rs485${rs485_id}_proxy_cell_temp_low_alarm).publish_state(false); + id(rs485${rs485_id}_proxy_charge_overcurrent_alarm).publish_state(false); + id(rs485${rs485_id}_proxy_discharge_overcurrent_alarm).publish_state(false); + id(rs485${rs485_id}_proxy_cell_imbalance_alarm).publish_state(false); + id(rs485${rs485_id}_proxy_cell_voltage_high_alarm).publish_state(false); + id(rs485${rs485_id}_proxy_cell_voltage_low_alarm).publish_state(false); + id(rs485${rs485_id}_proxy_cell_overvoltage_protection).publish_state(false); + id(rs485${rs485_id}_proxy_cell_undervoltage_protection).publish_state(false); + id(rs485${rs485_id}_proxy_cell_overtemp_protection).publish_state(false); + id(rs485${rs485_id}_proxy_cell_undertemp_protection).publish_state(false); + id(rs485${rs485_id}_proxy_charge_overcurrent_protection).publish_state(false); + id(rs485${rs485_id}_proxy_discharge_overcurrent_protection).publish_state(false); + id(rs485${rs485_id}_proxy_system_fault_protection).publish_state(false); + } + +pylontech_rs485: + - uart_id: ${rs485_uart_id} + update_timeout: ${rs485_update_timeout} + # --- Link to PROXY sensors --- + state_of_charge: rs485${rs485_id}_proxy_soc + voltage: rs485${rs485_id}_proxy_voltage + current: rs485${rs485_id}_proxy_current + temperature: rs485${rs485_id}_proxy_temperature + state_of_health: rs485${rs485_id}_proxy_soh + cycle_count: rs485${rs485_id}_proxy_cycle_count + max_cell_voltage: rs485${rs485_id}_proxy_max_cell_v + min_cell_voltage: rs485${rs485_id}_proxy_min_cell_v + max_temperature: rs485${rs485_id}_proxy_max_temp + min_temperature: rs485${rs485_id}_proxy_min_temp + mosfet_temperature: rs485${rs485_id}_proxy_temperature + max_mosfet_temperature: rs485${rs485_id}_proxy_max_temp + min_mosfet_temperature: rs485${rs485_id}_proxy_min_temp + bms_temperature: rs485${rs485_id}_proxy_temperature + max_bms_temperature: rs485${rs485_id}_proxy_max_temp + min_bms_temperature: rs485${rs485_id}_proxy_min_temp + total_voltage_high_alarm: rs485${rs485_id}_proxy_total_voltage_high_alarm + total_voltage_low_alarm: rs485${rs485_id}_proxy_total_voltage_low_alarm + cell_voltage_high_alarm: rs485${rs485_id}_proxy_cell_voltage_high_alarm + cell_voltage_low_alarm: rs485${rs485_id}_proxy_cell_voltage_low_alarm + cell_temp_high_alarm: rs485${rs485_id}_proxy_cell_temp_high_alarm + cell_temp_low_alarm: rs485${rs485_id}_proxy_cell_temp_low_alarm + charge_overcurrent_alarm: rs485${rs485_id}_proxy_charge_overcurrent_alarm + discharge_overcurrent_alarm: rs485${rs485_id}_proxy_discharge_overcurrent_alarm + cell_imbalance_alarm: rs485${rs485_id}_proxy_cell_imbalance_alarm + cell_overvoltage_protection: rs485${rs485_id}_proxy_cell_overvoltage_protection + cell_undervoltage_protection: rs485${rs485_id}_proxy_cell_undervoltage_protection + cell_overtemp_protection: rs485${rs485_id}_proxy_cell_overtemp_protection + cell_undertemp_protection: rs485${rs485_id}_proxy_cell_undertemp_protection + charge_overcurrent_protection: rs485${rs485_id}_proxy_charge_overcurrent_protection + discharge_overcurrent_protection: rs485${rs485_id}_proxy_discharge_overcurrent_protection + system_fault_protection: rs485${rs485_id}_proxy_system_fault_protection + max_voltage: rs485${rs485_id}_proxy_max_charge_v + min_voltage: rs485${rs485_id}_proxy_min_discharge_v + max_charge_current: rs485${rs485_id}_proxy_max_charge_i + max_discharge_current: rs485${rs485_id}_proxy_max_discharge_i + requested_force_charge: yambms${yambms_id}_requested_force_charge + # --- Inverter Heartbeat & Com Status --- + inverter_heartbeat: rs485${rs485_id}_inverter_heartbeat + rs485_status: rs485${rs485_id}_status + heartbeat_switch: rs485${rs485_id}_switch_inverter_heartbeat_monitoring