#Merge statistics from old and new toon power meter entities.

1 messages · Page 1 of 1 (latest)

scarlet herald
#

I already found a post, but that piece of python code refuses to run, it's a bit old (2024) so that could be the cause. anyone has some insight how to get this up and running again?

https://community.home-assistant.io/t/merge-statistics-of-old-entity-to-new-entity/467816/42

Traceback (most recent call last):
File "/usr/lib/python3.12/site-packages/pandas/core/indexes/range.py", line 521, in get_loc
return self._range.index(new_key)
^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: 0 is not in range

silver frigate
#

An easy way to merg statistics is to:

  • Delete the old entity (no renaming! Really delete it)
  • Don't delete the statistics for it
  • Rename the new entity to the same as the old was
  • Statistics should merge.
viral moss
mortal haven
thorny nimbus
#

You can only delete entities when their integrations no longer provide them. What integration creates your entity, and why is it still creating it?

#

Can the integration be uninstalled, or a config entry removed, or the device removed.

silver frigate
#

Indeed delete the device or config entry first.

mortal haven
#

Its under RFXCOM RFXtrx integration. So it won't delete the history when deleting the device?

thorny nimbus
#

nope

mortal haven
#

Never? Because that feels like a recipie for a huge database 😄 (Mine kinda already is :D)

thorny nimbus
#

Nothing deletes old statistics unless you manually do it

mortal haven
#

Seems to work 🙂 Then the question is. Any way of finding old un-needed history?

thorny nimbus
#

I think developer-tools/statistics lists old records without an entity

#

it will help you find what to clean up

#

don't say "history" though, that's a separate thing from statistics

#

history is always purged after the purge_days interval

mortal haven
#

Ah okay good to know

#

Trying to import/export missing statistics.. Because I have a couple of months of stats for that sensor in the wrong entity now.. hopefully it works 🙂

#

Worked somewhat.. got some of the information but not all.. strange.

thorny nimbus
#

care to elaborate?

mortal haven
#

Exported to a csv with the hacs import statistics integration. Changed the entity name in the csv. Imported via the integration.
But the csv didn't contain the data. Trying to change the export settings and see if that fixes it. Looks like it defaults to the current year or something.

thorny nimbus
#

ah ok I don't know about those import/export tools

mortal haven
#

Ah crap I might have ruined that data.. renamed the device and entities.. Looks like that I might have overwritten the old entity stats with the imported one that lacks the data.
Luckily I have a seconds sensor that I can figure out how it should be done correctly 🙂