Calculations in home assistant or node red

I am working on a project in home assisant
i can’t figure it out i have a node red flow that reads the values of the p1 meter and sends an eboiler to regulate at production and at consumption back tiling a weight in node red switches depending on the quantity the output and controls so modulating the consumption of that boiler to keep the meter at zero this works

now that we are still allowed to balance and possibly in the future to dynamic tariffs I want to control this with the flow but I want to be able to set a value with a set value or on automatic but first hand my thoughts are

if I want to feed back 1 kw and the consumption is 0 and production is 0
and I add 1 to consumption the flow thinks that 1 kw is used and controls the flow when I add the kw to production it controls the flow
so I see it for me to regulate the flow

that calculation I made with helpers input works but with grid sensor result unknown
in node red it does not work either has anyone an idea to get this working
greetings jurgen

Post the flow that you want to modify.