The blog

Annoyance on low battery

Laptops should be a bit annoying when they are low on battery. Otherwise, I will not realise it until it’s too late, and my computer will turn off in the middle of whatever I was doing.

Proper linux Desktop Environments already do this, but since I am running the Awesome window manager with a custom config, I only get what I add myself.

My solution is as follows. First, the annoyance script:


#!/usr/bin/env python3
import subprocess
import math
import sys

with open('/sys/class/power_supply/BAT0/status') as f:
    status =

if status in ["Charging\n", "Full\n"]:

with open('/sys/class/power_supply/BAT0/energy_full') as f:
    total = int(

with open('/sys/class/power_supply/BAT0/energy_now') as f:
    now = int(

perc = math.floor(now / total * 100)
if perc < 10:["notify-send",
                    "-t", "0",
                    "-i", "/usr/share/icons/Numix/24/status/gpm-battery-020.svg",
                    "-u", "normal" if perc > 5 else "critical",
                    f"Low battery! {perc}%"])

Depending on the laptop, energy_now and energy_full are replaced by charge_now and charge_full. And notify-send must be installed.

Then we could run it on login on a loop with a sleep, but I just have systemd call it every 2 minutes:


Description=Notify of low battery



Description=Check battery status every 2 minutes


$ systemctl --user enable --now battery.timer

Got any comments? Send me an email: