@@ -186,8 +186,9 @@ async def async_setup_entry(
186186 entities .append (SolarEdgeBatteryAvailableEnergy (battery , config_entry ))
187187 entities .append (SolarEdgeBatterySOH (battery , config_entry ))
188188 entities .append (SolarEdgeBatterySOE (battery , config_entry ))
189+ entities .append (SolarEdgeBatterySOC (battery , config_entry ))
189190 entities .append (SolarEdgeBatteryStatus (battery , config_entry ))
190-
191+
191192 if entities :
192193 async_add_entities (entities )
193194
@@ -1565,6 +1566,43 @@ def native_value(self):
15651566 else :
15661567 return round (self ._platform .decoded_model ['B_SOE' ], 0 )
15671568
1569+
1570+ class SolarEdgeBatterySOC (SolarEdgeSensorBase ):
1571+ state_class = SensorStateClass .MEASUREMENT
1572+ native_unit_of_measurement = PERCENTAGE
1573+
1574+ def __init__ (self , platform , config_entry ):
1575+ super ().__init__ (platform , config_entry )
1576+ """Initialize the sensor."""
1577+
1578+ @property
1579+ def unique_id (self ) -> str :
1580+ return f"{ self ._platform .model } _{ self ._platform .serial } _battery_soc"
1581+
1582+ @property
1583+ def name (self ) -> str :
1584+ return f"{ self ._platform ._device_info ['name' ]} State of Charge"
1585+
1586+ @property
1587+ def native_value (self ):
1588+ if (
1589+ self ._platform .decoded_model ['B_Energy_Available' ]== SUNSPEC_NOT_IMPL_FLOAT32
1590+ or self ._platform .decoded_model ['B_Energy_Available' ] == 0xFF7FFFFF
1591+ or self ._platform .decoded_model ['B_Energy_Available' ] == 0x7F7FFFFF
1592+ or self ._platform .decoded_model ['B_Energy_Max' ]== SUNSPEC_NOT_IMPL_FLOAT32
1593+ or self ._platform .decoded_model ['B_Energy_Max' ] == 0xFF7FFFFF
1594+ or self ._platform .decoded_model ['B_Energy_Max' ] == 0x7F7FFFFF
1595+ ):
1596+ return None
1597+
1598+ else :
1599+ try :
1600+ soc = self ._platform .decoded_model ['B_Energy_Available' ] / self ._platform .decoded_model ['B_Energy_Max' ]
1601+ return round (soc * 100 , 1 )
1602+
1603+ except ZeroDivisionError :
1604+ return None
1605+
15681606class SolarEdgeBatteryStatus (Status ):
15691607 def __init__ (self , platform , config_entry ):
15701608 super ().__init__ (platform , config_entry )
0 commit comments