You are not logged in.

#1 2017-07-16 22:08:45

kols
Member
From: Norway
Registered: 2017-07-16
Posts: 21

Battery-alarm and flashing LEDs

Hello, all!

If you're like me, and you're using a Lenovo T410i, you're probably familiar with the fact that this otherwise excellent laptop does not have a visible battery indicator on the front. There is, however, a battery indicator on the back of the screen, along with a little half moon symbolising that the laptop is in sleep. If you're in a tty, running a fullscreen application or you're away from the laptop, you'd want to have some audiovisual way of knowing that your laptop is about to shutdown.

Enter my little script. It relies on beep, and having access to a few system files to alter the state of the LEDs.

#!/bin/bash

while true;
  do
    sleep 10 #checking every 10s shouldn't be much of a task

    #Get values
    charging=$(acpi -b | awk '{print $3}' | tr -d [:punct:])
    battperc=$(acpi -b | awk '{print $4}' | tr -d [:punct:])

    if [ ${battperc//%,} -lt 15 ]; #I set my low battery limit to 15%
      then
        if [ "$charging" == "Charging" ];
          then
            echo "0 on" > /proc/acpi/ibm/led #Getting the powerbutton to be static
          else
            #Make the laptop sound annoyed and distressed
            beep -f 1000 -l 100 -n -f 700 -l 100 -n -f 400 -l 200
            echo "0 blink" > /proc/acpi/ibm/led #Getting the powerbutton to blink
        fi
      elif [ $battperc -gt 20 ];
        then
          echo "0 on" > /proc/acpi/ibm/led
    fi  
done

I've put this script in /usr/local/bin/lowbattled

It's started at boot, by adding the following in your crontab:

@reboot /usr/local/bin/lowbattled

Well, there you have it. The powerbutton now blinks when the battery is low.

EDIT: Changed how the two variables battperc and charging are aquired. Now everything that isn't alphanumeric is removed from those strings.

Last edited by kols (2017-07-16 23:40:47)

Offline

#2 2018-01-09 10:46:15

vinzv
Member
Registered: 2017-09-12
Posts: 186
Website

Re: Battery-alarm and flashing LEDs

I don't like those LED's and covered them at my x220 with black tape (both on the inside and on the cover).
So you're script is indeed very useful - thanks!

Last edited by vinzv (2018-01-09 10:46:29)

Offline

Board footer

Powered by FluxBB