Merge PR #74 from Fahmula

RS485 link status, Heartbeat and Requested Force Charge.

Successfully tested with Deye and Battery Lithium `12`.
This commit is contained in:
Sleeper85 authored and GitHub committed 2025-08-02 22:32:17 +02:00
commit f4b54c4acd
1 file changed
+128 -98
+128 -98
View File
@@ -1,5 +1,5 @@
# Updated : 2025.07.10
# Version : 1.2.0
# Updated : 2025.08.02
# Version : 1.3.0
# GitHub : https://github.com/fahmula/esphome-pylontech-rs485
# YamBMS ( Yet another multi-BMS Merging Solution )
@@ -37,100 +37,122 @@ select:
optimistic: true
entity_category: config
switch:
- platform: template
name: "${name} ${rs485_name} Inverter Heartbeat Monitoring"
id: ${rs485_id}_switch_inverter_heartbeat_monitoring
restore_mode: RESTORE_DEFAULT_OFF
optimistic: true
entity_category: diagnostic
sensor:
- platform: template
id: yambms_proxy_soc
id: ${rs485_id}_proxy_soc
internal: true
- platform: template
id: yambms_proxy_voltage
id: ${rs485_id}_proxy_voltage
internal: true
- platform: template
id: yambms_proxy_current
id: ${rs485_id}_proxy_current
internal: true
- platform: template
id: yambms_proxy_temperature
id: ${rs485_id}_proxy_temperature
internal: true
- platform: template
id: yambms_proxy_soh
id: ${rs485_id}_proxy_soh
internal: true
- platform: template
id: yambms_proxy_cycle_count
id: ${rs485_id}_proxy_cycle_count
internal: true
- platform: template
id: yambms_proxy_max_cell_v
id: ${rs485_id}_proxy_max_cell_v
internal: true
- platform: template
id: yambms_proxy_min_cell_v
id: ${rs485_id}_proxy_min_cell_v
internal: true
- platform: template
id: yambms_proxy_max_temp
id: ${rs485_id}_proxy_max_temp
internal: true
- platform: template
id: yambms_proxy_min_temp
id: ${rs485_id}_proxy_min_temp
internal: true
- platform: template
id: yambms_proxy_max_charge_v
id: ${rs485_id}_proxy_max_charge_v
internal: true
- platform: template
id: yambms_proxy_min_discharge_v
id: ${rs485_id}_proxy_min_discharge_v
internal: true
- platform: template
id: yambms_proxy_max_charge_i
id: ${rs485_id}_proxy_max_charge_i
internal: true
- platform: template
id: yambms_proxy_max_discharge_i
id: ${rs485_id}_proxy_max_discharge_i
internal: true
# --- Inverter Heartbeat ---
- platform: template
id: ${rs485_id}_inverter_heartbeat
name: "${name} ${rs485_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: yambms_proxy_total_voltage_high_alarm
id: ${rs485_id}_proxy_total_voltage_high_alarm
internal: true
- platform: template
id: yambms_proxy_total_voltage_low_alarm
id: ${rs485_id}_proxy_total_voltage_low_alarm
internal: true
- platform: template
id: yambms_proxy_cell_temp_high_alarm
id: ${rs485_id}_proxy_cell_temp_high_alarm
internal: true
- platform: template
id: yambms_proxy_cell_temp_low_alarm
id: ${rs485_id}_proxy_cell_temp_low_alarm
internal: true
- platform: template
id: yambms_proxy_charge_overcurrent_alarm
id: ${rs485_id}_proxy_charge_overcurrent_alarm
internal: true
- platform: template
id: yambms_proxy_discharge_overcurrent_alarm
id: ${rs485_id}_proxy_discharge_overcurrent_alarm
internal: true
- platform: template
id: yambms_proxy_cell_imbalance_alarm
id: ${rs485_id}_proxy_cell_imbalance_alarm
internal: true
- platform: template
id: yambms_proxy_cell_voltage_high_alarm
id: ${rs485_id}_proxy_cell_voltage_high_alarm
internal: true
- platform: template
id: yambms_proxy_cell_voltage_low_alarm
id: ${rs485_id}_proxy_cell_voltage_low_alarm
internal: true
- platform: template
id: yambms_proxy_cell_overvoltage_protection
id: ${rs485_id}_proxy_cell_overvoltage_protection
internal: true
- platform: template
id: yambms_proxy_cell_undervoltage_protection
id: ${rs485_id}_proxy_cell_undervoltage_protection
internal: true
- platform: template
id: yambms_proxy_cell_overtemp_protection
id: ${rs485_id}_proxy_cell_overtemp_protection
internal: true
- platform: template
id: yambms_proxy_cell_undertemp_protection
id: ${rs485_id}_proxy_cell_undertemp_protection
internal: true
- platform: template
id: yambms_proxy_charge_overcurrent_protection
id: ${rs485_id}_proxy_charge_overcurrent_protection
internal: true
- platform: template
id: yambms_proxy_discharge_overcurrent_protection
id: ${rs485_id}_proxy_discharge_overcurrent_protection
internal: true
- platform: template
id: yambms_proxy_system_fault_protection
id: ${rs485_id}_proxy_system_fault_protection
internal: true
# --- RS485 Status ---
- platform: template
id: ${rs485_id}_status
name: "${name} ${rs485_name} Status"
entity_category: diagnostic
interval:
- interval: 100ms
@@ -142,81 +164,89 @@ interval:
- lambda: !lambda |-
// --- PROTOCOL ENABLED: Pass real data if available ---
// The .has_state() check prevents race conditions at startup.
if (id(${yambms_id}_battery_soc).has_state()) id(yambms_proxy_soc).publish_state(id(${yambms_id}_battery_soc).state);
if (id(${yambms_id}_total_voltage).has_state()) id(yambms_proxy_voltage).publish_state(id(${yambms_id}_total_voltage).state);
if (id(${yambms_id}_current).has_state()) id(yambms_proxy_current).publish_state(id(${yambms_id}_current).state);
if (id(${yambms_id}_max_temperature).has_state()) id(yambms_proxy_temperature).publish_state(id(${yambms_id}_max_temperature).state);
if (id(${yambms_id}_battery_soh).has_state()) id(yambms_proxy_soh).publish_state(id(${yambms_id}_battery_soh).state);
if (id(${yambms_id}_charging_cycles).has_state()) id(yambms_proxy_cycle_count).publish_state(id(${yambms_id}_charging_cycles).state);
if (id(${yambms_id}_max_cell_voltage).has_state()) id(yambms_proxy_max_cell_v).publish_state(id(${yambms_id}_max_cell_voltage).state);
if (id(${yambms_id}_min_cell_voltage).has_state()) id(yambms_proxy_min_cell_v).publish_state(id(${yambms_id}_min_cell_voltage).state);
if (id(${yambms_id}_max_temperature).has_state()) id(yambms_proxy_max_temp).publish_state(id(${yambms_id}_max_temperature).state);
if (id(${yambms_id}_min_temperature).has_state()) id(yambms_proxy_min_temp).publish_state(id(${yambms_id}_min_temperature).state);
if (id(${yambms_id}_requested_charge_voltage).has_state()) id(yambms_proxy_max_charge_v).publish_state(id(${yambms_id}_requested_charge_voltage).state);
if (id(${yambms_id}_requested_discharge_voltage).has_state()) id(yambms_proxy_min_discharge_v).publish_state(id(${yambms_id}_requested_discharge_voltage).state);
if (id(${yambms_id}_requested_charge_current).has_state()) id(yambms_proxy_max_charge_i).publish_state(id(${yambms_id}_requested_charge_current).state);
if (id(${yambms_id}_requested_discharge_current).has_state()) id(yambms_proxy_max_discharge_i).publish_state(id(${yambms_id}_requested_discharge_current).state);
// Mirror RS485 status into inverter_com_status
if (id(${rs485_id}_status).has_state()) id(inverter_com_status).publish_state(id(${rs485_id}_status).state);
// Sensor Values
if (id(${yambms_id}_battery_soc).has_state()) id(${rs485_id}_proxy_soc).publish_state(id(${yambms_id}_battery_soc).state);
if (id(${yambms_id}_total_voltage).has_state()) id(${rs485_id}_proxy_voltage).publish_state(id(${yambms_id}_total_voltage).state);
if (id(${yambms_id}_current).has_state()) id(${rs485_id}_proxy_current).publish_state(id(${yambms_id}_current).state);
if (id(${yambms_id}_max_temperature).has_state()) id(${rs485_id}_proxy_temperature).publish_state(id(${yambms_id}_max_temperature).state);
if (id(${yambms_id}_battery_soh).has_state()) id(${rs485_id}_proxy_soh).publish_state(id(${yambms_id}_battery_soh).state);
if (id(${yambms_id}_charging_cycles).has_state()) id(${rs485_id}_proxy_cycle_count).publish_state(id(${yambms_id}_charging_cycles).state);
if (id(${yambms_id}_max_cell_voltage).has_state()) id(${rs485_id}_proxy_max_cell_v).publish_state(id(${yambms_id}_max_cell_voltage).state);
if (id(${yambms_id}_min_cell_voltage).has_state()) id(${rs485_id}_proxy_min_cell_v).publish_state(id(${yambms_id}_min_cell_voltage).state);
if (id(${yambms_id}_max_temperature).has_state()) id(${rs485_id}_proxy_max_temp).publish_state(id(${yambms_id}_max_temperature).state);
if (id(${yambms_id}_min_temperature).has_state()) id(${rs485_id}_proxy_min_temp).publish_state(id(${yambms_id}_min_temperature).state);
if (id(${yambms_id}_requested_charge_voltage).has_state()) id(${rs485_id}_proxy_max_charge_v).publish_state(id(${yambms_id}_requested_charge_voltage).state);
if (id(${yambms_id}_requested_discharge_voltage).has_state()) id(${rs485_id}_proxy_min_discharge_v).publish_state(id(${yambms_id}_requested_discharge_voltage).state);
if (id(${yambms_id}_requested_charge_current).has_state()) id(${rs485_id}_proxy_max_charge_i).publish_state(id(${yambms_id}_requested_charge_current).state);
if (id(${yambms_id}_requested_discharge_current).has_state()) id(${rs485_id}_proxy_max_discharge_i).publish_state(id(${yambms_id}_requested_discharge_current).state);
// Binary Sensors (Alarms/Protections)
if (id(${yambms_id}_errors_bitmask_warning).has_state()) {
uint16_t mask = id(${yambms_id}_errors_bitmask_warning).state;
id(yambms_proxy_total_voltage_high_alarm).publish_state((mask & 0x0002) > 0);
id(yambms_proxy_total_voltage_low_alarm).publish_state((mask & 0x0004) > 0);
id(yambms_proxy_cell_temp_high_alarm).publish_state((mask & 0x0008) > 0);
id(yambms_proxy_cell_temp_low_alarm).publish_state((mask & 0x0010) > 0);
id(yambms_proxy_charge_overcurrent_alarm).publish_state((mask & 0x0100) > 0);
id(yambms_proxy_discharge_overcurrent_alarm).publish_state((mask & 0x0080) > 0);
id(yambms_proxy_cell_imbalance_alarm).publish_state((mask & 0x1000) > 0);
id(yambms_proxy_cell_voltage_high_alarm).publish_state((mask & 0x0002) > 0);
id(yambms_proxy_cell_voltage_low_alarm).publish_state((mask & 0x0004) > 0);
id(${rs485_id}_proxy_total_voltage_high_alarm).publish_state((mask & 0x0002) > 0);
id(${rs485_id}_proxy_total_voltage_low_alarm).publish_state((mask & 0x0004) > 0);
id(${rs485_id}_proxy_cell_temp_high_alarm).publish_state((mask & 0x0008) > 0);
id(${rs485_id}_proxy_cell_temp_low_alarm).publish_state((mask & 0x0010) > 0);
id(${rs485_id}_proxy_charge_overcurrent_alarm).publish_state((mask & 0x0100) > 0);
id(${rs485_id}_proxy_discharge_overcurrent_alarm).publish_state((mask & 0x0080) > 0);
id(${rs485_id}_proxy_cell_imbalance_alarm).publish_state((mask & 0x1000) > 0);
id(${rs485_id}_proxy_cell_voltage_high_alarm).publish_state((mask & 0x0002) > 0);
id(${rs485_id}_proxy_cell_voltage_low_alarm).publish_state((mask & 0x0004) > 0);
}
if (id(${yambms_id}_errors_bitmask_alarm).has_state()) {
uint16_t mask = id(${yambms_id}_errors_bitmask_alarm).state;
id(yambms_proxy_cell_overvoltage_protection).publish_state((mask & 0x0002) > 0);
id(yambms_proxy_cell_undervoltage_protection).publish_state((mask & 0x0004) > 0);
id(yambms_proxy_cell_overtemp_protection).publish_state((mask & 0x0008) > 0);
id(yambms_proxy_cell_undertemp_protection).publish_state((mask & 0x0010) > 0);
id(yambms_proxy_charge_overcurrent_protection).publish_state((mask & 0x0100) > 0);
id(yambms_proxy_discharge_overcurrent_protection).publish_state((mask & 0x0080) > 0);
id(yambms_proxy_system_fault_protection).publish_state((mask & 0x0800) > 0);
id(${rs485_id}_proxy_cell_overvoltage_protection).publish_state((mask & 0x0002) > 0);
id(${rs485_id}_proxy_cell_undervoltage_protection).publish_state((mask & 0x0004) > 0);
id(${rs485_id}_proxy_cell_overtemp_protection).publish_state((mask & 0x0008) > 0);
id(${rs485_id}_proxy_cell_undertemp_protection).publish_state((mask & 0x0010) > 0);
id(${rs485_id}_proxy_charge_overcurrent_protection).publish_state((mask & 0x0100) > 0);
id(${rs485_id}_proxy_discharge_overcurrent_protection).publish_state((mask & 0x0080) > 0);
id(${rs485_id}_proxy_system_fault_protection).publish_state((mask & 0x0800) > 0);
}
pylontech_rs485:
uart_id: ${rs485_uart_id}
update_timeout: ${rs485_update_timeout}
# --- Link to PROXY sensors ---
state_of_charge: yambms_proxy_soc
voltage: yambms_proxy_voltage
current: yambms_proxy_current
temperature: yambms_proxy_temperature
state_of_health: yambms_proxy_soh
cycle_count: yambms_proxy_cycle_count
max_cell_voltage: yambms_proxy_max_cell_v
min_cell_voltage: yambms_proxy_min_cell_v
max_temperature: yambms_proxy_max_temp
min_temperature: yambms_proxy_min_temp
mosfet_temperature: yambms_proxy_temperature
max_mosfet_temperature: yambms_proxy_max_temp
min_mosfet_temperature: yambms_proxy_min_temp
bms_temperature: yambms_proxy_temperature
max_bms_temperature: yambms_proxy_max_temp
min_bms_temperature: yambms_proxy_min_temp
total_voltage_high_alarm: yambms_proxy_total_voltage_high_alarm
total_voltage_low_alarm: yambms_proxy_total_voltage_low_alarm
cell_voltage_high_alarm: yambms_proxy_cell_voltage_high_alarm
cell_voltage_low_alarm: yambms_proxy_cell_voltage_low_alarm
cell_temp_high_alarm: yambms_proxy_cell_temp_high_alarm
cell_temp_low_alarm: yambms_proxy_cell_temp_low_alarm
charge_overcurrent_alarm: yambms_proxy_charge_overcurrent_alarm
discharge_overcurrent_alarm: yambms_proxy_discharge_overcurrent_alarm
cell_imbalance_alarm: yambms_proxy_cell_imbalance_alarm
cell_overvoltage_protection: yambms_proxy_cell_overvoltage_protection
cell_undervoltage_protection: yambms_proxy_cell_undervoltage_protection
cell_overtemp_protection: yambms_proxy_cell_overtemp_protection
cell_undertemp_protection: yambms_proxy_cell_undertemp_protection
charge_overcurrent_protection: yambms_proxy_charge_overcurrent_protection
discharge_overcurrent_protection: yambms_proxy_discharge_overcurrent_protection
system_fault_protection: yambms_proxy_system_fault_protection
max_voltage: yambms_proxy_max_charge_v
min_voltage: yambms_proxy_min_discharge_v
max_charge_current: yambms_proxy_max_charge_i
max_discharge_current: yambms_proxy_max_discharge_i
state_of_charge: ${rs485_id}_proxy_soc
voltage: ${rs485_id}_proxy_voltage
current: ${rs485_id}_proxy_current
temperature: ${rs485_id}_proxy_temperature
state_of_health: ${rs485_id}_proxy_soh
cycle_count: ${rs485_id}_proxy_cycle_count
max_cell_voltage: ${rs485_id}_proxy_max_cell_v
min_cell_voltage: ${rs485_id}_proxy_min_cell_v
max_temperature: ${rs485_id}_proxy_max_temp
min_temperature: ${rs485_id}_proxy_min_temp
mosfet_temperature: ${rs485_id}_proxy_temperature
max_mosfet_temperature: ${rs485_id}_proxy_max_temp
min_mosfet_temperature: ${rs485_id}_proxy_min_temp
bms_temperature: ${rs485_id}_proxy_temperature
max_bms_temperature: ${rs485_id}_proxy_max_temp
min_bms_temperature: ${rs485_id}_proxy_min_temp
total_voltage_high_alarm: ${rs485_id}_proxy_total_voltage_high_alarm
total_voltage_low_alarm: ${rs485_id}_proxy_total_voltage_low_alarm
cell_voltage_high_alarm: ${rs485_id}_proxy_cell_voltage_high_alarm
cell_voltage_low_alarm: ${rs485_id}_proxy_cell_voltage_low_alarm
cell_temp_high_alarm: ${rs485_id}_proxy_cell_temp_high_alarm
cell_temp_low_alarm: ${rs485_id}_proxy_cell_temp_low_alarm
charge_overcurrent_alarm: ${rs485_id}_proxy_charge_overcurrent_alarm
discharge_overcurrent_alarm: ${rs485_id}_proxy_discharge_overcurrent_alarm
cell_imbalance_alarm: ${rs485_id}_proxy_cell_imbalance_alarm
cell_overvoltage_protection: ${rs485_id}_proxy_cell_overvoltage_protection
cell_undervoltage_protection: ${rs485_id}_proxy_cell_undervoltage_protection
cell_overtemp_protection: ${rs485_id}_proxy_cell_overtemp_protection
cell_undertemp_protection: ${rs485_id}_proxy_cell_undertemp_protection
charge_overcurrent_protection: ${rs485_id}_proxy_charge_overcurrent_protection
discharge_overcurrent_protection: ${rs485_id}_proxy_discharge_overcurrent_protection
system_fault_protection: ${rs485_id}_proxy_system_fault_protection
max_voltage: ${rs485_id}_proxy_max_charge_v
min_voltage: ${rs485_id}_proxy_min_discharge_v
max_charge_current: ${rs485_id}_proxy_max_charge_i
max_discharge_current: ${rs485_id}_proxy_max_discharge_i
requested_force_charge: ${yambms_id}_requested_force_charge
# --- Inverter Heartbeat & Com Status ---
inverter_heartbeat: ${rs485_id}_inverter_heartbeat
rs485_status: ${rs485_id}_status
heartbeat_switch: ${rs485_id}_switch_inverter_heartbeat_monitoring