Import historic data into energy entity

I recently integrated my district heating station to monitor the energy consumption as well as the (static) price.
Now I would like to import the historical data which consists of:

  • One entry per month for the last 2 years (data from the invoices)
  • A few additional entries from manual readings I wrote down

Now I tried using SQLite Web to insert the data into the statistics table but after that the energy dashboard showed some negative values.

Here is the query I used to insert the values (dummy-data with only a few entries):

INSERT INTO statistics (created_ts, metadata_id, start_ts, state, sum) VALUES
(1664582399, 1, 1664578799, 542, 542),
(1667260799, 1, 1667257199, 1242, 700),
(1669852799, 1, 1669849199, 1742, 500),

So basically, what I did was to read the data from the invoices and used the last day of the month at 23:59 as create_ts and -1h as start_ts. As state I used the total reading, as sum I used the difference. The start_ts and create_ts are not 100% correct as they are in unix time while the data was created using local time but I would be able to correct this.
Now I’ve seen that there is also a “last_reset_ts” field but I don’t understand when to set it and which value to use here.
So my question is:
How can I import the historical data using SQL?

And I would also like to insert the historical price data. The price is static so my guess would be to create one cost entry / consumption entry. Is that correct?

Load you data into a csv file and run this: Custom Integration to import long term statistics from a file like csv or tsv

Thanks! What exactly do I need to write into the “sum” column? I thought it is the difference between the last state and the current but that does not seem to be true.
But if it is an alltime sum, than it is always the same as the state, at least if you added the entity with state = 0

I have no idea. I don’t use it. I was just aware it existed. Try asking in the linked topic.