# fleet.ev-charging-cost
What one electric vehicle charge costs on a time-of-use tariff (Economy 7,
an EV tariff with a cheap overnight window, or a flat public rate), from the
energy that went into the battery, the charger's efficiency and power, and the
time charging started.
## How the energy is priced
1. **Energy drawn** is more than energy added: the charger and battery lose
some. `efficiencyBasisPoints` is the share that arrives, so 40 kWh added at
90% draws 44.44 kWh from the supply, and that is what the meter bills.
2. **When it is drawn**: at `chargerPowerWatts` from `startTime`, without a
break, so the energy falls into the tariff windows in order. A charge
starting at 23:30 on a tariff that is cheap from 00:30 pays the day rate for
its first hour. Pricing the whole charge at the rate in force when it
started is the usual mistake.
3. **The cost** is the energy in each window times that window's price,
summed exactly and rounded once, with the mode you choose.
The charger is assumed to draw its full rated power throughout. Real charging
slows as the battery fills (above about 80% on a rapid charger), so for a
rapid charge to 100% this is a lower bound on the time and, where the price
changes during the charge, an estimate of the split.
## The tariff
A list of windows, each a start time (`HH:MM`) and a price per kWh in tenths
of a minor unit (24.5p is `245`), in ascending order of start. A window runs
until the next one starts, and the last one runs past midnight to the first,
so `[{00:30, 75}, {05:30, 245}]` is 7.5p from 00:30 to 05:30 and 24.5p for the
other 19 hours. One window is a flat rate. Standing charges are per day, not
per charge, so they are not included.
## Exactness
A minute of charging moves `chargerPowerWatts / 60` Wh into the meter's count,
and energy added becomes drawn energy by dividing by the efficiency. Counting
in units of 1/(60 x efficiency) Wh makes both whole numbers, so every window's
share is exact and the only rounding is the final one: cost to the minor unit
(`mode`), energy drawn to the watt hour (half-up) and time up to the next whole
minute. A charge longer than a day goes round the tariff as many times as it
needs to.
## Limits and errors
Energy added is 0 to 1,000,000 Wh (1 MWh), efficiency 1 to 10000 basis points,
charger power 1 W to 1 MW. Times must be `HH:MM` from 00:00 to 23:59. An empty
tariff, windows out of order or starting at the same time, a negative price, a
bad currency code or rounding mode are errors.
This capability is self-contained: no `energy.*` capability existed to build on
when it was written.