Automatic sleep on idle computer at specific battery level

1

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.

labeebahmad32

Posted 2014-08-02T09:34:48.153

Reputation: 11

Did you find any way to make it work? – pilau – 2014-09-24T00:52:40.857

Answers

1

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 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

pilau

Posted 2014-08-02T09:34:48.153

Reputation: 183

Ill let u know if it works for me.. – labeebahmad32 – 2014-09-25T06:41:37.237

@labeebahmad32 great - let me know :) – pilau – 2014-09-25T10:53:41.833

@labeebahmad32 did it work out for you eventually? – pilau – 2015-01-19T12:05:02.607