Energy dashboard with battery storage - doubled and duplicated consumption

Hi,

I have the following setup:

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?

Thanks.

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.

Thanks, this will would until I introduce solar, which can either power the house or change the batteries (to be discharged later).

I think the same scenario would occur in this instance?

Not sure. You could ask in the HA Discord energy channel https://discord.gg/p3ed4aAv

I’m still having the same issue with a simpler setup.

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’m running into this myself, any solution yet?

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??

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):

cards:
  - type: entities
    entities:
      - entity: input_boolean.sim_ups_battery_charging
      - entity: sensor.sim_ups_battery_charging_power
      - entity: sensor.sim_ups_battery_discharging_power
      - entity: input_number.battery_test_load
      - entity: sensor.sim_ups_input_power
      - entity: input_number.battery_test_charge
      - entity: sensor.simulated_ups_charging
      - entity: sensor.simulated_ups_discharging
      - entity: sensor.sim_ups_battery_discharging_power_kwh
      - entity: sensor.sim_ups_battery_charging_power_kwh
    title: UPS Battery Simulation

utility_meter.yaml

ups_simulator_charging:
    source: sensor.sim_ups_battery_charging_power_kwh
    cycle: monthly
    name: Simulated UPS Charging
ups_simulator_discharging:
    source: sensor.sim_ups_battery_discharging_power_kwh
    cycle: monthly
    name: Simulated UPS Discharging

sensor.yaml

- platform: template
  sensors:
    sim_ups_battery_charging_power:
      friendly_name: "Sim UPS Battery Charging Power"
      value_template: >-
        {% if (states('input_boolean.sim_ups_battery_charging') == 'on') and ((states('input_number.battery_test_charge') | float) < 100.00) %}
          {{ (100.00) }}
          {% else %}
          {{ (0.00) }}
        {% endif %}
      unit_of_measurement: 'W'
      device_class: energy
    sim_ups_battery_discharging_power:
      friendly_name: "Sim UPS Battery Discharging Power"
      value_template: >-
        {% if states('input_boolean.sim_ups_battery_charging') == 'on' %}
          {{ (0.00) }}
          {% else %}
          {{ ((states('input_number.battery_test_load') | float) + 15.00) }}
        {% endif %}
      unit_of_measurement: 'W'
      device_class: energy
    sim_ups_input_power:
      friendly_name: "Sim UPS Input Power"
      value_template: >-
        {% if (states('input_boolean.sim_ups_battery_charging') == 'on') %}
          {% if ((states('input_number.battery_test_charge') | float) < 100.00) %}
            {{ (115.00) + (states('input_number.battery_test_load') | float) }}
            {% else %}
            {{ ((15.00) + (states('input_number.battery_test_load') | float)) }}
          {% endif %}
          {% else %}
          {{ (0.00) }}
        {% endif %}
      unit_of_measurement: 'W'
      device_class: energy

I’m using the following rest sensor:

 - platform: rest
   resource: https://globalapi.solarmanpv.com/device/v1.0/currentData?appId=xxxxxx&language=en&=
   method: POST
   name: "Total Charging Energy kWh"
   scan_interval: 3600
   headers:
    Authorization: bearer xxxxxxx
    Content-Type: application/json
   payload: '{  "deviceSn": "xxxxxx"}'
   value_template: "{{ value_json.dataList[42].value }}"
   unit_of_measurement: "kWh"
   device_class: energy
   state_class: total_increasing

But I’m not able to use it in the energy dashboard (does not appear in the list). Does anyone have a clue ?

Kr,

Bart

A bit late, but I just had the same problem and found the solution.

I have created the sensor with a wrong unit and then changed the unit. As a result the database had entries with different units.

Must be fixed in Developer Tools / Statistics

Hello,

I have the same issue with the energy dashboard and want to let you know, that I just created a feature request, see here.

I would appreciate, if you would vote for it :slight_smile:

Thx, nob