Can I create a task in task scheduler that starts when a specific battery level reaches on idle computer to go to sleep? Windows does give option to make computer to go to sleep at specific battery level but it doesnt care if laptop is idle or not.
I got it!
I made a scheduled task that triggers when the computer is idle, and repeatedly runs a batch file that checks if the battery is discharging and how many percent it carries.
If the battery is discharging (ie, laptop is not plugged to mains), and the battery is charged 25% or less, it will immediately put the computer to sleep (or hibernate, if it's turned on already).
The task is set to repeat itself (ie, run the batch file) every 5 minutes indefinitely. Also, make sure you set the following conditions:
I based my batch script on
battstat.bat from here: http://www.robvanderwoude.com/wmiexamples.php
You will find my script below.
@ECHO OFF :: Localize variables SETLOCAL :: Use WMI to retrieve battery status information FOR /F "tokens=* delims=" %%A IN ('WMIC /NameSpace:"\\root\WMI" Path BatteryStatus Get PowerOnline^,RemainingCapacity /Format:list ^| FIND "="') DO SET Battery.%%A FOR /F "tokens=* delims=" %%A IN ('WMIC /NameSpace:"\\root\WMI" Path BatteryFullChargedCapacity Get FullChargedCapacity /Format:list ^| FIND "="') DO SET Battery.%%A :: Calculate runtime left and capacity SET /A Battery.RemainingCapacity = ( %Battery.RemainingCapacity%00 + %Battery.FullChargedCapacity% / 2 ) / %Battery.FullChargedCapacity% :: Display results IF /I "%Battery.PowerOnline%"=="FALSE" ( IF %Battery.RemainingCapacity% LEQ 25 ( Rundll32.exe Powrprof.dll,SetSuspendState Sleep ) ) GOTO:EOF :: End localization IF "%OS%"=="Windows_NT" ENDLOCAL