Energy that survives a Home Assistant restart: why statistics lose hours, and how the gap gets filled

  • Tested on firmware v1.2.1
  • Getting started

Home Assistant goes down for twenty minutes — an update, a reboot, a power cut. It comes back, and the Energy dashboard has either a hole where the evening was, or a spike in the hour it returned that nobody used.

The shape is familiar enough that people recognise it in one line:

"It is just adding all the energy you missed to the hour the system was turned back on." — anon11644107, Home Assistant forum thread 965144

And the other shape, when a device restarts instead:

"This causes our Shelly 3EMs to reboot and then HA records a major peak of 1000's of kWh being consumed." — msa, thread 479362

Why it happens, and why it is not your configuration

Two mechanisms, both ordinary.

The counter catches up all at once. Your meter kept counting while Home Assistant was not listening. When it comes back and reads the counter again, the whole difference arrives in one reading — and lands in the hour of the restart, because that is when it was recorded. The energy is real. The hour is not.

Or the counter goes backwards. A device that loses power can come back at zero. A cumulative sensor reads that as a counter reset, and what follows is either a vanished total or an invented one:

"This causes your energy to go from 4445 kWh to 0kWh" — anon11644107, thread 386521

"whenever the sensor dropped out and got back again, its value got added to the utility meter" — TimoVerbrugghe, thread 1010856

Neither is a mistake in your setup, which is exactly why it costs so many evenings — you are looking for a fault in a place that has none. Home Assistant stores energy as hourly long-term statistics, and a cumulative counter that restarts does not fit that model cleanly. Both halves are reasonable on their own.

Fixing it by hand works, and does not stick

The answer people pass round is Developer Tools → Statistics, where you can correct a row, or a direct edit of the statistics table. It genuinely works — within its limits: you can adjust an hour that is wrong, but you cannot create hours that were never recorded. And it does not scale to the size of a real gap:

"I have a 2 day gap in my energy statistics because my inverter was offline." — ConfusedTA, thread 803010

"This is something that has been raised a lot and that I also faced, without being able to find an easy workaround." — VaReTaS, thread 803010

"I would like to get this normalized somehow. But I can't even figure out where to start." — 104mapo, thread 965144

Two days is roughly fifty rows. Three weeks is around five hundred. And the fix is against the symptom, not the cause, so the next restart starts the work again.

What changes when the record lives on the meter

The hole exists because the only copy of the record was in Home Assistant, and Home Assistant was not running.

An RBgrid hub keeps its own book: it measures, closes each 15-minute period, costs it with the price in force at that moment, and writes the result to its own flash. None of that depends on Home Assistant being up. When the hub is the thing doing the recording, a Home Assistant restart is an interruption in viewing, not in measuring.

Each stored hour also carries its own quality note, so a record that is unusual says so rather than looking normal. An hour that absorbed energy from a break in measurement is marked as covering an outage, and the History page shows that note beside the figure — the number is not quietly presented as if nothing happened.

This is about the hub's record, not about Home Assistant's. Nothing here changes what Home Assistant stores or how it stores it. The next section is about the part that does reach Home Assistant.

The hourly import, and the setting that decides what you see

The RBgrid integration belongs to one of the two ways of running the hub: the hub flashed as an ESPHome device. If yours runs the standalone firmware and reaches Home Assistant over MQTT, there is no import to turn on, and moving between the two is a reflash rather than a setting — so this is chosen at the start, not switched later.

On that route the hub's book does not stay on the hub. Every hour the integration asks for it and writes it into Home Assistant's own long-term statistics as a second set of rows, alongside the ones Home Assistant already keeps for your live sensors — one row per hour, with the energy and the cost the hub recorded for that hour, not for the hour the reading arrived. It carries on from where it left off, so a pause of days is filled hour by hour rather than dropped into one. The first import, which has nothing yet to carry on from, reaches backwards instead: up to 30 days of the hub's hourly book go into statistics in a single pass. Two limits come with that, and both matter more than the number: hours the hub spent without power are not in its book, so nothing can fill them; and the import adds its own rows without touching the ones you already have.

The import runs by itself, once an hour. The Import into HA statistics button on the panel's History tab runs that same pass immediately — it is one mechanism with a manual trigger, not two. In Home Assistant's own pickers — the Energy dashboard's source settings, a statistics card — the rows appear under names like RBgrid Hub Main energy in and … cost. An imported hour can turn up with its energy and without its cost, and gain the cost on a later pass; that is the tariff plan's currency not being known at the moment of the import, not money going missing.

⚠️ By default the Energy dashboard is not showing you those rows. The integration's setup wizard connects the dashboard to the live counters, and on those a restart still produces the familiar step in the hour Home Assistant came back. The imported rows, which have no gap, are available in the Energy dashboard's source settings — you have to pick them.

So there are three different things, and conflating them is how people end up disappointed:

Has a gap after a restart?
The hub's own record No — it never stopped measuring
The imported statistics rows in Home Assistant No — they are a copy of that record, hour by hour
The live counters the dashboard uses by default Yes — same step as before, in the hour HA returned

On the MQTT route there is no import at all: the hub publishes live values, and Home Assistant's statistics behave exactly as they always have. The hub's own record is still intact, and it is still the place to look when a figure is in doubt.

How to check, rather than trust

  • In the hub: open the hub's own History page for the day in question. An hour that absorbed energy from a break says so in its quality note, so you can tell a strange-looking hour from a wrong one.
  • In Home Assistant: compare the live-counter source with the imported RBgrid Hub … rows for the same day. If they differ, the difference is the gap — and the imported rows are the ones with the hours in their own places.
  • Against your bill: the hub's applied-price log keeps 40 days as CSV, one row per closed 15-minute period, with the source of each price.

What this does not do

  • It does not repair Home Assistant's existing history. Rows that were already wrong stay wrong; the import adds its own rows from the hub's own book, it does not rewrite yours.
  • It does not change the dashboard's default source. That choice is yours to make in the Energy dashboard's settings, and this article is not predicting it will change.
  • It does not give Home Assistant 15-minute resolution. The hub's periods are the hub's; what reaches Home Assistant is hourly, as it has always been.
  • It does not stop your sensors dropping out. It removes the consequence for the record, not the cause in your network.

Where to read more

Quotes are reproduced from public Home Assistant forum threads and GitHub issues, with their authors and thread numbers, so you can read each thread in full.