sphaero / sphaebian

Debian Based Distro for people like me.
GNU General Public License v2.0
0 stars 0 forks source link

hibernate on low battery #12

Open sphaero opened 5 years ago

sphaero commented 5 years ago

as we've installed as little as possible there's nothing responding to low battery situations.

best aproach is some timed script?

sphaero commented 5 years ago

.config/systemd/user/low-battery.service

[Unit]
Description=Check for low battery and hibernate if too low

[Service]
ExecStart=%h/bin/low-battery.sh

[Install]
WantedBy=multi-user.target

.config/systemd/user/low-battery.timer

[Unit]
Description=Runs every 5 minutes - needed by low-battery.service

[Timer]
OnCalendar=*:0/5
Persistent=true     

[Install]
WantedBy=timers.target

~/bin/low-battery.sh

#!/bin/sh
STATUS=`cat /sys/class/power_supply/BAT0/status`
CAPACITY=`cat /sys/class/power_supply/BAT0/capacity`

if [ "$STATUS" = Discharging -a "$CAPACITY" -lt 5 ]; then
    notify-send -c critical "Hibernating" "Hibernating due to low battery" &> /dev/null
    logger "Hibernating due to low battery" &> /dev/null
    systemctl hibernate
fi