https://github.com/arindas/batnotify
Low battery notifier bash script and systemd service
https://github.com/arindas/batnotify
bash systemd-service systemd-timer
Last synced: 7 months ago
JSON representation
Low battery notifier bash script and systemd service
- Host: GitHub
- URL: https://github.com/arindas/batnotify
- Owner: arindas
- License: mit
- Created: 2020-02-22T16:17:04.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2024-09-14T12:40:38.000Z (over 1 year ago)
- Last Synced: 2025-07-15T02:34:17.152Z (7 months ago)
- Topics: bash, systemd-service, systemd-timer
- Language: Shell
- Homepage:
- Size: 10.7 KB
- Stars: 7
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# batnotify
[](https://opensource.org/licenses/MIT)

Notification script and systemd timer for triggering low battery notifications.
## How it works
We query battery state and charge percentage by reading from:
- `/sys/class/power_supply/BAT0/status`
- `/sys/class/power_supply/BAT0/capacity`
If the battery state is "discharging" and the current charge percentage is less than the
specified `${SAFE_BATTERY_LEVEL}`, we trigger a notification using `notify-send`
Now we run the script using a systemd service file. In order to repeatedly check
the status, we run a systemd timer for the corresponding service file.
## Installation
```sh
# clone the repo
git clone git@github.com:arindas/batnotify.git
cd batnotify/
# install the relevant files
cp ./batnotify ~/.local/bin
cp ./batnotify.service ~/.config/systemd/user
cp ./batnotify.timer ~/.config/systemd/user
# enable and start the systemd service timer
systemctl --user enable batnotify.timer
systemctl --user start batnotify.timer
```
## Uninstallation
```sh
# disable and stop the systemd service timer
systemctl --user disable batnotify.timer
systemctl --user stop batnotify.timer
```
## See also
- [`poweralertd`](https://sr.ht/~kennylevinsen/poweralertd/): Also handles power notifications for different wireless devices, in addition to main system power.