Convert an bidirectional energy meter to two cumulating ( import / export )

I have an energy meter in the grid path that measures the usual stuf (current, voltage, power) and also integrates the power to an energy meter. By design this meter work bidirectional (net meter).

But the energy dashboard insists of having two separate meters for grid consumption and return.
I did not manage to find an easy way using template sensors to convert this meter to two meter without negative values.

I managed to split the power and then use the HA integration helper to have these two virtual meters calculated. But these integration meter differ ~ 10% from the “built in” energy counter of the meter and sometimes some spikes produce false values that I then have to correct manually in the statistics. So I don’t want to use the integration helper of HA anymore and just split the energy meter values I already accurately receive.

Any solution on this? Because i have the same problem. Net Value is wrong calculated.

Sascha

Yes, but I don’t like it very much.

My input value that goes both ways is e3dcfs_grid_energy

I have created 2 Helper / Input Numbers:

  • e3dcfs_grid_energy_import
  • e3dcfs_grid_energy_export

like this

I have created 2 automations. In yaml:

- id: '1676582846413'
  alias: e3dcfs_grid_energy_goes_higher
  description: ''
  trigger:
  - platform: state
    entity_id:
    - sensor.e3dcfs_grid_energy
  condition:
  - condition: template
    value_template: '{{ states(''sensor.e3dcfs_grid_energy'') not in [''unavailable'',
      ''unknown'', ''none''] }}'
  - condition: template
    value_template: '{{ (trigger.to_state.state | float) > (trigger.from_state.state
      | float) }}'
  action:
  - service: input_number.set_value
    data:
      value: '{{ (states.input_number.e3dcfs_grid_energy_import.state | round(3))
        + (trigger.to_state.state | round(3)) - (trigger.from_state.state | round(3))
        }}'
    target:
      entity_id: input_number.e3dcfs_grid_energy_import
  mode: single
- id: '1676583393733'
  alias: e3dcfs_grid_energy_goes_lower
  description: ''
  trigger:
  - platform: state
    entity_id:
    - sensor.e3dcfs_grid_energy
  condition:
  - condition: template
    value_template: '{{ states(''sensor.e3dcfs_grid_energy'') not in [''unavailable'',
      ''unknown'', ''none''] }}'
  - condition: template
    value_template: '{{ (trigger.to_state.state | float) < (trigger.from_state.state
      | float) }}'
  action:
  - service: input_number.set_value
    data:
      value: '{{ (states.input_number.e3dcfs_grid_energy_export.state | round(3))
        + (trigger.from_state.state | round(3)) - (trigger.to_state.state | round(3))
        }}'
    target:
      entity_id: input_number.e3dcfs_grid_energy_export
  mode: single

I created also 2 utlity meters in configuration yaml:

utility_meter:
  e3dcfs_grid_energy_import_daily:
    unique_id: e3dcfs_grid_energy_import_daily
    net_consumption: true
    source: input_number.e3dcfs_grid_energy_import
    cycle: daily
  e3dcfs_grid_energy_export_daily:
    unique_id: e3dcfs_grid_energy_export_daily
    net_consumption: true
    source: input_number.e3dcfs_grid_energy_export
    cycle: daily

These two are then used in the energy dashboard for grid consumption and return to grid.