Skip to content

Commit

Permalink
Added attributes to Inverter Battery SoC sensor
Browse files Browse the repository at this point in the history
  • Loading branch information
faanskit committed Dec 11, 2022
1 parent 28cb200 commit ce0673a
Show file tree
Hide file tree
Showing 3 changed files with 142 additions and 2 deletions.
19 changes: 19 additions & 0 deletions custom_components/saj_esolar_air/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,22 @@
B_DIR_CH = "Charging"
B_DIR_DIS = "Discharging"
B_DIR_STB = "Standby"

B_CAPACITY = "Battery Capacity"
B_CURRENT = "Battery Current"
B_POWER = "Battery Power"

B_GRID_DIRECT = "Grid Direction"
B_IMPORT = "Importing"
B_EXPORT = "Exporting"
G_POWER = "Grid Power"
S_POWER = "Solar Power"
IO_POWER = "Input/Output Power"
IO_DIRECTION = "Output Direction"

PV_POWER = "Photovoltaics Power"
PV_DIRECTION = "Photovoltaics Direction"

B_T_LOAD = "Total Load Power"
B_H_LOAD = "Home Load Power"
B_B_LOAD = "Backup Load Power"
2 changes: 1 addition & 1 deletion custom_components/saj_esolar_air/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"domain": "saj_esolar_air",
"name": "eSolar",
"version": "0.0.6",
"version": "0.0.7",
"config_flow": true,
"issue_tracker": "https://github.com/faanskit/ha-esolar/issues",
"documentation": "https://github.com/faanskit/ha-esolar#readme",
Expand Down
123 changes: 122 additions & 1 deletion custom_components/saj_esolar_air/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,21 @@
B_DIR_CH,
B_DIR_DIS,
B_DIR_STB,
B_CAPACITY,
B_GRID_DIRECT,
B_IMPORT,
B_EXPORT,
B_CURRENT,
B_POWER,
G_POWER,
S_POWER,
IO_POWER,
IO_DIRECTION,
PV_POWER,
PV_DIRECTION,
B_T_LOAD,
B_H_LOAD,
B_B_LOAD,
)

ICON_POWER = "mdi:solar-power"
Expand Down Expand Up @@ -827,7 +842,7 @@ def native_value(self) -> float | None:
self._attr_extra_state_attributes[
B_DIRECTION
] = B_DIR_DIS
elif kit[0]["storeDevicePower"]["batteryDirection"] == -1:
elif kit["storeDevicePower"]["batteryDirection"] == -1:
self._attr_extra_state_attributes[
B_DIRECTION
] = B_DIR_CH
Expand Down Expand Up @@ -1098,6 +1113,20 @@ def __init__(
P_UID: None,
I_MODEL: None,
I_SN: None,
B_CAPACITY: None,
B_CURRENT: None,
B_POWER: None,
B_DIRECTION: None,
G_POWER: None,
B_GRID_DIRECT: None,
IO_POWER: None,
IO_DIRECTION: None,
PV_POWER: None,
PV_DIRECTION: None,
B_T_LOAD: None,
B_H_LOAD: None,
B_B_LOAD: None,
S_POWER: None,
}

async def async_update(self) -> None:
Expand All @@ -1112,6 +1141,9 @@ async def async_update(self) -> None:
if kit["devicesn"] == self.inverter_sn:
self._attr_extra_state_attributes[I_MODEL] = kit["devicetype"]
self._attr_extra_state_attributes[I_SN] = kit["devicesn"]
self._attr_extra_state_attributes[B_CAPACITY] = kit[
"storeDevicePower"
]["batCapcityStr"]

# Setup state
if kit["onLineStr"] == "1":
Expand All @@ -1131,4 +1163,93 @@ def native_value(self) -> float | None:
if kit["onLineStr"] == "1":
value = kit["storeDevicePower"]["batEnergyPercent"]

# Setup dynamic attributes
self._attr_extra_state_attributes[B_CURRENT] = kit[
"storeDevicePower"
]["batCurr"]
self._attr_extra_state_attributes[B_POWER] = kit[
"storeDevicePower"
]["batteryPower"]

if kit["storeDevicePower"]["batteryDirection"] == 0:
self._attr_extra_state_attributes[
B_DIRECTION
] = B_DIR_STB
elif kit["storeDevicePower"]["batteryDirection"] == 1:
self._attr_extra_state_attributes[
B_DIRECTION
] = B_DIR_DIS
elif kit["storeDevicePower"]["batteryDirection"] == -1:
self._attr_extra_state_attributes[
B_DIRECTION
] = B_DIR_CH
else:
self._attr_extra_state_attributes[
B_DIRECTION
] = P_UNKNOWN

self._attr_extra_state_attributes[G_POWER] = kit[
"storeDevicePower"
]["gridPower"]

if kit["storeDevicePower"]["gridDirection"] == 1:
self._attr_extra_state_attributes[
B_GRID_DIRECT
] = B_EXPORT
elif kit["storeDevicePower"]["gridDirection"] == -1:
self._attr_extra_state_attributes[
B_GRID_DIRECT
] = B_IMPORT
else:
self._attr_extra_state_attributes[
B_GRID_DIRECT
] = P_UNKNOWN

self._attr_extra_state_attributes[IO_POWER] = kit[
"storeDevicePower"
]["inputOutputPower"]

if kit["storeDevicePower"]["outPutDirection"] == 1:
self._attr_extra_state_attributes[
IO_DIRECTION
] = B_EXPORT
elif kit["storeDevicePower"]["outPutDirection"] == -1:
self._attr_extra_state_attributes[
IO_DIRECTION
] = B_IMPORT
else:
self._attr_extra_state_attributes[
IO_DIRECTION
] = P_UNKNOWN

self._attr_extra_state_attributes[PV_POWER] = kit[
"storeDevicePower"
]["pvPower"]

if kit["storeDevicePower"]["pvDirection"] == 1:
self._attr_extra_state_attributes[
PV_DIRECTION
] = B_EXPORT
elif kit["storeDevicePower"]["pvDirection"] == -1:
self._attr_extra_state_attributes[
PV_DIRECTION
] = B_IMPORT
else:
self._attr_extra_state_attributes[
PV_DIRECTION
] = P_UNKNOWN

self._attr_extra_state_attributes[B_T_LOAD] = kit[
"storeDevicePower"
]["totalLoadPower"]
self._attr_extra_state_attributes[B_H_LOAD] = kit[
"storeDevicePower"
]["homeLoadPower"]
self._attr_extra_state_attributes[B_B_LOAD] = kit[
"storeDevicePower"
]["backupLoadPower"]
self._attr_extra_state_attributes[S_POWER] = kit[
"storeDevicePower"
]["solarPower"]

return value

0 comments on commit ce0673a

Please sign in to comment.