FreeBSD Laptop Find Out Battery Life Status Command

last updated in Categories , ,

I know how to find out battery life status using Linux operating system. How do I monitor battery status on a laptop running FreeBSD version 9.x/10.x/11.x/12.x?

You can use any one of the following commands to get battery status under FreeBSD laptop including remaining battery life and more.


FreeBSD Laptop Find Out Battery Life Status Command

  1. apm command : The apm utility controls the Intel / Microsoft APM (Advanced Power Management) BIOS and displays the current status of APM on laptop PCs.
  2. sysctl command : The sysctl utility retrieves kernel state.
  3. hwstat command : Another command line tool to display CPU temp and battery info.
  4. acpiconf command : The acpiconf command allows the user control of the ACPI power management functions and query laptop battery status.

amp command example

The syntax is:

apm [options]

Type the following command:
$ apm
Sample outputs:

FreeBSD Laptop Find Out Battery Life Status Using amp Command
Fig.01: FreeBSD apm command in action

sysctl command example

Type the following command:
$ sysctl hw.acpi.battery
Sample outputs:

hw.acpi.battery.info_expire: 5
hw.acpi.battery.units: 2
hw.acpi.battery.state: 1 # This will be -1 when we have AC power attached. #
hw.acpi.battery.time: 111 70

hwstat command

The hwstat command is not part of the base system. Type the following command to install hwstat using the pkg_add command/pkg command:
# pkg install hwstat
# pkg_add -rv hwstat
Sample outputs:

scheme:   [ftp]
user:     []
password: []
host:     []
port:     [0]
document: [/pub/FreeBSD/ports/amd64/packages-9.0-release/Latest/hwstat.tbz]
looking up
connecting to
<<< 220 FTP server (Version 6.00LS) ready.
>>> USER anonymous
<<< 331 Guest login ok, send your email address as password.
>>> PASS vivek@fdbsd9
<<< 230 Guest login ok, access restrictions apply.
>>> PWD
<<< 257 "/" is current directory.
>>> CWD pub/FreeBSD/ports/amd64/packages-9.0-release/Latest
<<< 250 CWD command successful.
>>> MODE S
<<< 200 MODE S accepted.
>>> TYPE I
<<< 200 Type set to I.
setting passive mode
>>> PASV
<<< 227 Entering Passive Mode (193,162,146,4,226,183)
opening data connection
initiating transfer
>>> RETR hwstat.tbz
<<< 150 Opening BINARY mode data connection for 'hwstat.tbz' (8779 bytes).
Fetching for final status
<<< 226 Transfer complete.
x bin/hwstat
x share/licenses/hwstat-0.5.1/
x share/licenses/hwstat-0.5.1/LICENSE
x share/licenses/hwstat-0.5.1/BSD
x man/man1/hwstat.1.gz
tar command returns 0 status
extract: Package name is hwstat-0.5.1
extract: CWD to /usr/local
extract: /usr/local/bin/hwstat
extract: /usr/local/share/licenses/hwstat-0.5.1/
extract: /usr/local/share/licenses/hwstat-0.5.1/LICENSE
extract: /usr/local/share/licenses/hwstat-0.5.1/BSD
extract: /usr/local/man/man1/hwstat.1.gz
extract: CWD to /usr/local
Running mtree for hwstat-0.5.1..
mtree -U -f +MTREE_DIRS -d -e -p /usr/local >/dev/null
Attempting to record package into /var/db/pkg/hwstat-0.5.1..
Package hwstat-0.5.1 registered in /var/db/pkg/hwstat-0.5.1

Type the following command to see CPU temperature and battery information under FreeBSD operating system:
$ hwstat
Sample outputs:

Fig.02: hwstat in action
Fig.02: hwstat in action

acpiconf command example

To see information about the specified battery, enter:
$ acpiconf -i batt#
$ acpiconf -i 0 | grep capacity
$ acpiconf -i 0

Sample outputs:

Design capacity:	8850 mAh
Last full capacity:	6248 mAh
Technology:		secondary (rechargeable)
Design voltage:		11100 mV
Capacity (warn):	885 mAh
Capacity (low):		268 mAh
Low/warn granularity:	88 mAh
Warn/full granularity:	88 mAh
Model number:		DELL 1C75X35
Serial number:		1142
Type:			LION
OEM info:		Samsung SDI
State:			charging
Remaining capacity:	69%
Remaining time:		unknown
Present rate:		2846 mA (34738 mW)
Present voltage:	12206 mV

How to find out battery design capacity

You need to note down the following values from the above the acpiconf -i 0 command:
Design capacity: 8850 mAh
Last full capacity: 6248 mAh

So formula to get battery wear is as follows:

echo "scale = 2; ${last_full_capacity} / ${total_capacity} * 100" | bc -l



How to tell if your FreeBSD laptop battery is worn

When Last full capacity is below 80% Designed capacity then the battery is likely showing signs of wear and requires replacing. For example:

# Author: Vivek Gite
# Purpose: Quick and dirty way to find out laptop battery worn out or not 
# -------------------------------------------------------------------------------
echo "** Battery info for $HOSTNAME @ $(date)  ** "
acpiconf -i 0 | egrep "^(OEM|Model)" | awk -F':' '{sub(/^[ \t]+/, "",$2); printf "%s\n", $2}'
last_full_capacity=$(acpiconf -i 0 | grep "^Last full capacity:" | awk '{ print $4}')
total_capacity=$(acpiconf -i 0 | grep "^Design capacity:" | awk '{ print $3}')
echo "** Battery wear info ** "
wear=$(echo "scale = 2; ${last_full_capacity} / ${total_capacity} * 100" | bc -l)
echo "$wear"
# if $wear is < 80% warn the user #
if [ ${wear%%.*} -lt 80 ]
        # \a will send beep alert #
	echo -e "\aYou may need to replace the battery."
How to tell if your FreeBSD laptop battery is worn or not
Are you finding that the battery in your FreeBSD based laptop isn’t lasting as long as it used to? Here how to tell if it is getting worn or not.


We used various command to find out battery status under FreeBSD operating system for laptop. See FreeBSD docs here for more information.

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.


2 comment

Leave a Comment