Growatt Inverter Faultcode in ESPhome

Hi there! I’m trying to implement a piece of diagnostics from my inverter into HA. I checked the Growatt Inverter Modbus RTU Protocol_II manual and I implemented this piece of code:

- platform: modbus_controller
  name: "Fault code"
  id: raw_fault_code
  address: 105
  register_type: "read"
  state_class: measurement     
  entity_category: diagnostic
  icon: mdi:eye
  value_type: U_WORD

text_sensor:
  - platform: template
    name: "Fault Code Description"
    entity_category: diagnostic
    icon: mdi:alert
    lambda: |-
      switch ((int)id(raw_fault_code).state) {
        case 0:
          return {"No Error"};
        case 1 ... 23:
          return {"Error: 99+x"};
        case 24:
          return {"Auto Test Failed"};
        case 25:
          return {"No AC Connection"};
        case 26:
          return {"PV Isolation Low"};
        case 27:
          return {"Residual I High"};
        case 28:
          return {"Output High DCI"};
        case 29:
          return {"PV Voltage High"};
        case 30:
          return {"AC V Outrange"};
        case 31:
          return {"AC F Outrange"};
        case 32:
          return {"Module Hot"};
        default:
          return {"Unknown Error"};
      }

However the register returns a whole different number, for instance “203”. Which corresponds more with Growatt inverter error codes + troubleshooting tips . How do I import the right fault codes and corresponding message?

I dont have this nor do I know what im talking about.
Whats your baud rate? Why not include all of the errors? Does your growatt controller have a display?

For readability I only posted a snippet of my code.
To elaborate more:
In the manual (https://www.photovoltaicsolar.in/Growatt_Manual/MAX%20Series%20Modbus%20RTU%20Protocol.pdf) on page 48 it shows a list of fault types and corresponding messaging. It refers to page 28 which states the adress: 105. However when I read the input register (ie 105) it gives me a different number than the ones corresponding on page 48.

Given there is 32 error codes it’s probably bitwise…
Looking at registers, get the 106 and 107 … as a u-dword and then convert to binary and then if that bit is high then it will be that error.

Make few known faults like “no AC connected” and check what’s the code reg 105 gives out.
It shouldn’t be hard to map them when you have few known codes.

Not getting any results from register 106 and 107. From 105 I get the 203 Error code, which corresponds with de pv isolation error I get. Turning of the AC gets me the 304 error code which seems to be correct. I have now the codes from the website in the config:

text_sensor:
  - platform: template
    name: "Fault Code Description"
    entity_category: diagnostic
    icon: mdi:alert
    lambda: |-
      switch ((int)id(raw_fault_code).state) {
        case 0:
          return {"No Error"};
        case 101:
          return {"Communication fault"};
        case 102:
          return {"Consistent fault. Data received by master and slave processors are different."};
        case 116:
          return {"EEPROM Fault"};
        case 117:
          return {"Relay fault"};
        case 118:
          return {"Init model fault"};
        case 119:
          return {"GCFI device damage"};
        case 120:
          return {"HCT Fault"};
        case 121:
          return {"Communication fault, the master processor can’t receive data from the slave processor"};
        case 122:
          return {"Growatt bus voltage too high"};
        case 201:
          return {"Residual I High Error: Leakage current too high"};
        case 202:
          return {"PV Voltage High Error: The DC input voltage exceeds the maximum tolerable value."};
        case 203:
          return {"PV Isolation Low Error: Insulation problem"};
        case 204:
          return {"Warning 204: Dry connect function abnormal"};
        case 205:
          return {"Warning 205: PV1 or PV2 boost broken"};
        case 207:
          return {"Warning 207: USB over-current"};
        case 300:
          return {"AC V Outrange Error: Refers to error 300 AC V outrange."};
        case 302:
          return {"No AC connection Error"};
        case 303:
          return {"PE abnormal Error: Voltage of Neutral and PE above 30V"};
        case 304:
          return {"AC F Outrange Error: Utility grid frequency out of permissible range."};
        case 401:
          return {"Warning 401: Inverter communicates with Meter abnormal"};
        case 402:
          return {"Error: Output High DCI"};
        case 404:
          return {"Warning 404: EEPROM abnormal"};
        case 405:
          return {"Error: Relay fault"};
        case 407:
          return {"Auto Test Failed Error: The auto test didn’t pass."};
        case 408:
          return {"Error: Over Temperature"};
        case 409:
          return {"Error: Bus over voltage"};
        case 411:
          return {"Error: DSP communicates with M3 abnormal"};
        case 414:
          return {"Error: EEPROM fault"};
        case 417:
          return {"Error: The data sampled by the DSP and redundant M3 is not the same"};
        case 420:
          return {"Error: GFCI fault"};
        default:
          return {"Unknown Error"};
      }

I have Sofar inverter and the fault codes were different from what protocol sheet states as well…