Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

keeping historical data from other entity (not quite a issue - just a probable solutions) #16

Open
pejotigrek opened this issue Apr 16, 2024 · 2 comments

Comments

@pejotigrek
Copy link

hi!

as I am in the process of planning to exchange my own buggy templates to your integration, I am also looking for a solution to keep my over-two-years old history in the energy dashboard.

case mentioned in #2 seems to be clear: history is lost until manually importing/changing it in the database, but - I see the light in the tunnel ;)

PROBABLE SOLUTION no.1

according to this comment on the official community [I'm not the author, just the messenger], there is a way to keep old data. it just needs a bit of caution and specific steps:

  1. Delete old entity
  2. Rename new entity to old entity_id
  3. New entity will inherit old entities history

I didn't tested this yet [I think I'll setup some testing environment for that, just in case, but still have not enough time to play with it...] but as it was updated "recently" [about december '23, and the comment from March the 5th confirms it's ok] there is a chance it works still, especially that it was posted by a trusted forum moderator petro.

did you, or anyone using your integration, tried this by a chance?

--

PROBABLE SOLUTION no.2

on the other hand - while I am using a template sensor to do all the counting, and this template sensor is attached to energy dashboard, and PROBABLY MOST OF THE PEOPLE use template sensors too in similar scenario - the simplest solution would be to use your integration's sensor in the "original" template sensor. I know, this would double the entities, but also it won't mess anything in the dashboard, as still the same sensor would be attached to the energy dashboard. maybe you could add this to the documentation as a possible workaround? this would make the usage less scary to users that already have quite a big database of energy info :)

@MiguelAngelLV
Copy link
Owner

MiguelAngelLV commented Apr 20, 2024

A solution is copy all stats from old sensors to new sensors.

Using:

INSERT INTO `statistics` (column1, column2, ..., `metadata_id`)
SELECT column1, column2, ..., 'new-metada-id'
FROM `statistics`
WHERE `metadata_id` = 'old-metadata-id` AND `start_ts` < 'first-date-new-values'';

You must copy each sensor stats and after fix the ouliers witch developer console -> stats tool

@pejotigrek
Copy link
Author

pejotigrek commented Apr 20, 2024

A solution is copy all stats from old sensors to new sensors.
(...)

I know this, and that's a "very dirty" solution, which can be a real PAIN if you've got months or even years of statistics - too many things can go wrong with this method ;) not mentioning that it is scary for people that never played with sql and can steer away from the integration.

that's why I'm just pointing to the two possible, more elegant and what's important: safer solutions, if anybody needs them.

don't get me wrong - I know that this all is because of how "unfortunate" entity-history is handled by HomeAsssistant - so I am not trying to tell the integration is wrong, or your sql export/import method is wrong; I'm just giving some tips for others to try if they need to, and are afraid that fiddling directly with database can do more harm than good :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants