How do I tell my system to create a sound alert whenever my battery has charged at least X percent?

How is that not enough information? I figured this being part of the linux community there would be some kinda app that was already made that I could try out, I figured someone here would know of the app, that’s pretty much the only solution I can think of that would work.

You could write your own.

Query with e.g. upower -d, grep the status, then beep :person_shrugging:

Hmm, that seems like it would have a lag between though, is there a C api I can use instead that you know of?

What kind of “lag”?

Well 1st have to wait for one app to read the status and format it, then another app to extract the status then yet another to interpret the script utilizing them, for a battery that lag could over time add up to a shorter lifespan, I don’t know how much of a shorter lifespan but it doesn’t hurt to reduce lag by as much as possible, also I’m gonna have to map the api in the library I’m making anyways so I might as well learn of it now

You can create a script and run it every minute using cron (should work on Xorg):


battery_level=$(acpi -b | grep -P -o '[0-9]+(?=%)')

if [[ $battery_level -eq $battery_limit ]]; then
    export $DISPLAY=:0
    notify-send "Battery level reached $battery_limit!"
    paplay /usr/share/sounds/freedesktop/stereo/complete.oga

I’m guessing there was an issue with your 1st version, thanks anyways, if I can’t find a specific app able to do it by itself or the C api to do it with then I’ll probably try your solution :slight_smile:

There are many other options too. For example in Dells you cap battery level to a certain limit.

There are many other options too. For example in Dells you cap battery level to a certain limit.

Well this is on a tuxedo built laptop with standard install of the XCFE variant on it, only installed the os and started using the laptop maybe a week ago so I don’t think I have that option, anyways I still want the sound alert for when the battery is close to full so I would need an app or script that does that, your script certainly looks like an easy solution but if I’m gonna have one I might as well put effort into finding a solution that takes the least amount of cpu time & consumes the least amount of power, that way peops who find this thread later will know what to look for if they need their solution to be more efficient than a simple shell script

btw, related question, how do I set a program or script to run periodically? And how to set that period with it

Thanks, for now I’m running that little script that was given however I’m also looking into the libraries needed to program it directly via this file I found while searching the net:

Made a comment in my code about it too just in case I lose the address, at the very least it serves as an example of how to use the api and what details to watch out for, for my library code I’ll have to exclude the mutex stuff since that should be sorted by the code using the wrapper, fortunately I managed to design a custom mutex & a custom wrapper for critical sections, neither can dead lock and efforts have been made to prevent them being destroyed while another thread is trying to lock them, I even went and made a custom solution to thread locals since it was almost impossible to do a one to one mapping between microsoft’s TlsAlloc etc and __thread_local etc, in the process of doing so I managed to make a quick linked list gc out of it, since I’m also making wrappers for the thread APIs in general I can just call the cleanup function before letting the thread die completely, the api is designed to be faster if __thread_local is available but silently fallback to a critical section if it’s not, something like this:

PAWTLS pawvu tls_ptr_or_index = 0;
pawtls_getloc( (void**)&local_data_ptr, &tls_ptr_or_index, sizeof(local_data) );
pawtls_remloc( &tls_ptr_or_index );

Those are the only 3 functions and the 3rd one is meant as an exit call as everything that is linked will be deleted, I might take a PAWCLS pointer for the destruction callback before deletion though

Adapt this one

1 Like

Didn’t work out, I had my battery on charge for a while and just noticed it was at 87% after going back up from about 40ish percent, I’ll give the other one that was just posted a try until I get round to trying to construct an app that takes care of both reading the status and using the speakers to alert me to the battery state

May I ask, what your reacrion to the sound is?
Do you take the laptop from the power?

If you just want a notification to stop charging, you could also try tlp in case it supports your brand.
There one can set thresholds, when charging should start and to what capacity it be charged.

I do not know what brand of laptop you have, or even which kernel you use, but maybe this can mean something to you:


And, as mentioned, take a look at TLP:

I think you’ll want the Battery Care section:


Only just saw your message, I just turn off the switch at the wall, can’t overcharge if there’s no power supply to begin with, however the sound needs to play for me to notice the message when I’m absorbed in something like a video or programming or reading a story

Thanks, will do

Edit: Having looked at it I can see that it doesn’t actually do what I want it to do, it automates battery care sure but not in a way I like, I only want an annoying sharp sound to be played from the speakers to alert me to the fact the battery has charged at least 80% and leave the decision of whether to cut the power or not to me, I find this sound to be acceptable:


I just need to figure out how to read the battery state and work out what percentage it’s at and how to play the sound from C, I’m already familiar with the time() & clock() APIs so it’s only those 2 that I need to learn to setup my own app now

Then I’m guessing you’ll need to make a script that launches on boot, which you can create a Systemd unit for to accomplish and use bash’s watch to check for battery charge change.


Combine this:

…with watch

Welp that didn’t work, set it to every 300s and no sound had come out despite having reached 83% by the time I looked