battery warning

This commit is contained in:
Rachel Lambda Samuelsson 2024-03-12 11:59:27 +01:00
parent 0da2b3060f
commit 02d29fb799
2 changed files with 48 additions and 0 deletions

View File

@ -534,4 +534,51 @@ in rec {
enable = true;
};
};
systemd.user= {
timers = {
battery-check = {
Unit.Description = "Warn at low battery levels";
Timer = {
OnBootSec = "1min";
OnUnitActiveSec = "30s";
Unit = "battery-check.service";
};
};
};
services = {
battery-check = {
Unit.Description = "Warn at low battery levels";
Service = let batMon = pkgs.writeShellScript "botMon" ''
PATH="$PATH:${pkgs.lib.makeBinPath [
pkgs.acpi
pkgs.dunst
pkgs.gnugrep
pkgs.gawk
pkgs.systemd
]}"
acpi -b | grep "Battery 0" | awk -F'[,:%]' '{print $2, $3}' | {
read -r status capacity
if [ "$status" = Discharging -a "$capacity" -lt 2 ]; then
dunstify -u critical -a batMon \
-h string:x-dunst-stack-tag:batMon \
-h int:value:"$capacity" "Battery Critical: ''${capacity}%
Hibernating"
sleep 5
systemctl hibernate
elif [ "$status" = Discharging -a "$capacity" -lt 5 ]; then
dunstify -u critical -a batMon \
-h string:x-dunst-stack-tag:batMon \
-h int:value:"$capacity" "Battery Critical: ''${capacity}%"
fi
}
'';
in {
ExecStart = "${batMon}";
};
};
};
};
}

View File

@ -17,4 +17,5 @@ systemctl restart --user dunst
systemctl restart --user picom
systemctl restart --user polybar
systemctl restart --user network-manager-applet
systemctl restart --user battery-check.timer
exec berry