Skip to Content
Octopus Energy Packages

Energy Overview

Step-by-step guide to migrate the consumption chart and timeframe controls to the new measurements API

Which tab should I pick?

Blueprint if you use ConsumptionGraph, ConsumptionGraphControl, or DualConsumptionGraph from @krakentech/blueprint-utils or @octopus-energy/measurements before v0.5.

Coral if you already render with Coral's EnergyOverview compound components and useEnergyOverview / useEnergyOverviewTimeframe.

Replace state management

Replace useMeasurementFilters with useTimeframe (date range state) and usePreferences (display preferences like cost/kWh, tax, standing charge).

Before
import { DateRangeToggleValue, useMeasurementFilters } from "@octopus-energy/measurements";

const measurementFilters = useMeasurementFilters({
  initialDateRange: DateRangeToggleValue.WEEK,
  enableSmartAnchorDate: true,
});
After
import { usePreferences } from "@octopus-energy/measurements/preferences";
import { createLocalStorageAdapter } from "@octopus-energy/measurements/storage/local-storage";
import { useTimeframe } from "@octopus-energy/measurements/timeframe";

const storage = createLocalStorageAdapter();

const [timeframe, timeframeActions] = useTimeframe({
  storage,
  timezone: "Europe/London",
});

const [preferences, preferencesActions] = usePreferences({ storage });

timezone is now required

The old hook inferred the timezone from the browser. You must now pass an IANA timezone string explicitly (e.g. "Europe/London").

Key mapping:

Old optionNew equivalent
initialDateRangedefaults: { period: "month" }
enableSmartAnchorDateUse anchorDateQueryOptions() separately
defaultConsumptionMeasurementusePreferences({ defaults: { unit: "cost" } })
includeTaxusePreferences({ defaults: { tax: true } })
ignoreStoredFiltersOmit storage from useTimeframe
ignoreCostViewPreferenceOmit storage from usePreferences

Replace data fetching

Replace useMeasurements with two React Query calls: one for market supply points (meter descriptors) and one for the actual measurements.

Before
import { FuelType, useMeasurements } from "@octopus-energy/measurements";

const measurements = useMeasurements({
  variables: {
    accountNumber,
    dateLocale: enGB,
    enabled: true,
    marketSupplyPointId,
    measurementFilters,
    propertyId,
    utilityType: FuelType.Electricity,
  },
});
After
import { groupMeasurements } from "@octopus-energy/measurements";
import type { UtilityMarkets } from "@octopus-energy/measurements/market-supply-points";
import {
  marketSupplyPointsQueryOptions,
  measurementsQueryOptions,
} from "@octopus-energy/measurements/react-query";
import { useQuery } from "@tanstack/react-query";

const utilityMarkets: UtilityMarkets = {
  electricity: ["GBR_ELECTRICITY"],
  gas: ["GBR_GAS"],
};

const marketSupplyPointsQuery = useQuery(
  marketSupplyPointsQueryOptions(client, {
    accountNumber,
    propertyId,
    utilityMarkets,
  }),
);

const measurementsQuery = useQuery(
  measurementsQueryOptions(client, {
    marketSupplyPoints: marketSupplyPointsQuery.data,
    propertyId,
    timeframe,
  }),
);

const { electricity } = groupMeasurements(measurementsQuery.data, {
  by: "utility",
});

Replace utilityMarkets values

The utilityMarkets object maps utility types to market identifiers used by your territory. Replace GBR_ELECTRICITY and GBR_GAS with the market names your product uses.

Key option changes:

Old option (useMeasurements)New optionNotes
measurementFilters (required)timeframePass timeframe from useTimeframe
startAt / endAttimeframeDates are now derived from timeframe
marketSupplyPointIdmarketSupplyPointsPass the full array resolved by marketSupplyPointsQueryOptions
dateLocaleN/ANo longer part of the query; pass directly to <EnergyOverviewCard> and getDateRangeDisplay
enabledN/AUse React Query's enabled option directly on useQuery
firstpageSizeDefault 100, max 100
readingDirection (single)readingDirections (array)["consumption"], ["generation"], or both
utilityTypeN/AResolved from market supply points
dayIntervalreadingFrequenciesPartial<Record<TimeframeRange, ReadingFrequencyType>>. E.g. { day: "HOUR_INTERVAL" } for hourly day data.

Transform records into chart data

