You are not logged in.

#1 2013-05-07 20:11:14

Leduck
Member
From: Brazil
Registered: 2011-04-25
Posts: 48
Website

Shutdown on low battery [SOLVED]

What the packages needed for the gnome properly shutdown the laptop when on low battery. I've read the wiki and set up a rule in udev, but it did not work, it seems, there is a trigger for the event. Already installed acpid and neither worked. Have to configure something?

I do not want large configurations, now my battery lasts around 3 hours without any effort, I just really want to shutdown on low battery.

Thanks.

EDIT: Analyzing various forum posts, I realized that neither acpid_listen nor udevadm - monitor receiving a trigger for battery. Anyone have any suggestions?

Last edited by Leduck (2013-06-01 13:10:47)

Offline

#2 2013-05-08 10:37:45

valr
Member
From: Belgium
Registered: 2012-01-08
Posts: 62

Re: Shutdown on low battery [SOLVED]

Don't you have an option for that in gnome power manager (package gnome-power-manager) ?

Offline

#3 2013-05-08 10:56:52

vacant
Member
From: downstairs
Registered: 2004-11-05
Posts: 816

Re: Shutdown on low battery [SOLVED]

I used to have this as a cronjob just to warn me, so you could modify it to shutdown instead

#!/bin/bash
BATTINFO=`acpi -b`
if [[ `echo $BATTINFO | grep Discharging` && `echo $BATTINFO | cut -f 5 -d " "` < 00:15:00 ]] ; then
    DISPLAY=:0.0 /usr/bin/notify-send "low battery" "$BATTINFO"
fi

I don't know if "acpi -b" gives the same format for all devices, mine is an Acer 5742Z.

Rather than acpi, I'd probably use info from  /sys/class/power_supply/BAT0/* if I was using it now.

Offline

#4 2013-05-08 11:38:47

Leduck
Member
From: Brazil
Registered: 2011-04-25
Posts: 48
Website

Re: Shutdown on low battery [SOLVED]

This is a good solution and I had thought of it, what I would like to understand is that when I wore a distribution based on Debian my computer shut down properly and not now, is it any compilation flag kernel or is some function that was withdrawal, as the Arch uses more current versions of Debian, which anyway is strange, since newer versions should be more functional. For this reason I asked about the packages, as did a clean install might not have installed something necessary.

Offline

#5 2013-06-01 13:09:29

Leduck
Member
From: Brazil
Registered: 2011-04-25
Posts: 48
Website

Re: Shutdown on low battery [SOLVED]

I would like to share the script I did to solve this problem by following the idea of the vacant, thanks friend.

#!/usr/bin/bash

BATTERY_CAPACITY=$(cat /sys/class/power_supply/BAT0/capacity)
BATTERY_STATUS=$(cat /sys/class/power_supply/BAT0/status)

SHUTDOWN_WITH=3

NOTIFY_TITLE="Bateria Fraca"
NOTIFY_ICON=battery_empty
NOTIFY_MESSAGE="Seu computador será desligado em 1 minuto."

WM=gnome-shell
WMPID=$(pidof ${WM})
WMUSER=$(ps -e -o user,comm | grep ${WM} | cut -f1 -d " ")
DBUS=$(egrep -z 'DBUS_SESSION_BUS_ADDRESS|DISPLAY' /proc/${WMPID}/environ | sed -r -e 's/(.)DBUS_/\1 DBUS_/' -e 's/(.)DISPLAY/\1 DISPLAY/')

if [[ $BATTERY_CAPACITY -le $SHUTDOWN_WITH && $BATTERY_STATUS = "Discharging" ]]; then
	/bin/su ${WMUSER} -c "${DBUS} notify-send --urgency=critical --hint=int:transient:1 --icon $NOTIFY_ICON '$NOTIFY_TITLE' '$NOTIFY_MESSAGE'"
	sleep 60s
	BATTERY_STATUS=$(cat /sys/class/power_supply/BAT0/status)
	if [[ $BATTERY_STATUS = "Discharging" ]]; then
		systemctl poweroff
	fi
fi

After I saved in /usr/bin as battery_monitor and scheduled cron with the following line

*/2 * * * * /usr/bin/battery_monitor

I hope it is useful.

Last edited by Leduck (2013-06-20 01:30:28)

Offline

#6 2013-06-01 14:25:51

vacant
Member
From: downstairs
Registered: 2004-11-05
Posts: 816

Re: Shutdown on low battery [SOLVED]

Does that work?

If you see the "one minute warning" and plug the charger in, BATTERY_STATUS is still set to "Discharging" so it will always shutdown. You need to read BATTERY_STATUS again after "sleep 60".

edit: probably also need == rather than =

Last edited by vacant (2013-06-01 14:32:24)

Offline

#7 2013-06-01 14:35:27

Leduck
Member
From: Brazil
Registered: 2011-04-25
Posts: 48
Website

Re: Shutdown on low battery [SOLVED]

This change I did yesterday and had not tested right, I'm sorry and thank you for warning.

Already corrected the code in the post.

Once he is improving, updating here and I will accept suggestions.

Last edited by Leduck (2013-06-01 14:36:33)

Offline

Board footer

Powered by FluxBB