ha-statistics
Recorder long-term statistics — the aggregated, downsampled history HA keeps
for sensors with state_class (and external stats). Prerequisite:
../ha-shared/SKILL.md.
Statistics vs. history
- History (
hass-cli system history) = raw state changes, short retention. - Statistics (here) = hourly/daily/.. roll-ups (
sum/mean/min/max), kept long-term. Use these for "totals over a month", energy, trends.
Discover what exists
hass-cli statistics info # recorder health (backlog, running)
hass-cli statistics list # all statistic ids + metadata
hass-cli statistics list --type sum # only cumulative (energy/water/gas)
hass-cli statistics list --type mean # only averaged (temperature, power)
hass-cli statistics metadata --ids sensor.a,sensor.b
list entries carry statistic_id, unit_of_measurement, source,
has_sum, has_mean.
Pull values over a period
hass-cli statistics period \
--ids sensor.energy_total,sensor.water_total \
--start 2026-06-01T00:00:00+00:00 \
--end 2026-06-30T23:59:59+00:00 \
--period day
--periodbucket:5minute|hour|day|week|month(defaulthour).--startis required (ISO8601);--enddefaults to now.- Result maps each id to an array of buckets.
sumseries are cumulative — for "how much in June", subtract the first bucket'ssumfrom the last (or readchangewhen present).meanseries give the average per bucket.
Notes
- A fresh instance has empty statistics until the recorder accrues data
(first roll-up after ~1 hour);
listmay return[]initially. - Combine with
../ha-energy/SKILL.md: take thestat_*ids fromenergy prefs get, then query them here. - Audits (e.g. "dead/never-updating statistics") are derived client-side from this native data — not a built-in HA feature.