Look up your inverter brand and pray there is an integration for it. Also: try to make your electrical meter smart to be able to tell the difference between pulling from grid and delivering to grid. If you already have a smart meter, see if it exposes some interface (like P1 with the DSMR protocol for example) to easily integrate the meter into home assistant.
I have done all this with a goodwe inverter and a kamstrup meter P1 port using a DSMR dongle.
If you need any pointers, dm me.