Skip to main content

A Python script that sends notifications about the battery's status.

Project description

batnotifsd — Battery notifications daemon

What

This is a Python script that sends notifications about the battery's status (charger plugged in/unplugged, low/critical battery levels).

It's useful for window managers where you don't get this functionality out of the box like in a desktop environment.

Why

I wrote this because I simply could not find anything else that did the job 100% right. The internet is full of shell scripts that just tap into /sys/class/power_supply and take info from that in a while true loop with a sleep, most don't even autodetect the laptop's battery and they make you set a variable for the right battery for you, or, even worse, manually edit the shell script to put it in.

How

This Python script uses the pydbus library to get information directly from UPower through DBus, and then send it back through DBus using the org.freedesktop.Notifications bus, all in a GLib loop.

Also, it automatically detects the first battery that classifies as a laptop battery[^1].

Usage

To start the daemon, simply use:

$ batnotifsd

You probably want to add it to the autostart of your window manager, check with your WM's documentation for that.

Packages

NixOS

A derivation for this package is available inside my Nix package collection. Just follow my-nixpkgs/Usage to add the flake to your config and to add the program to your environment.systemPackages.

Right now I'm the only person actually using this program, so it's only available in the repo with my personal Nix derivations. If there's going to be any interest in it, I'll upstream a derivation into Nixpkgs.

Feel free to just take out the derivation from the pkgs/ folder and stick it in your configuration, if you know what you're doing.

PyPi

This script is available in PyPi here. To install it using pip, run:

$ pip install batnotifsd

About the flake

The Nix flake present in this repo is just the development shell I use to test this script.

More info

[^1]: If the value is set to "Battery", you will need to verify that the property power-supply has the value "true" before considering it as a laptop battery. Otherwise it will likely be the battery for a device of an unknown type.org.freedesktop.UPower.device specification in the UPower Manual

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

batnotifsd-1.0.3.tar.gz (11.6 kB view details)

Uploaded Source

Built Distribution

batnotifsd-1.0.3-py3-none-any.whl (11.7 kB view details)

Uploaded Python 3

File details

Details for the file batnotifsd-1.0.3.tar.gz.

File metadata

  • Download URL: batnotifsd-1.0.3.tar.gz
  • Upload date:
  • Size: 11.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.5

File hashes

Hashes for batnotifsd-1.0.3.tar.gz
Algorithm Hash digest
SHA256 cb8a9cf9e12645653b6269dce639e204729f2aa0028d8f81cb179e14435d4369
MD5 fe3bf8064da1f7deb4e2781e07a4d31c
BLAKE2b-256 ea6d02a85739c803f6493bfeecc124de7883808af6d170b81c3f7678635ef0ad

See more details on using hashes here.

File details

Details for the file batnotifsd-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: batnotifsd-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 11.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.5

File hashes

Hashes for batnotifsd-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 550b1cebe2e22fdea1797ca5ce1c0e0194f77460a9f1fdbcb24a2e26a37d063f
MD5 ffc11eb2e66e861a00bb28f89cb5cfe3
BLAKE2b-256 5c3f6ff43a7029f0d88e4863637581237845dedd48058f1d139923aa6063023e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page