Laptop Charging Automation

Jephin Davis
5 min readJun 10, 2023

--

Intro Image

In today’s fast-paced world, laptops have become an essential part of our lives. Whether it is for work, study or entertainment, we rely heavily on our laptops to get things done. However, one of the most common problems that laptop users face is the need to constantly monitor their laptop’s battery life and charge it when necessary. Did you know that keeping your charger on even after the battery is fully charged (100%) or letting your battery drain below 20% could impact the battery health?

This is where the need for automating laptop charging comes in. Let me show you how easy is it to automate this process and save you the hassle of constantly checking your laptop’s battery life.

What you need:

Smart plug setup

If you are not familiar with smart plugs, A smart plug is a device that is inserted into a standard electrical outlet and allows you to control the power to that outlet remotely. This can be done through a smartphone app, voice assistant, or other smart home automation system. With a smart plug, you can turn on or off any device that is plugged into the outlet, set schedules for when the device should turn on or off, and monitor energy usage.

Let's configure our smart plug:

You need to add your smart plug to a smart home app. It doesn't matter what app you use to setup the smart plug, but make sure that once set up, the Alexa app is able to detect the new device. I recommend Alexa app because of its ability to run routines.

In this example, I am using the Smart Life app to setup the smart plug.

1. Connect the smart plug to power and wait for the indicator led to blink rapidly. If it's not blinking rapidly, you can press and hold the power button of the plug.

2. When the LED is blinking start the pairing process in the smart life app.

3. Create an account in smart life app and click on add (+) button to add the smart plug. Follow the instructions in the app to complete the setup.

4. Once the smart plug is added to smart life, we can link it with Alexa.

Enable Alexa Skills

1. Go to Alexa app and sign in with your amazon account. Under the skills section search for ‘Smart Life’ and use the same credentials to link the smart life account to Alexa.

2. Now search for IFTTT trigger skill

3. Enable the skill by logging in using your Alexa account credentials.

4. Alexa will now look for devices and after the search you will see three triggers. (IFTTTrigger-1, IFTTTrigger-2 and, IFTTTrigger3. For our automation, we only need two)

5. Create two routines that can work when these triggers are activated. Our routines should be able to switch on and switch off the smart plug connected through the Smart Life app based on the triggers.

6. For the first routine, when IFTTTrigger-1 is activated, set the Smart Plug to switch on.

7. For the second routine, when IFTTTrigger-2 is activated, set the Smart Plug to switch off.

Configure IFTTT

1. Create a free account in IFTTT. Free account can create up to 3 applets.

2. Create an applet. Under ‘If This’ section, search for webhooks.

3. Select the option ‘Receive a web request’ and type in an event name. For our purpose, we will name it as “low_battery”. This is the webhook that needs to be triggered when laptop charger needs to be switched on.

4. Under the ‘Then That’ section, search for Alexa actions by mkZense and login using your Amazon Alexa credentials.

5. Select the trigger IFTTTrigger-1 here. This applet will now trigger the smart plug on when the event name “laptop charger on” is received as web request.

6. Create another applet with same steps as 4–7, but with event name as “battery_charged” and IFTTTrigger-2 as action.

7. Click on the documentation for webhooks and take a note of the webhook key assigned to your account.

8. You now have two event URLs as below:

a. https://maker.ifttt.com/trigger/low_battery/with/key/<Your webhook Key>

b. https://maker.ifttt.com/trigger/battery_charged/with/key/<Your webhook Key>

Setting up Trigger

Now that we have web hooks created that can turn on the charger and turn it off, we need to configure when these actions need to happen.

You can use the below batch script to do the same:

@echo off
for /f "tokens=2 delims==" %%E in ('wmic path Win32_Battery get batterystatus /value') do (set "bs=%%E")
if %bs% == 1 for /f "tokens=2 delims==" %%E in ('wmic path Win32_Battery get estimatedchargeremaining /value') do (if %%E LEQ 30 (curl -X POST https://maker.ifttt.com/trigger/low_battery/with/key/<your webhook key>))
if %bs% == 2 for /f "tokens=2 delims==" %%E in ('wmic path Win32_Battery get estimatedchargeremaining /value') do (if %%E GEQ 85 (curl -X POST https://maker.ifttt.com/trigger/batt_charged/with/key/<your webhook key>))

Save the batch script and schedule it to run every 10 minutes or 20 minutes using task scheduler.

Make sure to use the system user for this scheduled task, so that the task runs even if you are away.

Now, connect your laptop charger to smart plug and connect laptop to charger and forget everything and let the automation take care of everything else! Enjoy!

Alternate Method: Changes in BIOS

This method is strictly for personal laptops and not to be tried on your office/work laptops.

1. Switch on your laptop and enter the BIOS settings page by clicking any of the keys F10, F11, F12. You might have to experiment a bit here as the hotkey for BIOS settings vary from brand to brand and models to models.

2. Once you are in the BIOS settings, search for battery settings and look for options to set the percentage to start the charging and stop the charging.

3. This feature is not available all laptops. The name of this feature might be different from brand to brand.

--

--