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:
![Conditions for idle trigger](../../I/static/images/010cd0bb5a6edb505f01ffc8f53e3f5bbf2a882394ac943a03eedea9411ee809.png)
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
Did you find any way to make it work? – pilau – 2014-09-24T00:52:40.857