Categories
Projects

Auto limit EV charge to 80%

Why would you create software to stop charging your car at 80% ?
Because we both work from home, usage of our electric car is very irregular. On some days we use the car for several short trips, while at other times the car is not used several days in a row. No predictable daily commute along the very same route for us. Because of this usage pattern, or lack of it, we like to top up the battery to 80% at the end of each day when we used the car. That way the vehicle is ready for its next use whenever that may be. We attempt not to charge it to 100% because I dislike the situation where the car is fully charged and not used for several days. Although research and opinions differ on whether this is harmful for the battery’s longevity, I choose to take a conservative approach on this.

Early models of the Nissan Leaf (2011-2012, and up to about 2014 for UK models) had a build-in option to set a charge-timer with a limit to 80%. Just plug it in and the car itself would stop the charging process once the battery reached 80% SOC (state of charge). As ours is a later model (2016 30kwh Japanese import), this option is not available to us. Neither is the CarWings or Nissan Connect app operational in New Zealand.Over time I trialed various methods which improved with each iteration, leading up to the fully automatic limit system that we currently use.

Note, in the descriptions below, the solution first becomes more and more complicated, until it gets simplified again in the current iteration. Skip ahead to the end if you wish.

Estimate time needed and set an alarm

When we just bought the car, it only took a couple of days to figure out that when plugged in via our slow 3 pin EVSE (Electric Vehicle Charging Equipment, basically just a charge cable with some safety electronics build in), the charge would increase by about 6% per hour. So whenever we came home, we would do a rough calculation of the time needed. For example, to charge from 58% to 80% is a 22% increase, which would take a bit less than 4 hours. Set an alarm clock on my mobile phone and plug-out when the alarm rings. That worked pretty well most of the time, unless I got distracted after the alarm and forgot to plug out. Or unless we came home after 11pm.

OVMS for feedback while charging

After a couple of months I ordered an OVMS module online. Open Vehicle Monitoring System is an open source project that has developed the hardware and software to monitor various brands and models of electric cars. The module connects to the car via the OBD-II diagnostics port (like a LeafSpy dongle). A short cable allows the module to be neatly and safely tucked away in the foot-well on the driver’s side. The module can be ordered ready to go for about NZ $300, or can be soldered together yourself.

Every couple of seconds the module sends status information about the car to a central server. It will either do this using our own WiFi if we are parked at home, or on the road via a mobile phone sim-card inserted into the module (data use is low, I use a prepaid Vodafone sim which I need to top-up with NZ $20 once a year).

A mobile phone app on IOS and Android allows you to see the status of your car. So once the alarm goes off, or if I don’t trust my estimated stop time, I can use my phone to check on charging progress.

For some brands and models OVMS allows you to remotely start and stop charging using the app. Unfortunately, at that point that was not possible for the Nissan Leaf, hence we still have to go to the car to unplug (remark: this changed in OVMS in 2022).

Note that the OVMS module has many more features that are outside the scope of this blog.

 

Evnex charge-point

About half a year ago our electricity network provider announced they were going to do a test to learn more about the charging habits of electric vehicle owners. They installed a free charge-point (an Evnex R-Series) on our property in exchange for letting them inspect our electricity usage for half a year.

Although the charge-point is pretty smart, it has no way of knowing what kind of car it is charging and how far the charge has progressed. This is a limitation of the type-1 and type-2 charge methods (cable, hardware, protocol, etc). On the faster CHAdeMO chargers this information is provided by car to the charge-point, but those chargers come with a hefty price tag.

However, Evnex does provide an app that allows to monitor the charge-point. It allows you to see the history of charging sessions and whether a charge session is in progress right now. Also, the app has a button to remotely stop the current charge session.

While we still need to make an estimate of the required time and set an alarm, we can now remotely verify and monitor charge progress using OVMS, and then stop charging via Evnex without having to go outside to unplug the car.

Automatic stop

Other than the app, Evnex does not provide any method to view the status of the charge-point. They have indicated they might provide an API (Application Programming Interface, a way for software to talk to it) at some point in the future but haven’t given a date for it.

Determined to not being stopped by that inconvenience, I spend a weekend to reverse-engineer the communication to and from the Evnex app.

I had already developed software to be able to talk to the OVMS Server to extract information about our own car. Combined with the knowledge of how the Evnex app communicated I was now ready to develop a fully automated solution to charge to 80%.

The full solution works like this:

  • My software is continuously running to monitor our car via the OVMS module. At first I used a spare pc in my home office for this; it was running anyway to monitor our solar panels. Later I moved both these functions onto a tiny Raspberry Pi computer (about NZ $ 70).
  • When it detects the vehicle is charging it will also check whether the charge-point is currently charging something. Furthermore, it will determine whether car and Evnex charge-point are in close proximity (both can detect their GPS-location). If so, the software assumes the charge-point is currently charging our car.
  • When charging reaches 80%, a stop command is issued to the Evnex charge point. Charging will stop without needing to unplug.

This solution has been up and running reliably from 2020 to 2022.

Current, OVMS only solution

Since a software update in the beginning of 2022, the OVMS module now has out-of-the-box support to monitor and stop the charge at a specified charge level. This can be configured via ‘features’ page in the OVMS mobile app.

So no more need for the Rasberry Pi and the interface into the Evnex charger. This solution now will work with any charger. All you need is an OVMS module intalled in your car.

Addendum: Open source

I often build my own programs using software components that are generously made available by other developers as open source. To give back to this community, I decided to share key parts of my earlier solution in Github. Since I like to develop using C#, all are based on .NET Core:

For anyone interested in adding an OVMS module to their car, you would need the following components:

And a comprehensive video of the setup can be found here (the last 10 minutes are specific to the Kia e-Niro).