reagcz / IdeapadToolkit

A lightweight Lenovo Vantage alternative for the Ideapad Flex 5
MIT License
33 stars 2 forks source link

Ability to automatically switch to Conservation mode when a certain percentage of charge is reached #14

Open webdevs-pro opened 10 months ago

webdevs-pro commented 10 months ago

Hey @reagcz Thanks for useful app. Only one thing I really need is ability to automatically switch to Conservation mode for example on 80%. Or maybe it is possible to change Conservation mode rate from 60% to 80%?

reagcz commented 9 months ago

Sorry for taking so long to respond. Since the conservation mode is a firmware feature, changing the percentage it kicks in is not possible. You CAN change the max percentage in Lenovo Vantage, but this feature is only available on ThinkPads, not our puny IdeaPads.

As for the automatic switch, there's no way my program can tell when the battery reaches past a certain charge level. All I can do is to check the current percentage every few minutes. That would theoretically work without much of a performance impact and would be easy to implement.

The issue is, it would keep switching the charging on and off constantly, and I'm not sure that's good for the battery. But it's doable. Would this be an acceptable implementation @webdevs-pro?

mightytry commented 9 months ago

I think it would be enough to just switch it on at 80%. Because when I charge mine and turn protection on at 80% it keeps the current charge and is not discharging the battery, insted using the connected external power.

idwowrack commented 8 months ago

@webdevs-pro you could make a simple script to notify your self about the battery level limit (the bash code snippet). if it reached the top threshold battery level, then manually you switch mode to the conservative one.

`#!/bin/bash

TOP_THRESHOLD=84 BOTTOM_THRESHOLD=36 STABILITY_DURATION=3 # Number of consecutive checks to consider battery level as stable (adjust as needed) NOTIFIED=false

while true; do charger_status=$(WMIC Path Win32_Battery Get BatteryStatus | grep -oE '[0-9]+')

# 1 means discharging, 2 means charging, 3 means fully charged, 4 means low
if [ "$charger_status" -eq 1 ] || [ "$charger_status" -eq 2 ]; then
    battery_level=$(WMIC Path Win32_Battery Get EstimatedChargeRemaining | grep -oE '[0-9]+')

    if [ "$battery_level" -ge "$TOP_THRESHOLD" ] && [ "$charger_status" -eq 2 ]; then
        if [ "$NOTIFIED" = false ]; then
            NOTIFIED=true
            initial_level=$battery_level
            stability_counter=0
            powershell.exe -ExecutionPolicy Bypass -File "./notify.ps1" -Title "Battery Level" -Message "Battery level has reached at the top threshold and please enable the conservative mode via Lenovo Vantage >> Device: Power menu." -AppLogoPath "C:\Users\LENOVO\OneDrive\Pictures\is-it-legal.png"
        fi

`

webdevs-pro commented 8 months ago

Hey @idwowrack, thanks! I made similar thing but using AutoHotKey script and PowerBattery.dll. If charge reached 75% then script will switch mode to conservation and if battery level is below 70% it will switch to normal.

SetTimer, Tick, 10000
return

Tick() {
   batteryLevel := GetBatteryLevel()
   mode := GetMode()

   if (batteryLevel > 75 && mode != "Conservation") {
      RunWait, powershell.exe -Command "Set-Location -Path '%A_ScriptDir%'; Set-LenovoChargingMode Conservation",, Hide
      ShowBatteryStatus()
   } else if (batteryLevel <= 70 && mode != "Normal" && mode != "Rapid" ) {
      RunWait, powershell.exe -Command "Set-Location -Path '%A_ScriptDir%'; Set-LenovoChargingMode Normal",, Hide
      ShowBatteryStatus()
   }
}

This is part of my script

chikatambun commented 1 month ago

Looks like more promising using AHK for auto mode switching, @webdevs-pro Could you gist the step by step for using the autoscript ?