How to process grid, inverter and BMS?

I have a PZEM-004+NodeMCU monitoring the overall house consumption, this works fine. I recently installed an inverter (MPP Solar) through which the house will run. There are some solar panels and a battery with it’s own BMS (JK-BMS).

For MPP Solar I fixed and installed the ESPHome integration, I get real-time wattage but no long-term data. I assume this is needed for “Energy” integration.

For the BMS I did not manage to find a cable yet, but it will also get an ESPHome treatment. It has a running total for amp-hours but not sure how to directly convert that to Wh.

I could perhaps buy another PZEM unit and integrate that but I would basically need to monitor 4 values: PV voltage (0-400V), PV current (0-18A), Battery voltage (30-50V) and current (0-150A). Not sure what my options are.

On top of the above, the inverter is using about 30-60W on its own, this will need to be subtracted/added somehow.

Ok, actually I found out that the default Energy integration does a pretty good job.
I created some helpers:

  • battery_charge_power = inverter0_battery_voltage * inverter0_battery_charging_current
  • battery_charge_power_total - Riemann sum of the above
  • similar for battery_discharge_power
  • pv_output_kwh - Riemann sum of the inverter0_pv_charging_power
  • pv_output_kwh_total - utility meter of the above (does not work)

I manually edited the states of the above to convert them to device_class: energy and state_class: total. They probably won’t survive a HA restart so I probably need to follow this post How to edit a "Riemann sum integral" helper - #6 by worker72

At least I got some things to show up, will need to wait and see if it works as intended.