The grid charges the batteries from 00:00 until 05:00 (on a cheaper night time tarrif). The batteries then discharge this energy into the house during the day.
I have a CT sensor on the grid supply, and a CT sensor on the battery which logs charge and discharge.
The issue is that because the batteries charge from the grid, this is seen as “home” consumption as well as “battery consumption / charge”. When the batteries discharge, this is also seen as a “home” consumption, meaning the energy dashboard is duplicating values and in essence creating free energy. It is showing the house as consuming more than what has been supplied by the grid and the batteries combined.
I think i have this setup correctly, therefore any ideas as to how this can be corrected?
Sounds like you need to create a template sensor that subtracts the battery energy from your grid supplied energy. Then use this new template sensor as your gird energy sensor.
This is a small, off-line UPS in standby mode. The load is powered directly by the grid during normal operation, therefore template sensors are set up so input = output. During a blackout, the input template would change to 0, and output would return actual UPS consumption until battery runs out or grid power is back on.
The bar chart on the top half is correct. The problem is with the flow graph underneath; it doesn’t take into account that the UPS is powered from the grid (white line in the graph), and because of that the home consumption displayed is wrong (it should equal grid usage).
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
So, after a bit of fiddling, I figured out how to simulate a UPS and get it in the energy dashboard. I had to create an input_boolean two input_numbers, two righnmann calculated sensors, two utility_meters, and a couple other calculation sensors to get it to work:
This card allows you to configure the UPS load (I used 300w max as an arbitrary number), the battery percentage, and the state of the input power.
The sensors then calculate how much power is being fed into the battery (charging on line power), how much is coming out (discharging, power outage), how much is passing through, and how much load is on the grid.
Code below:
Regular Dashboard (for configuring the state of the UPS):