Skip to content

Commit

Permalink
Merge pull request #1095 from TonyMathiesen/Fix-inverter-state-run-mode
Browse files Browse the repository at this point in the history
Growatt: Fix run mode #791
  • Loading branch information
wills106 authored Oct 21, 2024
2 parents de5b7df + 5a3bf73 commit 8aeb9e0
Showing 1 changed file with 44 additions and 18 deletions.
62 changes: 44 additions & 18 deletions custom_components/solax_modbus/plugin_growatt.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,29 @@ def value_function_today_s_solar_energy(initval, descr, datadict):
def value_function_combined_battery_power(initval, descr, datadict):
return datadict.get('battery_charge_power', 0) - datadict.get('battery_discharge_power',0)

def value_function_inverter_state(initval, descr, datadict):
inverter_state = datadict.get('register_3000', 0)
inverter_state = inverter_state >> 8 # Remove the lower 8 bits by right-shifting by 8 bits
status_dict = {
0: "Waiting",
3: "Fault",
4: "Flash",
5: "PV Bat Online",
6: "Bat Online"
}
return status_dict.get(inverter_state)

def value_function_run_mode(initval, descr, datadict):
run_mode = datadict.get('register_3000', 0)
run_mode = run_mode & 0xFF # Mask out the upper 8 bits, keeping only the lower 8 bits
run_mode_dict = {
0: "Standby",
1: "Normal",
3: "Fault",
4: "Flash"
}
return run_mode_dict.get(run_mode)

# ================================= Button Declarations ============================================================

BUTTON_TYPES = [
Expand Down Expand Up @@ -3840,24 +3863,27 @@ def value_function_combined_battery_power(initval, descr, datadict):
# TL-X TL-XH
#
#####
# GrowattModbusSensorEntityDescription(
# name = "Inverter State",
# key = "inverter_state",
# register = 3000,
# register_type = REG_INPUT,
# unit = REGISTER_U8H, #currently not working in the integration
# scale = { 0: "Waiting", 3: "Fault", 4: "Flash", 5: "PV Bat Online", 6: "Bat Online", },
# allowedtypes = GEN4,
# ),
# GrowattModbusSensorEntityDescription(
# name = "Run Mode",
# key = "run_mode",
# register = 3000,
# register_type = REG_INPUT,
# unit = REGISTER_U8L, #currently not working in the integration
# scale = { 0: "Standby", 1: "Normal", 3: "Fault", 4: "Flash", },
# allowedtypes = GEN4,
# ),
GrowattModbusSensorEntityDescription(
key = "register_3000",
register = 3000,
register_type = REG_INPUT,
allowedtypes = GEN4,
internal = True,
),
GrowattModbusSensorEntityDescription(
name = "Inverter State",
key = "inverter_state",
value_function = value_function_inverter_state,
allowedtypes = GEN4,
entity_category = EntityCategory.DIAGNOSTIC,
),
GrowattModbusSensorEntityDescription(
name = "Run Mode",
key = "run_mode",
value_function = value_function_run_mode,
allowedtypes = GEN4,
entity_category = EntityCategory.DIAGNOSTIC,
),
GrowattModbusSensorEntityDescription(
name = "Total PV Power",
key = "total_pv_power",
Expand Down

0 comments on commit 8aeb9e0

Please sign in to comment.