Audio low battery alarm (SOLVED)

Suggestions and feedback for Linux Mint and the forums
Forum rules
Do not post support questions here. Before you post read: Where to post ideas & feature requests
Post Reply
User avatar
lyndave
Level 2
Level 2
Posts: 51
Joined: Tue Feb 07, 2017 12:30 pm
Location: australia

Audio low battery alarm (SOLVED)

Post by lyndave »

a low level battery alarm that makes an audio sound would be a great addition to linux mint
this alarm could be set at a level specified by the user (10 or 20 %) any level the user chooses.
it would be great if the user could choose any wav or mp3 files from their computer for the alarm sound.
i have done a lot of searching online for such an alarm and cannot find one, however their seems to be a need for such a device
Last edited by lyndave on Mon Apr 03, 2017 10:31 pm, edited 1 time in total.
User avatar
jimallyn
Level 19
Level 19
Posts: 9075
Joined: Thu Jun 05, 2014 7:34 pm
Location: Wenatchee, WA USA

Re: Audio low battery alarm

Post by jimallyn »

That shouldn't be too hard to write a script or program for. Either the acpi command or the upower command will give you the battery state. You could pipe the output through grep to pick out the line that has the information you want, then compare that with your desired alarm level, and either play a sound or not, depending on the level. I don't have a laptop here at the moment, so not able to play with this right now. I wouldn't be surprised if somebody pops in here to tell you how to do it, or maybe somebody will throw together a short script to do this.

Have a look at these pages:

https://www.cyberciti.biz/faq/linux-lap ... mperature/

http://askubuntu.com/questions/69556/ho ... g-terminal

https://www.cyberciti.biz/faq/linux-che ... ry-status/

https://www.ostechnix.com/how-to-check- ... -in-linux/
“If the government were coming for your TVs and cars, then you'd be upset. But, as it is, they're only coming for your sons.” - Daniel Berrigan
User avatar
lyndave
Level 2
Level 2
Posts: 51
Joined: Tue Feb 07, 2017 12:30 pm
Location: australia

Re: Audio low battery alarm

Post by lyndave »

i dont have enough experience to make a script for this sadly
User avatar
jimallyn
Level 19
Level 19
Posts: 9075
Joined: Thu Jun 05, 2014 7:34 pm
Location: Wenatchee, WA USA

Re: Audio low battery alarm

Post by jimallyn »

I might be able to pull it all together, but it would be a bit of a learning experience for me, and I'm not sure I have the time to wade through all that right now. There are probably people on these forums that could whip out a one-liner script to do that in their sleep. But not me. I'd have to work at it.
“If the government were coming for your TVs and cars, then you'd be upset. But, as it is, they're only coming for your sons.” - Daniel Berrigan
User avatar
lyndave
Level 2
Level 2
Posts: 51
Joined: Tue Feb 07, 2017 12:30 pm
Location: australia

Re: Audio low battery alarm

Post by lyndave »

jimallyn

i would like it if you could have a go at it, but no hurry, and thankyou for your interest
User avatar
lyndave
Level 2
Level 2
Posts: 51
Joined: Tue Feb 07, 2017 12:30 pm
Location: australia

Re: Audio low battery alarm

Post by lyndave »

jimallyn

i found this script for a low level alarm, perhaps this is something that could be put into the next version of mint


This is a script i found online after a lot of research, i changed the mp3 file to suite myself and i also changed the % that triggers the alarm.
i set the script up in cron -e
i also put the mp3 in Home
Then i tested it

To get mpg123 and be able to play audio:

sudo apt-get install acpi mpg123

File to open to write the command:

crontab -e

Command to enter at end of the file:


*/1 * * * * if [ `acpi -b | awk ' { print ( $(NF-2)-0)}'` -lt "60" ] ; then mpg123 /home/dave/alarm.mp3 ; fi

its a very simple script, however it does exactly what i require
User avatar
jimallyn
Level 19
Level 19
Posts: 9075
Joined: Thu Jun 05, 2014 7:34 pm
Location: Wenatchee, WA USA

Re: Audio low battery alarm

Post by jimallyn »

Cool, lyndave. I may copy that and use it whenever I do Linux installs on laptops. I knew somebody that knew what they were doing could do that in a one-liner. But not me!
“If the government were coming for your TVs and cars, then you'd be upset. But, as it is, they're only coming for your sons.” - Daniel Berrigan
User avatar
lyndave
Level 2
Level 2
Posts: 51
Joined: Tue Feb 07, 2017 12:30 pm
Location: australia

Re: Audio low battery alarm

Post by lyndave »

jimallyn

i just found a problem with the script :(
it seems once the script activates, the sound file starts and i can't shut it off,
even when the power level gets above the preset %
So i guess its back to the drawing board.
not happy..... :x
so i guess i will keep on looking for a script
User avatar
lyndave
Level 2
Level 2
Posts: 51
Joined: Tue Feb 07, 2017 12:30 pm
Location: australia

Re: Audio low battery alarm

Post by lyndave »

i have not been able to find or create a low level battery alarm with audio however i did come across a low/high level alarm that gives a pop up when the battery is either low or high, so i wouldn't say this was solved. however if anyone would like to have a look at the alarm i found the url is http://linuxsoftware.moncerbae.com/2015 ... buntu.html although it says ubuntu in the address, its for Linux mint as well
User avatar
lyndave
Level 2
Level 2
Posts: 51
Joined: Tue Feb 07, 2017 12:30 pm
Location: australia

Re: Audio low battery alarm

Post by lyndave »

i have worked on the low level battery alarm with audio and have come up
with a work about,it's not exactly what i wanted however it serves the purpose that i wanted.
What i have done is this.
Step 1 sudo apt-get install acpi
Step 2 i went to http://linuxsoftware.moncerbae.com/2015 ... buntu.html
and followed the instructions
Step 3 i went to sound settings/soundeffects and chose the sound i wanted under notifications.
After doing the above, the sounds goes off once the battery gets below 25% or above 95%


PROBLEM SOLVED :)
gvsa123

Re: Audio low battery alarm

Post by gvsa123 »

lyndave wrote: Wed Mar 15, 2017 9:24 pm

To get mpg123 and be able to play audio:

sudo apt-get install acpi mpg123

File to open to write the command:

crontab -e

Command to enter at end of the file:


*/1 * * * * if [ `acpi -b | awk ' { print ( $(NF-2)-0)}'` -lt "60" ] ; then mpg123 /home/dave/alarm.mp3 ; fi

its a very simple script, however it does exactly what i require
Would you mind breaking down what you did there for the people not familiar but interested in understanding the script. I found asking questions like this helps me understand linux and coding in general better. Thanks.
User avatar
Pierre
Level 21
Level 21
Posts: 13214
Joined: Fri Sep 05, 2008 5:33 am
Location: Perth, AU.

Re: Audio low battery alarm (SOLVED)

Post by Pierre »

the original poster will be unlikely to reply,
as this is an older post, that is no longer active.

you may be better off, if you instead start another, New Post, about your Script Query.
Image
Please edit your original post title to include [SOLVED] - when your problem is solved!
and DO LOOK at those Unanswered Topics - - you may be able to answer some!.
Post Reply

Return to “Suggestions & Feedback”