Problems with Shelly Pro 3EM summarizing and Energy dashboard

I have a balcony power station with a maximum output of 630W. I measure this with a Shelly PM Mini (sensor.solar_production_power and sensor.solar_production_energy). I also have a Shelly Pro 3EM in the fuse box that measures all three phases of the whole appartment. I have no way of measuring this with the smart electricity meter because it is several floors down in the basement.

I’m having trouble getting meaningful values with the energy dashboard built into HA. I think it’s because the Shelly Pro 3EM already offsets the draw from the grid and the feed-in (total_active_power) and I don’t really understand how to get the correct values from it.

I am trying to find out whether it is worth buying a battery and temporarily storing the electricity that I produce and am currently giving away to the grid operator. To do this, the “given away” surplus energy must not be offset against the grid consumption because I have to pay for the grid consumption in full and receive no money for the feed-in above what I consume from my solar production.

What I have done so far:

  • Created a template sensor sensor.grid_consumption_power, which sets the negative values of total_active_power to zero.
  • Created an integral sensor that calculates the energy for sensor.grid_consumption_power: sensor.grid_consumption_energy
  • Created a template sensor sensor.grid_feed_in_power that sets the positive values of total_active_power to zero and calculates the absolute value from the result. This is what I give away
  • Created an integral sensor that calculates the energy for sensor.grid_feed_in_power: sensor.grid_feed_in_energy
  • Created a template sensor sensor.solar_consumption_power that calculates the difference between sensor.solar_production_power and sensor.grid_feed_in_power
  • Created an integral sensor that calculates the energy for sensor.solar_consumption_power: sensor.solar_consumption_energy

I used this to create a dashboard that allows me to see how much energy I am “giving away” and what proportion of the grid supply I could cover with the surplus if I used a battery.

Problem 1:
Actually, all of this should also be possible with the HA energy dashboard. However, I don’t know how to do this with the Shellys I own. Can anyone here help?

Problem 2:
The sum of the energy calculated using integral sensors for self-consumption and surplus fed into the grid is approx. 10% less than the solar energy produced as measured in the Shelly PM Mini. Is this a known behaviour of the integral sensor? I have set the precision to two and the max sub-interval to one minute. I use the left Riemann sum.

Any help is appreciated.