You are not logged in.

#1 2012-03-31 21:26:27

anti-destin
Member
Registered: 2009-02-14
Posts: 234

[solved] creating low battery warnings

i use i3 as my window manager, and i'd like to create some low battery warnings. i have laptop-mode-tools and acpid installed.

what's the best way to generate low battery warnings? i was thinking of simply running i3-nagbar with a message when the battery reaches a certain threshold.

Last edited by anti-destin (2012-04-03 20:37:55)

Offline

#2 2012-03-31 21:32:33

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

Re: [solved] creating low battery warnings

I just use a cron job to do a check every five minutes and notify if there is less than 15 minutes of charge left

#!/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

Offline

#3 2012-04-01 04:02:36

stlarch
Member
From: hell
Registered: 2010-12-25
Posts: 1,265

Re: [solved] creating low battery warnings

Heh. I have a terrible habit of letting the battery run out. I had a script where it changes colors (to the brightest and most annoying color that you can't possibly miss) when it got low and I still let it run out. I was thinking sound would be the best warning? Maybe a sound recording saying something like "hey dumbass, your battery is getting ready to run out". Has anybody else done anything like that? tongue I guess a popup would be effective too.

Offline

#4 2012-04-01 04:23:14

/dev/zero
Member
From: Melbourne, Australia
Registered: 2011-10-20
Posts: 1,247

Re: [solved] creating low battery warnings

Please ensure you stfw before starting new threads. It's not like this hasn't been talked about before.

Offline

#5 2012-04-01 10:16:56

anti-destin
Member
Registered: 2009-02-14
Posts: 234

Re: [solved] creating low battery warnings

thanks for the replies.

/dev/zero: yes, i read that thread. that's why i created this one. i was wondering what the best way was.

what i ended up doing was the following. i created two files:

/etc/acpi/events/lowbattery:

event=battery.*
action=/etc/acpi/actions/lowbattery.sh %e

/etc/acpi/actions/lowbattery.sh:

#!/bin/bash
#
# low battery warning
#

BATTERY=/sys/class/power_supply/BAT0

REM=`grep "POWER_SUPPLY_CHARGE_NOW" $BATTERY/uevent | awk -F= '{ print $2 }'`
FULL=`grep "POWER_SUPPLY_CHARGE_FULL_DESIGN" $BATTERY/uevent | awk -F= '{ print $2 }'`
PERCENT=`echo $(( $REM * 100 / $FULL ))`

if [ $PERCENT -le "82" ]; then
  /usr/bin/i3-nagbar -m "Low battery"
fi

acpid is running, and i have already run chmod on the script.

but for some reason, nothing happens. did i miss something?

Offline

#6 2012-04-01 12:26:53

/dev/zero
Member
From: Melbourne, Australia
Registered: 2011-10-20
Posts: 1,247

Re: [solved] creating low battery warnings

anti-destin wrote:

/dev/zero: yes, i read that thread. that's why i created this one. i was wondering what the best way was.

what i ended up doing was the following. i created two files:
<snip>...</snip>

acpid is running, and i have already run chmod on the script.

but for some reason, nothing happens. did i miss something?

You should have put all this information in the opening post. Please consider the link in the Forum Guidelines to ESR's "How to ask questions the smart way".

I'm not sure why you've done things the way you have, it's totally different to the method described in the pre-existing thread. If you're following some other how-to, even if it's the wiki, you should link to it. Again, cf ESR.

I haven't tried my method with i3, but I expect all you need to do is modify the provided script to call i3-nagbar, instead of espeak.

Offline

#7 2012-04-03 20:37:40

anti-destin
Member
Registered: 2009-02-14
Posts: 234

Re: [solved] creating low battery warnings

to be fair, i didn't come across all this until long after i first posted. and, in any case, i was hoping to understand all the different methods, e.g., acpid, cron, your script, laptop-mode-tools, etc., and the merits and deficiencies of each.

i found some information here and here.

in any case, i just went ahead and created a cronjob. i'm marking this as solved.

Offline

Board footer

Powered by FluxBB