One of the main aims of an API Economy is to drive value where previously there was none. Value can be realised in several ways, it may be via increased usage of an existing API, enabling a new way of creating revenue or maybe improving an existing process by utilising APIs.

This article describes how, by using multiple APIs, a significant cost saving was made to using an existing green technology.

A bit of background information

No alt text provided for this image

The author is lucky enough to own a Kia eNiro Electric Vehicle. Much like with Teslas or other fully electric vehicles out there, you have the option to charge the battery quickly using one of the many Fast Chargers dotted throughout the country, or to charge (slowly) at home, using a ‘granny cable’ from a normal UK 3 pin plug.

Primarily in use in London, England the Kia doesn’t see many daily miles. Averaging 10 – 15 miles per day with the occasional longer runs when visiting places further afield. This means that the battery pack (good for 300+ miles in the summer) can go a significant number of days before requiring recharging.

The author gets his electricity (and Gas) from Octopus Energy. Octopus Energy offer an ‘Agile’ tariff. Unlike ‘normal’ tariffs, where each kwh of electricity used costs the same (regardless of when during the day or night it was used), the Agile tariff has a price that varies during the day. The price the electricity will cost is published a day or so in advance.

Best Battery Health

No alt text provided for this image

The generally accepted way to keep an electric cars battery in rude health is to keep the ‘State of Charge’ (how full the battery is) between 20% – 80%. The Kia has a setting which allows you to stop the car charging when it reaches a certain ‘fullness’ – say 80%.

The slower, AC charging method (i.e. from a wall plug rather than utilising a DC Fast charger at a service station or at the side of the road) is also a good way to keep the battery healthy, so plugging in the car each night to the granny charger in the garage will mean that the car gives many, many years of degradation free driving from the battery.

Creating Value with APIs

Octopus Energy offers a public, RESTful API to query how much the electricity will cost over the next day or so. Using this information, we can decide which times are cheapest to charge the battery.

Our existing process of charging the car’s battery can be made cheaper (hence adding value) by selectively choosing when to charge based on the information provided by the Octopus Energy API.

Missing functionality of the eNiro

The Kia eNiro really is a great car, it won the What Car ‘Car of the Year 2019’. For getting from A to B it is hard to fault the vehicle.

However, the Kia isn’t as flashy as Teslas and doesn’t offer anything useful in terms of remote connectivity to control or monitor charging. So, it is necessary to manually control the charging by physically switching the power socket on or off at the wall. This is a significant pain when you consider when the cheapest electricity is available (normally at select times between 12am – 6am).

No alt text provided for this image

Powering automation through APIs

If we are unable to get the car to control when it charges, we must try to automate another component in the system. Luckily through the universe of IOT devices we can control the plug socket’s delivery of power instead.

The Shelly 1PM is a small WIFI connected IOT device which can control and monitor the power delivery to a socket. It is small, supports the power requirements of charging the car and can be installed out of sight in the wall or socket innards. This is what is used to make up for the cars lack of remote charging control.

No alt text provided for this image

The Shelly 1PM offers its functionality out via (amongst other options) a RESTful API and this is what is utilised to control the power state of the socket during the unsocial hours.

Mashing APIs to create solutions

The process, that uses the Octopus Energy APIs to determine the cheapest times to charge and the Shelly 1PM API to control the socket, is an application written in c#. This runs on a low power Synology NAS (so a power-hungry PC doesn’t need to be on all night to orchestrate the process). In order to keep us informed of what is going on (or going to go on), the application uses a RESTful API from to send informational SMS messages.

The resultant fully automated API driven solution controls the charging of the car. The only manual element of the process is that the car must be plugged in when it is parked at the end of the day. This requires 20 seconds additional effort per day, but results in a ‘fully’ charged car at the start of the next day.

Icing on the cake

Electricity prices went negative on 8/12/19 and 9/12/19

An additional benefit of the Octopus Energy agile tariff is that the electricity prices can be priced negative. This means that on certain days, charging the car becomes a revenue stream. Therefore the system is programmed to utilise as many free or paid half-hours as it can.

The reason for negative prices is an excess of power in the grid. In Octopus Energy’s case, it is due to renewable sources creating more than the expected instantaneous demand. Negative prices will drive the demand up – If systems can be ‘smart’ and react to pricing.

Future improvements

Systems can usually be improved. The automated charging system is no different in this respect.

  • If the Kia supported querying battery state or charge remotely the systems algorithms could be further optimised to reduce the cost of charging – or to adjust the charging times/thresholds based on how empty the battery is.
  • An installed ‘home charger’ can charge at a faster rate than a granny cable. Using one which supports an API based control method could reduce the number of hours that charging happens which may also improve the Pence Per Mile figure.


Why is the process not more interactive? Why is the service not an API that can accept changes to its settings?

The car charging needs to work without interaction because it is not only the author who drives the car. Full autonomy has greater value in the long term when non-techy people must also use the system.  Each additional step introduced increases the chance of something not working causing the consumer to lose faith in the reliability of the system.

If you need to fill up the car after a long drive, how do you do that?

The external plug socket has a button installed which will turn the socket on or off. This is achieved by wiring the button to the Shelly 1PM’s switch input. Currently the on-off schedules determined by the service will still be enforced.

What data do you collect from the system?

The Shelly 1PM’s API reports the power usage per minute and has counters for total power usage (among others). Along with the cost metrics provided by the Octopus Energy API, the following metrics can be derived.

1.      Expected Cost of the charging session (Price per kWh x Expected charge rate)

2.      Actual Cost of the charging session (Price per kWh x Actual power usage)

3.      Average charge rate

As the car doesn’t report data back, some metrics are ‘guess-timated’ as part of the data logging

1.      Expected additional range

Does this only work for Electric Cars?

No, anything that relies on electricity that is ‘dumb’ could benefit from a similar system. An example may be turning on an immersion heater for hot water during the cheapest half-hours of the night (or day), or for use with electrical storage heaters.

There may be value in other applications, but the process cannot be negatively impacted by the sudden disconnection of the power as that is a key component of the cost optimisation process.

Where can I get the components of the system?

Car: Kia eNiro First Edition (, but any fully electric or Plug in hybrid vehicle would work.

Shelly 1PM: (

IP65 UK Plug Socket: Sourced from Amazon, but similar are available elsewhere.

Computer – Or any other NAS or computer which can reasonably be left on all the time without having a material impact on electricity usage. A low power system such as a Raspberry Pi would probably work well.

Octopus Energy: This UK supplier of green electricity can probably provide a supply for anyone in the UK. There may be other similar suppliers in other countries. The Agile tariff requires a ‘Smart’ electricity meter to be installed.

If you were to sign up to Octopus Energy using the referral link ( you will receive £50 credit.

Software: The service, written in Microsoft C# (dotnet 4.7/core), will be made freely available on Github when the author has had the opportunity to write some worthwhile documentation.