 # Splitting Algebraic Energy to production and consumption

I have a Aeotec Home Energy Meter ZW095 Which measures my energy consumption. I also have a grid tied solar panel inyecting current to the house. The meter has 4 modes of operation:

``````Value	Description
0	Energy absolute value
1	Algebraic sum energy
2	Consuming electricity
3	Generating electricity
``````

I set it to (1) Algebraic sum energy. Which is the only one that shows positive and negative power(W) values (negative when it is injecting energy to the grid). The energy as stated is being calculated using an algebraic sum. This means that the total energy can increase or decrease depending of your energy production and consumption.

Home Assistant on the other hand expect two different entities (both of them positive). One for Total consumption, and one for total production.

My question is: Is there an easy way of calculating the production and consumption entities based on wether the algebraic energy is increasing or decreasing. In Other words if the meter energy goes from 102.31 kWh to 102.33 then Consumption should increase by 0.02. But if energy goes from 102.31 to 102.30 then Production should increase by 0.01.