On Restart sensor restores previous value which messes up statistics

I have a sensor which updates just before midnight to get the final reading cost of that days electricity. This sensor is then is fed into a Statistics (mean) sensor to give me an average cost based on the last weeks readings. My issue is that on a restart the first sensors value is restored which then upsets the Statistic calculation. Is there a way around this? Or is there a better way to do it?

  - trigger:
      - platform: time_pattern
        hours: 23
        minutes: 59
    sensor:
      - name: "Daily Energy Cost"
        unique_id: 'daily_energy_cost'
        icon: mdi:cash
        state: "{{ states('sensor.smart_meter_energy_cost_today')|float }}"
        unit_of_measurement: "GBP"

  - platform: statistics
    name: "Average Energy Cost"
    unique_id: average_energy_cost
    entity_id: sensor.daily_energy_cost
    state_characteristic: mean
    sampling_size: 7

Following.

I’m struggling with something similar, trying to use “sum” statistics to track cumulative rainfall last 7 days based on a template sensor that updates daily at 11:59pm based on a sensor that has yesterday’s rainfall. Unfortunately, restarting HA causes the sensor template to update, causing it to add yesterday’s rainfall to the total twice.

Can anybody explain how to use Statistics within Home assistant WITHOUT a restart affecting the results? Or even a workaround?

The only way I have managed to get this to work without any interuption from restarts is by using the HACS Average Sensor add on.

This didn’t work either! As far as I can see there is no way to use either the statistics or average platforms that are not affected by a home assistant restart. This surely should be simple to do!