Skip to content

Commit

Permalink
Merge pull request #622 from canton7/bugfix/h3-pro-fixes
Browse files Browse the repository at this point in the history
Update inv_power scale and battery_discharge_2 register order
  • Loading branch information
canton7 authored May 29, 2024
2 parents 1a93701 + c7f21ad commit 99da96d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
13 changes: 10 additions & 3 deletions custom_components/foxess_modbus/entities/entity_descriptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,7 @@ def _inv_current_set(
scale=0.001,
)

def _inv_power(phase: str | None, addresses: list[ModbusAddressesSpec]) -> EntityFactory:
def _inv_power(phase: str | None, addresses: list[ModbusAddressesSpec], scale: float) -> EntityFactory:
key_suffix = f"_{phase}" if phase is not None else ""
name_suffix = f" {phase}" if phase is not None else ""
return ModbusSensorDescription(
Expand All @@ -759,7 +759,7 @@ def _inv_power(phase: str | None, addresses: list[ModbusAddressesSpec]) -> Entit
device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement="kW",
scale=0.001,
scale=scale,
round_to=0.01,
validate=[Range(-100, 100)],
)
Expand All @@ -769,27 +769,32 @@ def _inv_power(phase: str | None, addresses: list[ModbusAddressesSpec]) -> Entit
addresses=[
ModbusAddressesSpec(holding=[39135, 39134], models=Inv.H3_PRO),
],
# This one appears to be in mW, despite what the spec says
scale=0.000001,
)
yield _inv_power(
"R",
addresses=[
ModbusAddressesSpec(holding=[31012], models=Inv.H3_SET),
ModbusAddressesSpec(holding=[39249, 39248], models=Inv.H3_PRO),
],
scale=0.001,
)
yield _inv_power(
"S",
addresses=[
ModbusAddressesSpec(holding=[31013], models=Inv.H3_SET),
ModbusAddressesSpec(holding=[39251, 39250], models=Inv.H3_PRO),
],
scale=0.001,
)
yield _inv_power(
"T",
addresses=[
ModbusAddressesSpec(holding=[31014], models=Inv.H3_SET),
ModbusAddressesSpec(holding=[39253, 39252], models=Inv.H3_PRO),
],
scale=0.001,
)

def _inv_power_reactive(phase: str | None, addresses: list[ModbusAddressesSpec]) -> EntityFactory:
Expand Down Expand Up @@ -1190,7 +1195,9 @@ def _invbatpower(index: int | None, addresses: list[ModbusAddressesSpec]) -> Ite
yield from _invbatpower(
index=2,
addresses=[
ModbusAddressesSpec(holding=[39236, 39235], models=Inv.H3_PRO),
# It does genuinely look like these two are the wrong way around, see
# https://github.com/nathanmarlor/foxess_modbus/discussions/516#discussioncomment-9569558
ModbusAddressesSpec(holding=[39235, 39236], models=Inv.H3_PRO),
],
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@
{
"addresses": {
"holding": [
39236,
39235
39235,
39236
]
},
"key": "battery_charge_2",
Expand Down Expand Up @@ -117,8 +117,8 @@
{
"addresses": {
"holding": [
39236,
39235
39235,
39236
]
},
"key": "battery_discharge_2",
Expand Down Expand Up @@ -829,7 +829,7 @@
},
"key": "inv_power",
"name": "Inverter Power",
"scale": 0.001,
"scale": 1e-06,
"signed": true,
"type": "sensor"
},
Expand Down Expand Up @@ -979,8 +979,8 @@
{
"addresses": {
"holding": [
39236,
39235
39235,
39236
]
},
"key": "invbatpower_2",
Expand Down

0 comments on commit 99da96d

Please sign in to comment.