The recorder integration in Home Assistant stores everything that happens in your home. It is the backbone of the history and the logbook. It also keeps long-term statistics, which power the energy dashboard and other graphs you see in Home Assistant.
Actions
Spook adds one action for the recorder. You find it wherever you add an action, marked with a 👻.
Import statistics
Imports long-term statistics into the recorder database of Home Assistant.
Your energy history does not start the day you installed Home Assistant. Your energy provider has years of it, often as a CSV file you can download, and a previous system may have its own. This action writes that history into the long-term statistics, so it shows up in the energy dashboard and the statistics graphs.
How to use it
- Open the script that should do the import, and select Add action.
- Search for import statistics, and select Recorder: Import statistics 👻.
- Fill in Statistics ID, usually the entity ID of the sensor, and Source, usually
recorder. - Turn Has a mean and Has a sum on or off to match the kind of sensor: a meter that counts up has a sum, a temperature has a mean.
- Optionally, fill in Name and Unit of measurement.
- Fill in Statistics, the list of values to import, one per hour. This one is easiest in YAML, see the example below.
- Select Save, and run the script once.
Just want to see it work? Try this action opens it in your Home Assistant, ready to run once.

| Action properties | |
|---|---|
| Action | Recorder: Import statistics 👻 |
| Action name | recorder.import_statistics |
| Action targets | No targets |
| Action response | No response |
| Spook's influence | Newly added action |
| Tools | Try this action |
| Action data parameters | |||
|---|---|---|---|
| Attribute | Type | Required | Default / Example |
has_mean | boolean | Yes | |
has_sum | boolean | Yes | |
name | string | No | None |
source | string | Yes | |
statistic_id | string | Yes | |
unit_of_measurement | string | No | None |
stats | mapping | Yes | |
stats attribute mapping | |||
|---|---|---|---|
| Attribute | Type | Required | Default / Example |
start | datetime string | Yes | |
mean | float | No | |
min | float | No | |
max | float | Yes | |
last_reset | datetime string | No | None |
state | float | No | |
sum | float | No | |
More information about the mapping/meaning of fields in long-term statistics can be found on the Home Assistant data portal.
One hour of energy use for a meter that counts up:
action: recorder.import_statistics
data:
has_mean: false
has_sum: true
statistic_id: sensor.some_energy_sensor
source: recorder
unit_of_measurement: kWh
stats:
- start: "2023-07-03 21:00:00+02:00"
sum: 123123
Repairs
Spook looks through the recorder for long-term statistics that no entity belongs to anymore, and tells you in the repairs dashboard.
This one Spook can fix for you, straight from the repair. New to repairs? Follow Fix your first repair.
Orphaned long-term statistics
The recorder keeps long-term statistics for sensors that no longer exist, usually because a sensor was removed and its history was kept. Not harmful, but they take up database space, and keep showing up in pickers and graphs long after the sensor is gone.
Orphaned long-term statistics
The recorder keeps long-term statistics for sensors that no longer exist, usually because a sensor was removed and its history was kept. Not harmful, but they take up database space, and keep showing up in pickers and graphs long after the sensor is gone.

How to fix it: Open the repair, and choose Clear these statistics to have Spook throw that history away, for good. Or choose Let me do it myself, which points you at Settings > Tools > Statistics. Want to keep them? Keep them, stop telling me leaves them alone and stops the repair coming back. The repair disappears by itself once it is fixed.
The recorder keeps long-term statistics separately from the states it records, and it keeps them by statistic ID, not by entity. So they outlive the entity they were collected for. Spook compares the statistics in the database against the entities that still exist, and raises a repair listing the ones with no entity behind them anymore.
Spook looks again before it clears anything, and only removes what the list you read and that fresh look agree on. Anything that has an entity behind it again by the time you press the button is left where it is, without being named. The repair comes back for whatever is still orphaned. If none of them still need clearing, Spook says so.
A statistic has to keep looking abandoned for a quarter of an hour before Spook mentions it at all. A sensor can be gone for a moment, when an integration reloads or while Home Assistant is still starting. That is no reason to delete its history.
Use cases
What people use this for:
- Import data into the recorder yourself. For example, history from a previous system, or the CSV file with your energy usage from your energy provider.
Missing something here?
An action, an entity or a repair this integration should have? Say so. Stuck, or found a bug? There is help.


