How-to: extrapolation / projection function (e.g. for estimated yearly energy costs)?

For some reason extrapolation (estimation of energy consumption based on historic consumption in my case) isn’t a feature which is discussed so far.
But I really want to get some feedback on how you realised that and how you’ve managed the issues, in order to fix some problems that I have with my implementation.

Simply said, I’m using a change statistics sensor like this one:

  - platform: statistics
    name: 'total energy | consumption last 7 days'
    unique_id: total_energy_consumption_last_7_days
    entity_id: sensor.total_energy
    state_characteristic: change
    max_age: 
      hours: 168

The result is then multiplied by 52 (weeks) and the current electricity price via a template sensor:

 - sensor:
    - name: "total energy | costs/year (7days)"
      unique_id: total_energy_costs_year_7d
      unit_of_measurement: €
      device_class: monetary
      state_class: measurement
      state: >-
        {{ (
            states('sensor.total_energy_consumption_last_7_days')|float(0) *
            states('input_number.electricity_price_eur_kwh')|float(0) * 52
          )|round(2) }}

The issue that I’m facing is that the extrapolated value regularly goes to 0 after a restart and I have to reload the statistic entities multiple times until most of the sensor show the correct value. But with some of them I have no luck. These go back to 0 after a restart and need build up for 7 days in my case. I also have extrapolation which is based on 30 days of consumption, which take even longer to build up :frowning:

What do you think about my implementation and do you have a better idea which might also solve my problem? (Yes, I tried the average statistic on the historic power usage, which is nice because it returns a proper value without waiting 7 or 30 days, but it killed my Raspi in terms of CPU power :smiley:)

Thank you very much in advance!