muppet3000 / homeassistant-grott

Home Assistant Integration for Grott - MQTT
MIT License
73 stars 17 forks source link

MIN TL-XH inverter format has different keys for battery info #15

Closed shampeon closed 1 year ago

shampeon commented 1 year ago

My MIN-TL-XH inverter uses the T06NNNNXMIN.json format. The keys for the battery information are different between these inverters and e.g. the SPH inverters.

     "bms_status"         : {"value" : 1014,"length" : 2,"type" : "num","divide" : 1},
     "bms_error"          : {"value" : 1018,"length" : 2,"type" : "num","divide" : 1},
     "bms_warninfo"       : {"value" : 1022,"length" : 2,"type" : "num","divide" : 1},
     "bms_soc"            : {"value" : 1026,"length" : 2,"type" : "num","divide" : 1},
     "bms_batteryvolt"    : {"value" : 1030,"length" : 2,"type" : "num","divide" : 100},
     "bms_batterycurr"    : {"value" : 1034,"length" : 2,"type" : "num","divide" : 100},
     "bms_batterytemp"    : {"value" : 1038,"length" : 2,"type" : "num","divide" : 10},
     "bms_maxcurr"        : {"value" : 1042,"length" : 2,"type" : "num","divide" : 100},
     "bms_deltavolt"      : {"value" : 1046,"length" : 2,"type" : "num","divide" : 100},
     "bms_cyclecnt"       : {"value" : 1050,"length" : 2,"type" : "num","divide" : 1},
     "bms_soh"            : {"value" : 1054,"length" : 2,"type" : "num","divide" : 1},
     "bms_constantvolt"   : {"value" : 1058,"length" : 2,"type" : "num","divide" : 100},
     "bms_bms_info"        : {"value" : 1062,"length" : 2,"type" : "num","divide" : 1},
     "bms_packinfo"       : {"value" : 1066,"length" : 2,"type" : "num","divide" : 1},
     "bms_usingcap"       : {"value" : 1070,"length" : 2,"type" : "num","divide" : 1},
     "bms_fw"             : {"value" : 1074,"length" : 2,"type" : "num","divide" : 1},
     "bms_mcuversion"     : {"value" : 1078,"length" : 2,"type" : "num","divide" : 1},
     "bms_commtype"       : {"value" : 1082,"length" : 2,"type" : "num","divide" : 1}

E.g. bms_batteryvolt instead of vbat.

So none of the battery entities are created in HA.

muppet3000 commented 1 year ago

@shampeon thanks for getting in touch, I believe this is a duplicate of #10, however, since we have all of the relevant information here it would be really nice if you could help me out and tell me what the "human name" is for each of these values e.g. I assume bms_batteryvolt is the Battery Voltage, but I can't really guess at some of the others, there's things like bms_soc which is obviously the Statement of charge. If you could give me a human name for each of them I can map them through without too much trouble. Something like this would be good:

shampeon commented 1 year ago

I'm about to head out for a vacation, but I did find this protocol document that appears to have descriptions of these keys. See page 53.

I haven't found a recent copy of "GrowattxxSxx P ESS Protocol" that supposedly has more details, though.

FWIW, here's what I see in Shine:

Screen Shot 2023-06-09 at 3 24 58 PM

And this is from Grott:

         -  bms_status           :  289
         -  bms_error            :  0
         -  bms_warninfo         :  0
         -  bms_soc              :  99
         -  bms_batteryvolt      :  53.2
         -  bms_batterycurr      :  0.0
         -  bms_batterytemp      :  25.1
         -  bms_maxcurr          :  0.0
         -  bms_deltavolt        :  127.5
         -  bms_cyclecnt         :  108
         -  bms_soh              :  99
         -  bms_constantvolt     :  56.8
         -  bms_bms_info         :  0
         -  bms_packinfo         :  3
         -  bms_usingcap         :  0
         -  bms_fw               :  0
         -  bms_mcuversion       :  0
         -  bms_commtype         :  0
muppet3000 commented 1 year ago

Thanks @shampeon that's a great start, I'll try and implement as many of these as possible next week when I'm back at my desk.

muppet3000 commented 1 year ago

@shampeon Please could you try pulling the 'main' version of this integration via HACS and then letting me know if the missing battery values now appear?

shampeon commented 1 year ago

Missing values are there, but the battery voltage is off by 1 decimal place.

Screen Shot 2023-06-20 at 1 56 27 PM

In Grott:

         -  bms_batteryvolt      :  53.1
shampeon commented 1 year ago

I also think this should be "State of Charge":

Screen Shot 2023-06-20 at 1 59 11 PM
muppet3000 commented 1 year ago

You were cutting it fine there, I was literally just about to shut my laptop down for the night.

I've just pushed to main again with a corrections for both of these - can you confirm they're now correct?

muppet3000 commented 1 year ago

I'm now shutting down - looking forward to some feedback on this though.

shampeon commented 1 year ago

