There is no need for fixing anything, besides some of us having a problem with the cost entity, thats it.
Its a home assistant issue and not a migration issue, as it’s really complicated how the last resets works in that particular entity.
Besides that i tested it for some days now and no problems at all, u can just convert safe.
Always make back-ups.
ALSO IMPORTANT, DURING THE CONVERSION DEPENDING HOW BIG THE homeassistant_v2.db is , THERE WILL BE NO DATA RECORDED IF YOU DUPLICATE THE DB AND KEEP THE OLD ONE RUNNING U CAN MANUAL INSERT THAT MISSING DATA AFTERWARDS ONLY IF YOU KNOW PHPMYADMIN!.
I tell you a way what went totally fine for me having tons of data in my database for almost 2 years.
So what i did:
- use winscp and go into homeassistant config folder, there you see homeassistant_v2.db file.
Just right click it and press duplicate, call it home-assistant_v3.db
do all this in terminal :
# Install pre-req
apk add python3
apk add py3-pip
pip3 install sqlite3-to-mysql
than do this, be sure u change password,username,and host,db file
sqlite3mysql \
--sqlite-file /config/home-assistant_v3.db \
--mysql-database homeassistant \
--mysql-host core-mariadb \
--mysql-user homeassistant \
--mysql-password 'YOURPASSWORD' \
--ignore-duplicate-keys
i changed this:
--sqlite-file /config/home-assistant_v2.db \
to this:
--sqlite-file /config/home-assistant_v3.db \
and did not use: (was my choice)
--ignore-duplicate-keys
Always make back-up!!!
Just let it migrate, if its ready, u just change the yaml and let it use the new MARIADB url as recorder and restart Home assistant and you ready. thats it
As some of us who are using the cost entity, somehow there is a bug/or mechanism that triggers the last reset and mess up the cost data.
The work-around for the cost entity is this:
- create a new total cost entity, and just import the old data doesn’t matter if it’s static or a fixed price entity… just import that into the new total cost entity and it should work as expected, just choose a day before and not the same day.
using this code:
the id’s are found here using phpmyadmin.
be sure to change MYNEWID and OLDID and the date 2022-12-01.
thanks to @vingerha
insert the code here, be sure u select the correct database and always make back-ups!
insert into statistics (created,start,state,sum,metadata_id) select created, start, 0, sum, MYNEWID from statistics where metadata_id = OLDID and start < ‘2022-12-01’
When the next energy update happens in the energy dashboard, it could show for this day a negative value, no worries as the next day it calculates correct, and u can manual just correct the value of that day… all the old data is also normal visibel in the energy dashboard.
But remember this is not a fix just a temporary work around, till we know how the last reset works for that particular entity…
Again all credits to @eddiewebb for making this conversion possible