Add ability to import long-term recorded data of individual sensors into a new sensor grouping them

Feature:

When creating a new e.g. template sensor based on other sensors (e.g. sum of energy meters from individual devices), introduce the ability to import the history from these individual devices based on what is recorded in the database.

Use case:

I have 1+ years of energy consumption data for my devices. I would now like to clean up my energy dashboard a create a new template sensor summing these devices into one (e.g. all my heaters into an all heaters energy sensor) to display on the dashboard.

If I do this now, I will effectively lose the 1 year of past data. My choice is to not display the individual sensors, but have the correct energy totals from today. Or continue to display them, but have the energy use doubled because my sum sensor already includes them.

Such a thing was not necessary before since who cares about 10 days of data. But in principle we are now encouraged to compare past energy use to today’s and eventually will have multiple years of data. Any restructuring of the sensors (grouping, etc) will destroy the ability to compare.

Of course I am opening a can of worms. But today if I redefine an exisiting template sensor to include/remove soem sensor or perform some arithmetical operation without changing the unique_id, I am ending up with a history not equivalent to the current definition.

I’ll broaden the scope of this request to add the capability of recording data for a given date/time.

Utility providers “APIs” provide metering data usually with a delay of several days, and they can not be recorded with the proper timestamp, so they are pushed into the database as if they are current readings.

Once Home Assistant accepts recording data/states at a given timestamp, the possibility to import old data could be implemented using “user scripts”.

Recording states/data for a given timestamp implies that the Energy dashboard data and other statistics for the corresponding time period must be updated as well in order to reflect this.

I just found the other feature request which is related: Add historic data to Energy dashboard .