@@ -1347,6 +1347,22 @@ def value_function_battery_capacity_gen5(initval: int, descr: Any, datadict: dic
13471347 return 0
13481348
13491349
1350+ def value_function_remaining_battery_capacity (initval : int , descr : Any , datadict : dict [str , Any ]) -> int | float :
1351+ # Sum BMS reported capacities to get total available
1352+ bat1_capacity : int | float = datadict .get ("bms_battery_capacity" , 0 )
1353+ bat2_capacity : int | float = datadict .get ("bms_2_battery_capacity" , 0 )
1354+ # Check if we have a chargeable capacity sensor
1355+ chargeable_capacity : int | float = datadict .get ("chargeable_battery_capacity" , - 1 )
1356+ if chargeable_capacity >= 0 :
1357+ # If so, remaining capacity is total less chargeable (clamp to strictly non-negative)
1358+ return max (bat1_capacity + bat2_capacity - chargeable_capacity , 0 )
1359+ # Otherwise base value on per-battery nominal capacity and SoC %. We do not account for SoH
1360+ # as this is an approximation and SoH sensors may be unavailable.
1361+ bat1_soc = float (datadict .get ("battery_1_capacity_charge" , 0 )) / 100.0
1362+ bat2_soc = float (datadict .get ("battery_2_capacity_charge" , 0 )) / 100.0
1363+ return bat1_capacity * bat1_soc + bat2_capacity * bat2_soc
1364+
1365+
13501366def value_function_software_version_g2 (initval : int , descr : Any , datadict : dict [str , Any ]) -> str | None :
13511367 # AC/HYBRID GEN2: split registers hold raw minor versions with a fixed major of 2
13521368 return f"DSP v2.{ datadict .get ('firmware_dsp_minor' )} ARM v2.{ datadict .get ('firmware_arm_minor' )} "
@@ -8353,6 +8369,19 @@ def value_function_bms_2_max_charge(initval: int, descr: Any, datadict: dict[str
83538369 register = 0x118 ,
83548370 register_type = REG_INPUT ,
83558371 register_data_type = REGISTER_U32 ,
8372+ modbus_max = 99 ,
8373+ allowedtypes = AC | HYBRID | GEN4 | GEN5 | GEN6 ,
8374+ ),
8375+ SolaXModbusSensorEntityDescription (
8376+ name = "Remaining Battery Energy" ,
8377+ key = "remaining_battery_capacity" ,
8378+ value_function = value_function_remaining_battery_capacity ,
8379+ native_unit_of_measurement = UnitOfEnergy .WATT_HOUR ,
8380+ device_class = SensorDeviceClass .ENERGY_STORAGE ,
8381+ state_class = SensorStateClass .MEASUREMENT ,
8382+ entity_registry_enabled_default = False ,
8383+ depends_on = ["bms_battery_capacity" , "bms_2_battery_capacity" , "chargeable_battery_capacity" ],
8384+ modbus_min = 100 ,
83568385 allowedtypes = AC | HYBRID | GEN4 | GEN5 | GEN6 ,
83578386 ),
83588387 SolaXModbusSensorEntityDescription (
0 commit comments