Energy custom sensor

Hi everyone, I need help to properly configure the Energy dashboard. At the moment the hardware is very simple, there is a shelly em that has 2 channels, one on the total consumption and one on the total production. Configured in this way, however, I am not able to manage the return to the grid, simply because I know how much I produce and I know how much I consume but since the energy dashboard works on the totals it is difficult for me to isolate the data of solar energy consumed and re-introduced. i was trying to create a custom sensor, but i can’t figure it out.
Obviously for custom dashboards I have no problems because there I work with immediate consumption and not with totals, but I would also like to have the energy dashboard well instrumented and with the correct data.