Cleaning up switched histories for daily reset and total increasing sensor

I have an interesting problem.

In Solax integration we used to have two sensors misslabeled - same metric daily reset and total increasing were switched, both marked as total increasing.

This situation was corrected in the patch in library used by solax integration and with recent bump - released.

This however caused my energy dashboard go haywire after the upgrade, I restored the backup, deleted the solax device, re-added it, and now - the conclusion.

My history is utterly bonkers :slight_smile: take a look:

I’d like to fix that, now I have 3 entities:
A. consumed total - containing proper total aggregated value… …just since today
B. consumed today - new entity, contain daily reset value, no history, just today
C. consumed (without total or today as a postfix) old entity, no longer provided by integration, renamed in library to today - no new values, but contains the history that I should have in consumed total now.

I’m fairly proficient with database edits, working mosltly with MariaDB for past few years, but, quoting classics “how hard can it be”?

Would anyone here have any advice where to start cleaning that mess (I made myself) up?
I’d like to:

  1. update the records of A before today a history of B (that contain no data before today as newly provided sensor after integration update)
  2. move (update?) data from C (as it contain proper total increasing data) as a pre-today records for A

Does it make sense?

…restored the backup.

Basically I would like to rename the following sensor AND it’s data in history short and long term:
from: solax_consumed_energy_total
to: solax_consumed_energy_today

After that rename the second one and also “move/rename” data to new name:
from: solax_consumed_energy
to: solax_consumed_energy_total

So, basically switch them around, renaming one of them (adding today) to align with current state of solax library.

Current behaviour is - when I do the renames of the entities as above, the data between long and short term history gets mixed up:

  1. short term data for new named solax_consumed_energy_total seem to still show daily data as it’s bound to entity name, and was renamed along. Long term data looks great.
  2. solax_consumed_energy_today loses all short term data (it never had it as new entity) and displays just long term data (which seem proper as it’s bound to the entity name/wasn’t renamed)

…hmm. Short history data get’s renamed and that’s why it’s broken. Long term stats seem fine. You’d probably noticed that I changed the retency of short term data.

Maybe I should just set the retention of short term data to 0 or purge it, and be left with proper long term stats, while building up new, proper, short term.