# [HOW TO] Smart battery charging (E-bike)

Because of some health issues I got myself an emtb (electric mountainbike).

Lots of people, and manufacturers, advocates for keeping the battery at around 30-80% charge for storing. And to only top it up to 100% before a ride.

It makes sense to care for the battery as it is one of the most expensive parts of the bike and obviously I started thinking of how to make it smart.

So I created 4 different advanced flows to add 25%, 50%, 75% and 100% charge. I will show the 50% flow as the others are the same except the calculation.

If I return from a ride and have 30% battery left, and know I´m not going to ride for a while - I just start the 50% flow to top it up to 80%.

Tips for improvements are welcomed!

What is needed?:

• A smart plug or relay with metering to plug the charger to (I am using a Shelly Plus 1PM)

How the flow works - Start
You can use your preferred trigger to start the flow.

1. I use a start block and favorite the flow so I can voice start it from the Google speaker in my garage.

2. When the flow is started it takes a reading from the meter and stores it in a Variable (To use later in step 7 for calculating how much is charged).

3. It then sets a Yes/No variable to Yes. This variable is to keep track of if the socket is used for charging or something else (see step 6). Without it, the shut off trigger later on would shut the socket off when using the socket for other things.

4. At the same time it turns the socket on that the charger is plugged into.

How the flow works - Stop
Next som calculations are needed to stop charging at the right time.
The battery for my bike is 720Wh capacity, so if I want to top it up with 50% that is 360Wh.

1. The trigger for stopping the charging is that the meter of the socket changed.

2. It then continues by checking if I´m using the socket to charge the battery (the variable that was set in step 3).

3. If the variable in step 6 is yes it continues to check, with Logic, if it has charged 360Wh.
This happens by comparing the current meter with the Variable from step 2 plus 360Wh.
The Shelly meter uses Kwh and that is why I add 0,36.

4. When 360Wh has been added it:

• Turns the socket off.
• Sets the charging Variable to No
• Creates a timeline message saying the charging is done as well as how much it charged with and how much the cost for the electricity was. The electricity cost is achieved by pulling the current price from my provider and calculating with how much electricity was used during the charge.

It depends on the ebike brand. My giant (yamaha) pedelec has a smart charger which keeps the battery already at the best charge. So in that case i would not mess around with the charge curve. For safety reasons i have a large fused relay (contactor) which is controlled by a zwave (aeotec) switch where i measure current. My flow switch of the charge current when its 0 for a while.

What do you mean it keeps the battery at the best charge? Doesn´t it charge full every time?

For my 100% charging flow I also use the current to switch off the socket when it reaches zero. Just when I don´t want to fully charge that I use the amount of Wh.

My charger has 2 modes, 100% and 60% and charging speed and mode is also depending on environment temperature. When the bike is not used for some time it automatic decreases the charge to 60% if its connected. Homey controls that as well (relay)

Ok that´s nice. No such thing on my charger so that´s why I needed Homey to do i for me.