You are not logged in.

#1 2018-09-14 18:40:48

burafino
Member
From: London
Registered: 2009-12-07
Posts: 19
Website

Critical battery hibernation issue

I'm trying to get my Lenovo Ideapad 510S to hibernate on critical battery.

The udev rule approach detailed in the wiki does not apply as the battery does not seem to send notifications, although the /sys/class/power_supply/BAT1/alarm file is non-zero and corresponds to roughly 10% of the value in /sys/class/power_supply/BAT1/energy_full. Also, Gnome Shell does display 'Battery Low' and 'Battery Critically Low' warnings at 10%, 3% and 2% capacity, and the latter two even say the computer will hibernate, but it just abruptly shuts down instead.
I couldn't find how Gnome knows the state of the battery to display a notification, so I resorted to the cron script approach detailed in the wiki.
This one seems to work, albeit with one exception - acpi sees my wireless mouse's battery and incorrectly reports it as 0%. Here too Gnome seems to know better, since it correctly shows me alerts when my mouse battery is low.
But the acpi script hibernates my system the first time cron runs it, no matter how much charge the laptop battery has.

$ ls /sys/class/power_supply/
ACAD  BAT1  hidpp_battery_0

$ acpi -b
Battery 0: Discharging, 0%, rate information unavailable
Battery 1: Discharging, 62%, 03:37:26 remaining

$ sudo acpi -b | awk -F'[,:%]' '{print $2, $3}'
 Discharging  0
 Discharging  62

Since acpi does not seem to have a way of displaying one particular battery, I added grep into the command chain, like so:

$ sudo acpi -b | grep "Battery 1" | awk -F'[,:%]' '{print $2, $3}'
 Discharging  62

This works fine while the mouse is online. But if it's disconnected in the process or even switched off during or before computer sleep, acpi no longer sees this battery and renames the laptop battery "Battery 0", so the grep rule stops working.

How do I make a rule that would always keep track of the right battery, or better still, how do I tap into what makes Gnome show correct notifications for correct batteries at correct times? Ideally, I want to trigger hibernation at the 2% threshold, when Gnome shows a critical battery level notification saying it will hibernate immediately.

Last edited by burafino (2018-09-17 17:52:05)

Offline

Board footer

Powered by FluxBB