Skip to main content

Get current battery state (device.battery_state)

Declaration

state = device.battery_state()

Returns

  • state
    String. One of the following values:
    "Full" Connected to power and fully charged
    "Charging" Connected to power and charging
    "Unplugged" Not connected to power
    "Unknown" State is unknown

Example

local mapping = {
Full = "Connected and full",
Charging = "Connected and charging",
Unplugged = "Not connected",
Unknown = "Unknown",
}
sys.alert("Battery state: " .. mapping[device.battery_state()])

Note: Uses function outside this chapter sys.alert