Absolute value of sensor in helper?

I’d love it if someone could help me with a helper entity.

I would like to have to absolute value of a sensor so that the math represents reality.

My use case is I have a Shelly 3EM Pro with 3 current sensors on my main grid service and my solar inverters.

The issue is that when the inverters produce power, it is a positive value, which adds up nicely with Grid net power because they cancel each other out, leaving the house usage in the middle.

However, when the batteries charge from the grid, the inverter power is negative and the grid power is positive, so their sum makes the house look like it’s using less, when it’s actually using more.

Either being able to use subtraction in a helper or the absolute value of the sensor would help… are there ways to do this?

Thanks

Create a Template Sensor helper and use the abs filter in its template to get the absolute value of the power sensor.

For example of the power sensor is sensor.foo then the Template Sensor’s template will be:

{{ states('sensor.foo') | float(0) | abs }}