Hi Andreas and welcome to the OpenEMS Community,
What you are planning to do is not (yet) legal here in Germany, but you could possibly adapt my prototype developments for upcoming German legislation:
See also my latest Video with Felix Goldbach on EES Europe Exhibition this May in Munich.
In principle if you adapt (and improve) the existing code, you could achieve an optimized energy schedule that predicts your local production and consumption and evaluates when and with how much energy to discharge the battery to the grid.
Regards,
Stefan