Hi Shérab

Shérab schrieb am 13.01.2017, 13:38 +0100:
>Has someone successfully set-up a low battery alert system that does not
>depend on a graphical desktop, please?
Yes, I do have written a script on my own. It's executed with cron, the crontab
looks like this:

* * * * * python3 /home/user/bin/akkuleer.py

The akkuleer.py (batter empty) is attached. It basically requires python3, aplay
and a file ~/.sounds/battery_low.wav.

Additional plus for this script is, that it can cope both with laptops with one
or two batteries (the newer Thinkpad have two).

HTH
Sebastian
-- 
Web: http://www.crustulus.de (English|Deutsch)  | Blog: 
http://www.crustulus.de/blog
FreeDict: Free multilingual dictionaries - http://www.freedict.org
Freies Latein-Deutsch-Wörterbuch: http://www.crustulus.de/freedict.de.html
#!/usr/bin/env python3
# vim:set expandtab sts=4 ts=4:

import subprocess, re, os, sys, time
from functools import reduce

proc=subprocess.Popen(['/usr/bin/acpi'], stdout=subprocess.PIPE)
data = proc.communicate()[0].decode(sys.getdefaultencoding())
batteries = []
for line in data.split('\n'):
    if line == '':
        continue
    try:
        matched = re.search(
                'Battery \d+:\s+(Discharging|Charging|Unknown|Full), (\d+)%.*',
                line)
        matched = int(matched.groups()[1])
    except (AttributeError, ValueError):
        os.system('espeak -v de --stdout -s 250 "Konnte keine Batterieinformationen ermitteln" | aplay -q -')
        raise
    batteries.append(matched)

under_7_percent = all(i < 7 for i in batteries)
if under_7_percent:
    for i in range(0, 5):
        os.system('aplay -q ~/.sounds/battery_low.wav &> /dev/null')
        time.sleep(2)

Attachment: signature.asc
Description: PGP signature

_______________________________________________
This message was sent via the BRLTTY mailing list.
To post a message, send an e-mail to: [email protected]
For general information, go to: http://brltty.com/mailman/listinfo/brltty

Reply via email to