Wow, if not even you Taras, one of the most active users here (or even a mod, right?) knows thisā¦ I tend to say: no one knows this.
Iām really a bit (a lot of a bit tbh) annoyed about this. One change has been promoted as improvement/great new feature, while at the same time not providing a solution for the downside of this change. Now people have no more control over the history of entities, they are not interchangeable anymore - so in the end one actually LOOSES data (history / LTS), which is - depending on the point of view - exactly the opposite of the Home Assistant now keeps history when renaming entities :metal:
announcement at 2023.4: Custom template macros, and many more new entity dialogs! - Home Assistant.
Thatās really bad because swapping entities saved me so much time and hassle in the past. Hopefully one will come up with a workaround solution (āthe manual wayā) or - no idea how - thereās a smart person adding a feature request to raise importance for and kick-start this (having a GUI feature in the dev tools / statistics section for example).
What would you recommend to make some progress here? Iām rather looking at the 10 seconds brainstorming idea of the GUI based āstatistics transfer featureā in the dev tools statistics section instead of risking my (one and only) productive system to see if thereās a way to actually hack HA to preserve LTS.
Really, guys, what do you do when devices die, e. g. when their sensors are part of the energy dashboard?
Not sure about devices, but on an entity level (as of until Core 2023.3): definitely no. They will sit and get rusty in the database forever. See WTH can't we fix recorder data easily using the UI (dev-tools section) - single data points + mass- changes? and Remove statistics of disabled (not deleted!) entities from recorder (took a deep dive into LTS fixes and deletions one year ago).
Run this and youāll probably be surprised how much rubbish is left in LTS while there is no corresponding data in states table anymore (deleted entities, left LTS):
SELECT
CASE WHEN entity_id IS NULL
THEN 'Orphaned'
ELSE 'OK'
END Issue,
entity_id,
statistic_id
FROM (
SELECT
b.entity_id,
a.statistic_id
FROM
statistics_meta a
LEFT JOIN 'states_meta' b
ON a.statistic_id = b.entity_id
GROUP BY
a.statistic_id -- we want to avoid duplicates
)
My small setup already has quite some of that (āorphaned statistics entities in recorderā):
By the way no idea what happened to https://community.home-assistant.io/t/statistics-fix-issue-large-amount-of-data/419728 - the URL is fine, but the thread is not available - did not survive the forums migration? Luckily it has been archived, at leastā¦ https://web.archive.org/web/20230401222744/https://community.home-assistant.io/t/statistics-fix-issue-large-amount-of-data/419728