Energy card - production and consumption with 1h balancing

Hi,
My power provider has to balancing my consumption and PV production (network export) within 1h. It has to be done like: energy_pv - energy_consumption if “+” then network exported (production), if “-” network imported (consumption).
I have Fronius inverter with consumption metter (S0), I have integrated it by HACS Fronius_inverter integration because there I’m able to have 5s sampels.
So my config looks like:

template:
    sensor:
    - name: "power consumption"
      unique_id: "sensor.power_consumption"
      icon: "mdi:flash"
      unit_of_measurement: "W"
      state: >
        {% set P = states('sensor.fronius_house_load') | float(0) | abs  | round(2) %}
        {{ P }}
    - name: "1h_balance"
      unique_id: "sensor.1h_balance"
      icon: "mdi:power-plug-outline"
      availability: "{{ is_numeric(states('sensor.fronius_house_load')) }}"
      unit_of_measurement: "kWh"
      state: >
        {% set production= states('sensor.1h_production') | float(0) %}
        {% set consumption = states('sensor.1h_consumption') | float(0) %}
        {{ ((production- consumption ) | float) | round(2, default=0) }}

sensor:
  - platform: fronius_inverter
    ip_address: 192.168.0.165
    scan_interval: 5
    powerflow: True
    power_units: W
    units: kWh
  - platform: integration
    source: sensor.power_consumption
    name: energy_consumption
    unit_prefix: k
    round: 3

utility_meter:
  1h_production:
    source: sensor.fronius_day_energy
    cycle: hourly
  1h_consumption:
    source: sensor.energy_consumption
    cycle: hourly

So everything almost fine but how to present that data (1h_balance) in energy card as a imported or exported energy ?
The problem is that 1h_balance every hour need to start from “0”, so it need next sensor which need to sumarize max value (when 1h_balacne > 0) for exported energy and sumarize min value (when 1h_balance < 0) for imported energy. Can somebody help me how to make in HA ?