A lightweight, custom Home Assistant card that visualizes your electricity consumption across different times of the day using a sleek pie chart. The card breaks the day down into three logical 8-hour periods: Night (00:00–08:00), Day (08:00–16:00), and Evening (16:00–24:00).
Unlike many other custom cards, this card requires no external dependencies (like ApexCharts). Instead, it renders everything using efficient, native SVG graphics and fetches history data directly through the Home Assistant History API.
- Donut pie chart split into periods: 00–08, 08–16, 16–24
- Fetches data directly from the HA History API (no ApexCharts, no external dependencies)
- Two modes:
- Interactive — date navigation with arrows and a date picker
- Static — locked to a specific day via
offset(no UI controls shown)
- Live updates for today's card when the sensor value changes
- Correct timezone handling — uses local time in all API calls
- Warning displayed if data is missing due to recorder
purge_keep_days - Single-segment pie renders correctly as a full ring
- Configurable colors, title, and max days back
- Registers with
window.customCardsfor the HA card picker
-
Copy
electricity-pie-card.jsto/config/www/electricity-pie-card.js -
Add the resource in
configuration.yaml:
lovelace:
resources:
- url: /local/electricity-pie-card.js
type: moduleOr via the UI: Settings → Dashboards → ⋮ → Resources → Add resource
- Restart Home Assistant (or reload resources).
| Option | Type | Default | Description |
|---|---|---|---|
entity |
string | required | The accumulating energy meter sensor |
title |
string | Elförbrukning |
Card title |
offset |
integer | (not set) | Days relative to today: 0 = today, -1 = yesterday, -2 = two days ago. When set, the card is static (no date navigation shown) |
max_days_back |
integer | 30 |
How many days back the date picker allows. Ignored when offset is set. See note on recorder below. |
colors |
list | ["#5B8AF5","#F5A623","#7ED321"] |
Colors for the three periods |
Note on
max_days_back: This is limited by Home Assistant's recorderpurge_keep_dayssetting (default: 10 days). If you navigate to a date outside the recorder window, the card will show a warning. To increase history retention, setpurge_keep_daysin your recorder config.
Interactive card — today with date navigation:
type: custom:electricity-pie-card
entity: sensor.dsmr_reading_electricity_delivered_1
title: Förbrukning idag
max_days_back: 30Static card — always shows yesterday:
type: custom:electricity-pie-card
entity: sensor.dsmr_reading_electricity_delivered_1
title: Igår
offset: -1Static card — two days ago:
type: custom:electricity-pie-card
entity: sensor.dsmr_reading_electricity_delivered_1
title: I förrgår
offset: -2Interactive with extended history (requires recorder config):
type: custom:electricity-pie-card
entity: sensor.dsmr_reading_electricity_delivered_1
title: Historik
max_days_back: 90
colors:
- "#E57373"
- "#FFB74D"
- "#81C784"The card calls HA's built-in /api/history/period/ endpoint directly. It fetches raw state values for the sensor and calculates the consumption diff per 8-hour period locally in JavaScript — the same logic as ApexCharts group_by: func: diff, but without any charting library overhead.
All API calls use local time (no UTC offset issues). Historical days are cached in memory for the session. Today's data is never cached and re-fetches whenever the sensor state changes.
To extend history beyond the default 10 days, add to configuration.yaml:
recorder:
purge_keep_days: 90- Initial release
- Donut pie chart with three 8-hour periods
- Interactive mode with date picker and arrow navigation
- Static mode via
offsetparameter - Direct HA History API integration — no ApexCharts dependency
- Configurable colors, title, max days back
- Registers with
window.customCards
