Posts: 22
catch22
Joined: 07 Jul 2013
#1
I have the battery-% in my conky, but would like to get a warning when on 10% and a second one a bit later, telling me that there'll be an automatic shutdown in 3 minutes.
Is there an easy script for this?

I've found something that goes in the direction, but there's no first warning and it's for BSD:

========= SCRAPER REMOVED AN EMBEDDED LINK HERE ===========
url was:"http://www.unix.com/bsd/115864-battery-empty-force-shutdown.html"
linktext was:"http://www.unix.com/bsd/115864-battery- ... tdown.html"
====================================

and also

========= SCRAPER REMOVED AN EMBEDDED LINK HERE ===========
url was:"http://forums.freebsd.org/showthread.php?p=34777"
linktext was:"http://forums.freebsd.org/showthread.php?p=34777"
====================================
Last edited by catch22 on 03 Aug 2013, 19:22, edited 1 time in total.
Posts: 1,062
Dave
Joined: 20 Jan 2010
#2
hmm, I have made conky do this before....
conky-configuration-t233-30.html?hilit=conky

maybe my post there will help?
Posts: 22
catch22
Joined: 07 Jul 2013
#3
Dave wrote:hmm, I have made conky do this before....
conky-configuration-t233-30.html?hilit=conky

maybe my post there will help?
Thanks Dave. I'll have to wait now till the battery is low, to see if I did it correctly __{{emoticon}}__
I'm not shure what I'd have to do with the lowbattery script that is included, but the main part of the conky now looks like this:

Code: Select all

TEXT
${color}antiX
${color}Desktop: ${color}${exec cat ~/.antix-session/desktop-code$DISPLAY}
${color}$sysname $kernel
${color}Uptime: $uptime
${color}${time %a %d %b %k:%M}

${color}Monitors:
${color}cpu: ${color}${cpu}%
${color}ram : ${color}$mem${color}/${color}$memmax ${color}- ${color}$memperc%
${color}swap: ${color}$swap${color}/${color}$swapmax ${color}- ${color}$swapperc%
${color}processes: ${color}$processes  ${color}running: ${color}$running_processes
${color}battery: ${color}$acpiacadapter, ${color yellow}${battery_percent BAT0}% 
${if_existing /sys/class/power_supply/AC/online 0}
${if_match ${battery_percent BAT0} <= 15}${execi 20 notify-send -t 10000 -i /usr/share/icons/gTangish-2.0a1/48x48/status/battery-caution.png"Battery Low""Battery Level is 15%                               Suggesting to save your work, or plug in the computer."}${endif}${endif}
${if_match ${acpitemp} >= 70}${execi 20 notify-send -t 10000 -i /usr/share/icons/gTangish-2.0a1/48x48/status/dialog-warning.png"Tempurature High""Shut Down will occur if Tempurature rises. Suggesting you save your work"}${endif}
${if_existing /sys/class/power_supply/AC/online 0}
${if_match ${battery_percent BAT0} <= 5}${execi 40 lowbattery}${endif}${endif}
${if_match ${acpitemp} >= 75}${execi 40 hightemp}${endif}

${color}Space:
${color}Root:${color} ${fs_free /} ${color}= ${fs_free_perc /}%
${color3}${execi 10 persist-enabled}
Posts: 146
Eperbab
Joined: 10 Dec 2012
#4
You don't have to wait for low battery. Just change {battery_percent BAT0} <= 15} for testing. e.g. <=85. (or actual battery stat -2%)
__{{emoticon}}__
Posts: 1,062
Dave
Joined: 20 Jan 2010
#5
or make the less than sign a greater than sign.

however you probably will not receive a notification as notify-send is not installed by default. this would either need to be installed or you can change it to use yad like.....
yad --image="info" --text="warning my battery is getting low. I am currently less than 15 %" --button="gtk-ok:0"

likewise you can do the same for less than 5 %. on there you could make yad ask to shutdown. so if ok is pressed your computer shutsdown, if cancel is pressed keep running.
Posts: 22
catch22
Joined: 07 Jul 2013
#6
Dave wrote:or make the less than sign a greater than sign.

however you probably will not receive a notification as notify-send is not installed by default. this would either need to be installed or you can change it to use yad like.....
yad --image="info" --text="warning my battery is getting low. I am currently less than 15 %" --button="gtk-ok:0"

likewise you can do the same for less than 5 %. on there you could make yad ask to shutdown. so if ok is pressed your computer shutsdown, if cancel is pressed keep running.
Thank you both! That yad-line works fine. I might look up in the man pages how to get the shutdown trick too, but for now I'm happy enough with the warning pop up __{{emoticon}}__
Posts: 22
catch22
Joined: 07 Jul 2013
#7
Minor detail: when the yad-warning starts, it doesn't pop up on top of other programs that are open; can I force it to show on top of everything else?
Posts: 1,062
Dave
Joined: 20 Jan 2010
#8
I think that there is an option in yad called --on-top that should keep the Window on top. Do yad --help or man yad to double check
Posts: 22
catch22
Joined: 07 Jul 2013
#9
Dave wrote:I think that there is an option in yad called --on-top that should keep the Window on top. Do yad --help or man yad to double check
Thanks Dave, but I managed to turn my minor issue into a big mess __{{emoticon}}__