Hmm, battery values aren't showing up any longer. Weird.

     - Grott values retrieved:
         -  pvserial             :  BGJ0B1202H
         -  pvstatus             :  1
         -  pvpowerin            :  203.9
         -  pv1voltage           :  0.0
         -  pv1current           :  0.0
         -  pv1watt              :  0.0
         -  pv2voltage           :  61.3
         -  pv2current           :  3.1
         -  pv2watt              :  203.9
         -  pv3voltage           :  0.0
         -  pv3current           :  0.0
         -  pv3watt              :  0.0
         -  pv4voltage           :  0.0
         -  pv4current           :  0.0
         -  pv4watt              :  0.0
         -  pvpowerout           :  157.7
         -  pvfrequentie         :  60.0
         -  pvgridvoltage        :  249.1
         -  pvgridcurrent        :  0.7
         -  pvgridpower          :  157.7
         -  pvgridvoltage2       :  0.0
         -  pvgridcurrent2       :  0.0
         -  pvgridpower2         :  0.0
         -  pvgridvoltage3       :  0.0
         -  pvgridcurrent3       :  0.0
         -  pvgridpower3         :  0.0
         -  vacrs                :  249.1
         -  vacst                :  0.0
         -  vactr                :  0.0
         -  ptousertotal         :  0.0
         -  ptogridtotal         :  3610.0
         -  ptoloadtotal         :  0.0
         -  totworktime          :  11691.2
         -  pvenergytoday        :  0.3
         -  pvenergytotal        :  519.2
         -  epvtotal             :  55.1
         -  epv1today            :  0.0
         -  epv1total            :  0.6
         -  epv2today            :  0.5
         -  epv2total            :  52.9
         -  epv3today            :  0.0
         -  epv3total            :  0.6
         -  etousertoday         :  7.5
         -  etousertotal         :  6797.6
         -  etogridtoday         :  17.3
         -  etogridtotal         :  12423.5
         -  eloadtoday           :  7.5
         -  eloadtotal           :  7262.7
         -  deratingmode         :  14
         -  iso                  :  65530
         -  dcir                 :  0.0
         -  dcis                 :  0.0
         -  dcit                 :  0.0
         -  gfci                 :  0
         -  pvtemperature        :  35.5
         -  pvipmtemperature     :  35.5
         -  temp3                :  33.3
         -  temp4                :  0.0
         -  temp5                :  43.5
         -  pbusvoltage          :  397.2
         -  nbusvoltage          :  0.0
         -  ipf                  :  20000
         -  realoppercent        :  1
         -  opfullwatt           :  0.0
         -  standbyflag          :  0
         -  faultcode            :  0
         -  warningcode          :  309
         -  systemfaultword0     :  0
         -  systemfaultword1     :  0
         -  systemfaultword2     :  0
         -  systemfaultword3     :  0
         -  systemfaultword4     :  0
         -  systemfaultword5     :  2
         -  systemfaultword6     :  1130
         -  systemfaultword7     :  0
         -  invstartdelaytime    :  300
         -  bdconoffstate        :  1
         -  drycontactstate      :  0
         -  edischrtoday         :  0.3
         -  edischrtotal         :  587.5
         -  echrtoday            :  0.2
         -  echrtotal            :  939.7
         -  eacchrtoday          :  0.2
         -  eacchrtotal          :  1192.4
         -  priority             :  1
         -  epsfac               :  60.0
         -  epsvac1              :  249.1
         -  epsiac1              :  0.0
         -  epspac1              :  0.0
         -  epsvac2              :  0.0
         -  epsiac2              :  0.0
         -  epspac2              :  0.0
         -  epsvac3              :  0.0
         -  epsiac3              :  0.0
         -  epspac3              :  0.0
         -  epspac               :  0.0
         -  loadpercent          :  0.0
         -  pf                   :  1000.0
         -  dcv                  :  0
         -  bdc1_sysstatemode    :  513
         -  bdc1_faultcode       :  0
         -  bdc1_warncode        :  0
         -  bdc1_vbat            :  53.2
         -  bdc1_ibat            :  0.0
         -  bdc1_soc             :  94
         -  bdc1_vbus1           :  390.5
         -  bdc1_vbus2           :  317.6
         -  bdc1_ibb             :  0.0
         -  bdc1_illc            :  0.0
         -  bdc1_tempa           :  32.6
         -  bdc1_tempb           :  33.4
         -  bdc1_pdischr         :  0.6
         -  bdc1_pchr            :  0.0
         -  bdc1_edischrtotal    :  587.5
         -  bdc1_echrtotal       :  939.7
         -  bdc1_flag            :  3
         -  bdc2_sysstatemode    :  30
         -  bdc2_faultcode       :  5
         -  bdc2_warncode        :  206
         -  bdc2_vbat            :  2.3
         -  bdc2_ibat            :  19.6
         -  bdc2_soc             :  1
         -  bdc2_vbus1           :  0.4
         -  bdc2_vbus2           :  9.7
         -  bdc2_ibb             :  9.4
         -  bdc2_illc            :  0.3
         -  bdc2_tempa           :  0.0
         -  bdc2_tempb           :  1668.0
         -  bdc2_pdischr         :  105512960.0
         -  bdc2_pchr            :  0.0
         -  bdc2_edischrtotal    :  0.0
         -  bdc2_echrtotal       :  0.0
         -  bdc2_flag            :  0
         -  bms_status           :  289
         -  bms_error            :  0
         -  bms_warninfo         :  0
         -  bms_soc              :  94
         -  bms_batteryvolt      :  53.1
         -  bms_batterycurr      :  0.0
         -  bms_batterytemp      :  23.1
         -  bms_maxcurr          :  0.0
         -  bms_deltavolt        :  127.5
         -  bms_cyclecnt         :  109
         -  bms_soh              :  99
         -  bms_constantvolt     :  56.8
         -  bms_bms_info         :  0
         -  bms_packinfo         :  3
         -  bms_usingcap         :  0
         -  bms_fw               :  0
         -  bms_mcuversion       :  0
         -  bms_commtype         :  0
