In an attempt to answer my own question, I queried the database directly, and I looked at the long term statistics of 2 sensors. One is a regular template sensor that records the total amount of energy consumed by a device, the other comes from the history_stats platform and it records the time the device was running on a day by day basis.
There is one row per hour, as is to be expected. Both sensors have a timestamp in the start_ts column (and some other housekeeping columns), but the way the actual stats are stored is different.
The sensor for total amount of energy stores the data in the state and sum columns, but the running-time sensor has the data stored in the mean, min, and max columns.
I can also see that the data I tried to import for the history_stats sensor actually did end up in the database table (which is called “statistics”). However, since I labeled the columns in the CSV file as ‘state’ and ‘sum’, that’s also where they ended up. So the table has null for mean, min, and max, and some values in state and sum.
It seems that Home Assistant ends up deciding to ignore these state and sum values for a history_stats based sensor, since those values aren’t supposed to be there to begin with. So even though the data is in the database, in the end it doesn’t get displayed. Which makes sense, it wasn’t supposed to be there in the first place.
So in conclusion, rather than importing the history_stats data in the state and sum columns, I should have used a mean, min, and max column.
I need to figure out now how to structure those, but more importantly how to get my hands on them. When I get a graph of this sensor that comes from history_stats in the history screen of Home Assistant, and then use the Download feature, it gives me the data as ‘state’ (which might be a bug in Home Assistant actually).