The old useMeasurements hook called prepareChartData internally to produce chart-ready series. This is now an explicit step using createMeasurementsOverview.

After
import { createMeasurementsOverview } from "@octopus-energy/measurements/overview";

const overview = createMeasurementsOverview(electricity?.measurements, {
  preferences,
  timeframe,
});

The overview object contains chartData, lineChartData, legendEntries, totalConsumption, totalStandingCharge, and more. See the Overview API reference for the full shape.

Wire to Coral components

The compat layer maps the new output into props that Coral's EnergyOverview compound components understand. getCardProps() returns the same shape that useEnergyOverview() produced, and getTimeframeProps() returns the same shape that useEnergyOverviewTimeframe() produced.

Replace ConsumptionGraph and ConsumptionGraphControl with Coral's EnergyOverview compound components. The compat layer produces all the props you need.

Before
import {
  ConsumptionGraph,
  ConsumptionGraphControl,
} from "@krakentech/blueprint-utils/client/components";

<ConsumptionGraphControl
  measurementFilters={measurementFilters}
  translations={translations}
/>
<ConsumptionGraph
  measurements={measurements}
  measurementFilters={measurementFilters}
  translations={translations}
  locale="en-GB"
  currency="GBP"
/>
After
import {
  getCardProps,
  getDateRangeDisplay,
  getTimeframeProps,
} from "@octopus-energy/measurements/compat";
import {
  EnergyOverview,
  EnergyOverviewCard,
  EnergyOverviewDataSection,
  EnergyOverviewDateDisplay,
  EnergyOverviewEnergyUsage,
  EnergyOverviewHeader,
  EnergyOverviewSettingsAndDisplay,
  EnergyOverviewSettingsControls,
  EnergyOverviewStandingCharge,
  EnergyOverviewTimeframeControls,
  EnergyOverviewTimeframeNavigation,
  EnergyOverviewTimeframeSummary,
  EnergyOverviewTimeframeToggleButton,
  EnergyOverviewTitle,
  EnergyOverviewTotalValue,
  EnergyOverviewUnitToggle,
  EnergyOverviewUnitToggleOption,
  EnergyOverviewViewType,
} from "@octopus-energy/coral/molecules";
import { enGB } from "date-fns/locale/en-GB";

const card = getCardProps({
  overview,
  utility: "electricity",
  preferences,
  preferencesActions,
});

const { navigation, timeframeControls, toggleButton } = getTimeframeProps({
  timeframe,
  timeframeActions,
});

const isPending = marketSupplyPointsQuery.isPending || measurementsQuery.isPending;

return (
  <EnergyOverview dateLocale={enGB} currency="GBP" loading={isPending}>
    <EnergyOverviewTimeframeControls {...timeframeControls}>
      <EnergyOverviewTimeframeToggleButton {...toggleButton} />
      <EnergyOverviewTimeframeNavigation {...navigation} />
    </EnergyOverviewTimeframeControls>

    <EnergyOverviewCard {...card} currency="GBP" dateLocale={enGB} locale="en-GB">
      <EnergyOverviewHeader>
        <EnergyOverviewTitle>Electricity usage</EnergyOverviewTitle>
        <EnergyOverviewViewType />
      </EnergyOverviewHeader>

      <EnergyOverviewDataSection>
        <EnergyOverviewTimeframeSummary>
          <EnergyOverviewDateDisplay>
            {getDateRangeDisplay(timeframe, enGB)}
          </EnergyOverviewDateDisplay>
          <EnergyOverviewTotalValue />
        </EnergyOverviewTimeframeSummary>

        <EnergyOverviewSettingsAndDisplay>
          <EnergyOverviewSettingsControls>
            <EnergyOverviewStandingCharge />
            <EnergyOverviewUnitToggle>
              <EnergyOverviewUnitToggleOption value="kWh">kWh</EnergyOverviewUnitToggleOption>
              <EnergyOverviewUnitToggleOption value="cost">£</EnergyOverviewUnitToggleOption>
            </EnergyOverviewUnitToggle>
          </EnergyOverviewSettingsControls>

          <EnergyOverviewEnergyUsage>Electricity usage</EnergyOverviewEnergyUsage>
        </EnergyOverviewSettingsAndDisplay>
      </EnergyOverviewDataSection>
    </EnergyOverviewCard>
  </EnergyOverview>
);

Complete example

Where to go next

On this page