Daily totals from forward and reverse active energy in platform atm90e32 [SOLVED]

The forward and reverse active energy entities created in platform atm90e32 are internally reset every fifteen minutes.
As a result the Utility Meter cannot be used to generate a resettable daily total. A template sensor can be used to manipulate the data from Wh to kWh but I see no way to grab the last data value before the internal reset so the template sensor value goes on increasing until a midnight reset.
Does anyone know of a way to do this? A script?

I am trying to do this with a template sensor is beyond my skill set. This is what I have tried in Developer Tool Template without success.

  template:
    - sensor:      
      name: Daily Import Sum
        auto accumVar = 0
      states('sensor.esp_6channelyaml_6c_ct6_rawatthours'): 0
      states('input_number.daily_import_total'): 0  # "states('input_number.daily_import_total')" translates to "reset value" in Japanese

      calculate_accumulated_value: |
        {{ accumVar + max(0, (states('sensor.esp_6channelyaml_6c_ct6_rawatthours') | float(0)) - (states('input_number.daily_import_total') | float(0)))}}

      accumVar: {{ include('calculate_accumulated_value') }}

      states('sensor.esp_6channelyaml_6c_ct6_rawatthours'): {{ states('sensor.esp_6channelyaml_6c_ct6_rawatthours') }}

      {% if states('sensor.esp_6channelyaml_6c_ct6_rawatthours') | float(0) < 0 %}
        accumVar: {{ states('input_number.daily_import_total') | float(0) }}
      {% else %}
        accumVar
      {% endif %}
      }}"

Any help would be much appreciated.

Solved this by reference to Template sensor with last good value stored in attribute - #2 by wigster