powercost is a tiny, dependency-free SDK that converts electricity consumption into the true all-in cost — spot energy, grid fees, energy tax and VAT, itemised. It runs in the browser (or Node), with tariff data as lazy-loaded packs. Calibrated to real Swedish tariffs.
npm i powercost import { price } from 'powercost'; import { swedenDb } from 'powercost/data/se'; // lazy data pack const cost = await price({ consumption: [{ start, end, kwh }], config: { zone: 'SE3', providerPlanId: 'tibber-kvartspris', gridOperatorId: 'vattenfall-e4-25a', reportCurrency: 'USD' }, db: swedenDb, live: true, // fetch spot + FX in the browser }); cost.total.format(); // "1.23 SEK"
A Swedish electricity bill is two companies plus the state. powercost models all of it.
Day-ahead spot price per bidding zone (15-min), plus your provider's påslag and fees — e.g. Tibber.
Your grid operator's transfer fee and fixed charges, energy tax (energiskatt), and 25% VAT on top of everything.
Every line returned separately in exact integer money — so you can trust the number, not just see it.
Separates the per-kWh cost that scales with usage from fixed monthly fees — the number load-shifting needs.
Pure ESM, no backend. Live spot (elprisetjustnu) + FX (ECB) are fetched directly from the browser.
Load only what you need — import('powercost/data/se'). New countries are just new modules.
The first thing it powers: is hosting a GPU worth it after electricity?
Feed measured consumption and your tariff; powercost returns the marginal all-in cost of those kWh. Net it against rental income for profit per day, week, month — and the break-even spot price to auto-pause above. The same engine works for EV charging, batteries, heat pumps, or any "what did this actually cost?" question.
A series of intervals — { start, end, kwh }. 5-minute, 15-minute, hourly; whatever you measure.
import('powercost/data/se') — region (SE1–SE4) + provider + grid operator. New markets are new packs.
One call returns the itemised, all-in cost in your currency — computed locally, no server.