battery notifier
Some checks failed
Activate Homelab Configuration / rebuild (push) Failing after 9s

This commit is contained in:
Satria 2026-03-20 06:49:51 +07:00
commit 028a370299

View file

@ -1,4 +1,4 @@
{ pkgs, resume-dev, ... }: { { pkgs, username, resume-dev, ... }: {
powerManagement.powertop.enable = true; powerManagement.powertop.enable = true;
services = { services = {
@ -10,6 +10,18 @@
echo 85 > /sys/class/power_supply/BAT*/charge_control_end_threshold || true echo 85 > /sys/class/power_supply/BAT*/charge_control_end_threshold || true
''}" ''}"
''; '';
cron = {
enable = true;
systemCronJobs = [
"* * * * * ${username} bash -x ${pkgs.writeShellScript "low-battery-notifier" ''
BAT_PCT=`${pkgs.acpi}/bin/acpi -b | ${pkgs.gnugrep}/bin/grep -P -o '[0-9]+(?=%)'`
BAT_STA=`${pkgs.acpi}/bin/acpi -b | ${pkgs.gnugrep}/bin/grep -P -o '\w+(?=,)'`
echo "`date` battery status:$BAT_STA percentage:$BAT_PCT"
test $BAT_PCT -le 30 && test $BAT_PCT -gt 15 && test $BAT_STA = "Discharging" && DISPLAY=:0.0 ${pkgs.libnotify}/bin/notify-send -c device -u normal "Low Battery" "\$\{BAT_PCT}% remaining."
test $BAT_PCT -le 15 && test $BAT_STA = "Discharging" && DISPLAY=:0.0 ${pkgs.libnotify}/bin/notify-send -c device -u critical "Low Battery" "Shutdown at 10%."
''} > /tmp/cron.batt.log 2>&1"
];
};
upower = { upower = {
enable = true; enable = true;
percentageCritical = 15; percentageCritical = 15;