I changed the conky-file and here's the relevant part of it:

Code: Select all

${color}battery: ${color}$acpiacadapter, ${color yellow}${battery_percent BAT0}% 
${if_existing /sys/class/power_supply/AC/online 0}
${if_match ${battery_percent BAT0} <= 15}${execi 20 yad --image-on-top="info" --text="WARNING... battery is getting below 15 %" --button="gtk-ok:0"}${endif}${endif}
${if_match ${acpitemp} >= 70}${execi 20 yad --image-on-top="info" --text="Tempurature High - Shut Down will occur if Tempurature rises. Suggesting you save your work"}${endif}${endif}
$
Now this conky doesn't show up anymore; BTW it's called"conkyrc_icewm" (without preceeding dot) and is located in a folder called .conky

When I restart conky it's incomplete - I found this is because there exists another .conkyrc in my home, so I renamed that to .conkyrcNOT to disable it.
Now when I restart conky there's yet another appearance of another one of which I don't even know where it is located __{{emoticon}}__

Sorry for reopening an old solved post and making such a newbee mess of it __{{emoticon}}__
Posts: 1,062
Dave
Joined: 20 Jan 2010
#10
Oh ok for icewm:
Your startup should have a line similar to:
conky -c ~/.conky/conkyrc_icewm
Similarly when you run conky you need to run it with the -c option just as above.
If you only use icewm, then you can copy the conkyrc_icewm file from ~/.conky to the main home folder ~/ and rename it .conky.
That way you will only need to run"conky" to have your desired config.

If you have renamed the .conkyrc to try to get conky to look elsewhere it will not, unless you specify the other location with -c. With the ~/.conkyrc file renamed to ~/.conkyrcNOT, then run"conky" it will just use the global config file found at / etc/conky/conky.conf. Clearly this is not what you were looking for.

To straiten out the battery warning thing. Try using the following code (Using the text portion from above)

Code: Select all

TEXT
${color}antiX
${color}Desktop: ${color}${exec cat ~/.antix-session/desktop-code$DISPLAY}
${color}$sysname $kernel
${color}Uptime: $uptime
${color}${time %a %d %b %k:%M}

${color}Monitors:
${color}cpu: ${color}${cpu}%
${color}ram : ${color}$mem${color}/${color}$memmax ${color}- ${color}$memperc%
${color}swap: ${color}$swap${color}/${color}$swapmax ${color}- ${color}$swapperc%
${color}processes: ${color}$processes  ${color}running: ${color}$running_processes
${color}battery: ${color}$acpiacadapter, ${battery_percent BAT0}%
${color}${battery_bar BAT0}
${if_existing /sys/class/power_supply/AC/online 0}${if_match ${battery_percent BAT0} <= 15}${execi 5 yad --image="info" --text="Your Battery is Low, sugggesting that you save your work or plug in\!" --button="gtk-ok:0" --on-top --width="300"}${endif}${if_match ${battery_percent BAT0} <= 5}${execi 40  yad --image="info" --text="Battery is at Critical\! $$" --form --field="Shut Down:BTN""""bash -c 'sudo shutdown -h now" --width="300" --button="gtk-cancel:1"}${endif}${endif}
${color}Space:
${color}Root:${color} ${fs_free /} ${color}= ${fs_free_perc /}%
${color3}${execi 10 persist-enabled}
I am guessing that you have received the yad errors before, so I have left the file location the same.
However if there is no error messages, then you will need to change"ls":
/sys/class/power_supply/
There should be a folder there for BAT and AC, Change the BAT0 to match the BAT folder there (in my case BAT1)
BAT0 -> BAT1
and change the ${if_existing /sys/class/power_supply/AC/online 0} to match the AC folder (in my case ACAD)
${if_existing /sys/class/power_supply/AC/online 0} -> ${if_existing /sys/class/power_supply/ACAD/online 0}

Dave
Posts: 22
catch22
Joined: 07 Jul 2013
#11
Thanks again Dave!
The conky location is clearer now __{{emoticon}}__

For some reason the pop up appears twice now, with the code as is below, but that's ok; double warning is better than none __{{emoticon}}__

Code: Select all

${color}battery: ${color}$acpiacadapter, ${color yellow}${battery_percent BAT0}% 
${color}${battery_bar BAT0}
${if_existing /sys/class/power_supply/AC/online 0}
${if_match ${battery_percent BAT0} <= 15}${execi 5 yad --image="info" --text="WARNING... battery is getting below 15 %" --button="gtk-ok:0" --on-top --width="300"}${endif}
${if_match ${battery_percent BAT0} <= 5}${execi 40 yad --image="info" --text="Battery is at Critical\! $$" --form --field="Shut Down:BTN""""bash -c 'sudo shutdown -h now" --width="300" --button="gtk-cancel:1"}${endif}${endif}
${if_match ${acpitemp} >= 70}${execi 20 yad --image-on-top="info" --text="Tempurature High - Shut Down will occur if Tempurature rises. Suggesting you save your work"}${endif}
${if_existing /sys/class/power_supply/AC/online 0}
${if_match ${battery_percent BAT0} <= 5}${execi 40 lowbattery}${endif}${endif}
${if_match ${acpitemp} >= 75}${execi 40 hightemp}${endif}