Screen Shot 2023-06-20 at 2 20 35 PM
shampeon commented 1 year ago

I'm going to remove/redownload once more to make sure. We can deal with this in the (UK) AM, though. Muchos gracias for your hard work here.

muppet3000 commented 1 year ago

Ok, let me know if you have the same issue tomorrow and I'll take another look. Maybe take a look in the HA logs as well, I maybe have made a typo that's causing it to throw an error, but that wouldn't make any sense, all the sensors would fail to update if that was the case. Make sure you're choosing to use the main branch/release in HACS, not the 1.0.1 release.

I'll assist further tomorrow if needed.

shampeon commented 1 year ago

Ok, I think I can reproduce the bug that's causing the battery entities to not show up.

When you initially configure the integration, it doesn't respect the option to "Calculate additional values from raw MQTT values".

To reproduce:

  1. In the Integrations panel click Add Integration.
  2. Search for "Grott" then click the Grott integration.
  3. In the configure pane, leave the Device ID blank but check "Calculate additional values from raw MQTT values".
  4. Click Submit.
  5. After the integration is added successfully, click Configure. Note that "Calculate additional values from raw MQTT values" is now unchecked.

I had to go back to Configure and check the box again before the entities were populated in order to get all 53 entities to show up. Otherwise it wouldn't detect the battery sensors, and I'd have 45 entities.

Screen Shot 2023-06-20 at 4 05 29 PM
muppet3000 commented 1 year ago

Well that's a whole load of weird! Especially since the calculation of additional values has nothing to do with the battery values (unless I've made some really odd mistake). I'll check through the code today and see what's happening. Could it be that some MQTT messages don't provide the battery data? i.e. one MQTT message just has the PV data and then another comes along later with the battery data? That could explain the difference.

As for the configuration box not being consistent - I'll need to take a look at that, that's a separate bug in it's own right.

Now that you have the battery values showing, are you able to confirm that they are correct?

muppet3000 commented 1 year ago

I've gone back and checked the code/logic.

The only thing I can think to confirm the above suggestion is to restart HA or remove/re-add the integration. Then leave it for a while, see if the integration eventually discovers the values. There's absolutely no reason for these values not to appear based on this config check box (which I appreciate needs fixing, but isn't related to this problem).

If the values are there on MQTT then they should appear in HA.

shampeon commented 1 year ago

Hmm, yeah that is weird. I had let it sit for a while (15 minutes?), and Grott was refreshing values in MQTT, which were showing up in HA. But no battery entities.

Just double checked. Everything is correct except:

-  bms_batterycurr      :  654.6

It's showing up as 6,546.6 A in HA.

But even the raw value is weird. I'm not pushing anywhere near hundreds of amps from the battery. It's sitting idle. Not relevant to this issue, though.

Screen Shot 2023-06-21 at 7 56 53 AM
muppet3000 commented 1 year ago

That's odd, I can't explain that delay for the sensors at all, other than the values being pushed at different rates to MQTT. Very odd behaviour!

I've just pushed a commit to main for the Current value, hopefully that should show the correct value now. Could you confirm when you get the chance?

shampeon commented 1 year ago

Confirmed.

LMK if you want to screenshare so you can see the behavior live.

muppet3000 commented 1 year ago

Thanks for the confirmation.

At least the sensor is now working just not as often as it should.

Would you mind opening a new big so that we can focus on that problem separately?

Copy all the details from above on how to reproduce it and I'll think about how we can debug it. Maybe just some aggressive logging could help in the first instance.

I'll close this bug when I do a release that contains the fix (hopefully over the weekend).

shampeon commented 1 year ago

Opened #17.

muppet3000 commented 1 year ago

Thanks @shampeon - So to be clear there are no issues with the new battery values any more, they persist between reboots etc and are updated. In testing though you discovered the other issue with the lack of persistent configuration for the calculated values?

shampeon commented 1 year ago

That's correct. Once the entities populate, they appear to persist across reboots, and as I found today, across HA upgrades.

muppet3000 commented 1 year ago

Released in v1.1.0