In this section you will learn how to get battery information - if supported by system:
For function reference and examples we assume, that we imported systeminformation as follows:
const si = require('systeminformation');
Battery Data
All functions in this section return a promise or can be called with a callback function (parameter cb in the function reference)
Function | Result object | Linux | BSD | Mac | Win | Sun | Comments |
---|---|---|---|---|---|---|---|
si.battery(cb) | {...} | X | X | X | X | battery information | |
hasbattery | X | X | X | X | indicates presence of battery | ||
cyclecount | X | X | numbers of recharges | ||||
ischarging | X | X | X | X | indicates if battery is charging | ||
designedcapacity | X | X | X | designed capacity of battery (mWh) | |||
maxcapacity | X | X | X | max capacity of battery (mWh) | |||
currentcapacity | X | X | X | current capacity of battery (mWh) | |||
capacityUnit | X | X | X | capacity unit (mWh if possible) | |||
voltage | X | X | X | current voltage of battery (V) | |||
percent | X | X | X | X | charging level in percent | ||
timeremaining | X | X | minutes left (if discharging) | ||||
acconnected | X | X | X | X | AC connected | ||
type | X | X | battery type | ||||
model | X | X | model | ||||
manufacturer | X | X | manufacturer | ||||
serial | X | X | battery serial | ||||
Example
{ hasbattery: true, cyclecount: 35, ischarging: false, designedcapacity: 64958, maxcapacity: 65865, currentcapacity: 64856, voltage: 12.767, capacityUnit: 'mWh', percent: 100, timeremaining: 551, acconnected: false, type: 'Li-ion', model: '', manufacturer: 'Apple', serial: 'F9Y19860Y9AH9XBAX' } |
Known issues
Windows Battery
wmic - which is used to determine temperature and battery sometimes needs to be run with admin privileges. So if you do not get any values, try to run it again with according privileges. If you still do not get any values, your system might not support this feature.