Energy dashboard with battery storage - doubled and duplicated consumption

I think I have a solution… Right now I have a UPS but I don’t have real sensors, so I’m using PowerCalc (HACS integration) to simulate the power usage.

The dashboard has the following logic…
Input to UPS is counted as a negative value, for charging the battery (why, I don’t know, since the battery is connected to the grid for input).
Output from UPS is counted a positive value, for discharging the battery.

In addition to the white line issue (aka no power draw listed for the grid), another problem is, we are tracking the power consumption at the input of the UPS, and at the output (the load percentage). This is the total throughput. The problem is, HA counts these two values as charging/discharging.

To get the data HA is seeking (and thus give you the right numbers), create a sensor that has the following output:

battery_power = (input - (load + idle power))

Since the above equation will give us a negative number when on battery (input will be 0), we need to create two sensors that HA can use:

if on battery: 
    input_sensor = 0
    output_sensor = abs(battery_power)   # abs function corrects the negative value

If on line:
    input_sensor = battery_power
    output_sensor = 0

Now, to write this in yaml…

Edit:
How did he get that working??