# want to shutdown laptop at 5% battery level.



## senenmut (Jan 1, 2023)

Hi there,
can anyone mention a tool for smooth handling in percentage manner for latop battery management in BSD ?
Have seen many tools in the ports collection from FreeBsd Page. However shutdown option is not described anywhere.
Which one is a good one ?
Greeting 
SM


----------



## Phishfry (Jan 1, 2023)

The tool I use for this is part of my Window Manager. xfce4-power-manager -System tab -Critical Power
On Critical Battery Power: Suspend/Hibernate/Shutdown
Set your Critical Battery Power to 5%


```
xfce4-power-manager --dump
---------------------------------------------------
       Xfce power manager version 4.18.0
With policykit support
Without network manager support
---------------------------------------------------
Can suspend: True
Can hibernate: True
Authorized to suspend: True
Authorized to hibernate: True
Authorized to shutdown: True
Has battery: True
Has brightness panel: False
Has power button: True
Has hibernate button: False
Has sleep button: True
Has battery button: True
Has LID: True
```


----------



## richardtoohey2 (Jan 2, 2023)

Probably not that difficult to script (he said in a vague hand-wavy sort of way.)

Run a script every minute getting battery level percentage and if 5 or less then run “shutdown -p now”.


----------



## Phishfry (Jan 2, 2023)

Vivek recently updated this tutorial which has good command line examples:


			https://www.cyberciti.biz/faq/freebsd-finding-out-battery-life-state-on-laptop/


----------



## smithi (Jan 2, 2023)

richardtoohey2 said:


> Run a script every minute getting battery level percentage and if 5 or less then run “shutdown -p now”.



A bit sudden-death methinks, Richard.

Such a script needs to warn the user when near doing something that drastic, maybe with beep tones every minute and a popup message (in X) or written to all consoles with wall otherwise, from perhaps 10% on down.

Another (safer) option is to use suspend rather than shutdown .. the user may just be in another room and wouldn't like to lose a two-hour edit or composition ...

Except for near-new batteries, reported percentage capacity and time remaining can be quite inaccurate, and the chip inside most laptop batteries needs recalibrating from time to time.

Another script useful for this will simply record battery state data with time and discharge rates (depending on activity) every minute or so from fully charged to battery exhaustion, ie to when the laptop shuts down itself.

I have done this for the last 20 years with Compaq and later 3 different Thinkpads, sometimes finding that time from reported 0% remaining until exhaustion can be up to an hour!

In such cases up to 3 full charge /  discharge cycles may drastically improve the battery's estimates of its capabilities, and at other times make little or no difference, especially for non-genuine replacement batteries from Ebay etc.

All up, battery care scripts are not so simple, yet worthwhile.

The data from acpiconf -i0 is the most useful, though even then there are differences in reporting different batteries, e.g. mA and mAh versus mW and mWh, so a good script will have a number of parameters, with defaults.


----------



## smithi (Jan 2, 2023)

Phishfry said:


> The tool I use for this is part of my Window Manager. xfce4-power-manager -System tab -Critical Power
> On Critical Battery Power: Suspend/Hibernate/Shutdown
> Set your Critical Battery Power to 5%



Sounds good, but ..



Phishfry said:


> Can suspend: True
> Can hibernate: True
> Authorized to suspend: True
> Authorized to hibernate: True
> Authorized to shutdown: True



FreeBSD can only hibernate on those extremely rare machines that support 'S4bios', ie support for S4 state is handled entirely by the BIOS, not the OS.

Do you have one of those?

If not, what happens when you try to hibernate?


----------



## senenmut (Jan 2, 2023)

hello and thank you for that kindy answers,
i am running GhostBsd and have the mate powermanagement tool.
that tool is catching the battery first which is called "samsung sdi dell mt2648 (80%)" , but has also a second one
which is called "Laptop-Battery (0)%" and specifications "unknown".
Just to say that it has one has is not defined. don't know why.
can it be that only this one is recognized by the mate tool as a real shutdown one ?
perhaps a kind of definition inside the mate tool.
however, i can write a script of course when the problem remains even if tools like mate power management are in use.

Greetings
SM


----------



## richardtoohey2 (Jan 2, 2023)

smithi said:


> A bit sudden-death methinks, Richard.
> 
> Such a script needs to warn the user when near doing something that drastic


Absolutely , but I was just going off the OP’s question - shutdown at 5%.


----------



## Phishfry (Jan 2, 2023)

smithi said:


> If not, what happens when you try to hibernate?


No problem hibernating. Its waking back up that is the issue.
I use CTL-ALT-<F*> and then back to CTL-ALT-F9 to wake it up.
Just going to another virtual console does the trick.
In the past power control worked better for me.


----------



## smithi (Jan 3, 2023)

Phishfry said:


> No problem hibernating. Its waking back up that is the issue.
> I use CTL-ALT-<F*> and then back to CTL-ALT-F9 to wake it up.
> Just going to another virtual console does the trick.
> In the past power control worked better for me.



I think you mean something different here by 'hibernating', perhaps blanking or switching off the screen?

Hibernation is where the entire system state including all RAM contents is written to a dedicated disk partition, then power is switched off entirely.

One can then restart from that point after any amount of time, even remove and replace the battery.  It's then a choice offered at next boot.

Windows does that and at least some linux boxes, but FreeBSD does not, without BIOS support.

I've yet to hear of any specific model that does s4bios (sysctl hw.acpi.s4bios: 1) but there must have been some ...


----------



## senenmut (Jan 4, 2023)

i find out the secondary battery is a module battery. it can be put in where the CD rom drive is for replacement and secondary power.
nothing to do with the "shutdown" function of software installed.
it should be function right but the mate power management software is not shutdown at a critical battery state.


----------



## leebrown66 (Jan 5, 2023)

richardtoohey2 said:


> Absolutely , but I was just going off the OP’s question - shutdown at 5%.


My laptop is console only.  I have a cron job every minute that beeps when it goes below 10%.
That's enough hassle to make me push the power button or plug it into power.


----------

