Control current DPM8624 depending on mains supply

Actually a simple task but I do not know how to implement it. Maybe you have some tips for me. I would like to control the current of the DPM824 (0…24A) depending on the mains supply, which should be as close to zero watts as possible. So if there is surplus from the PV system is fed into the grid. I would like to use this surplus to fill my battery (LiFePO4) via AC charging. A PID controller is probably not to use in this place? I work with Home Assistant and have all the necessary values available. So consumption of the house, PV power, surplus and access via RS485 and D1 mini (ESPHome) to the DPM8624.
I know this actually belongs in the Node Red forum. Unfortunately, I don’t get an answer there for almost two weeks. Maybe it works here :wink:
I use node red as an addon of Home Assistant.