Documentation / Widgets / Ready-made / Battery icon

Battery icon

A battery that shows how full it is: an outline and a nub in a colour of their own, and a fill as long as its level in a colour you choose for each state it can be in - charged, low, critical or charging - with a lightning bolt over it while it charges. It is an icon and nothing else. Its Level and Charging are bound to variables, usually ones read from the board's power chip; the figure in per cent is a label of your own, bound to the same variable. It is drawn from plain boxes and lines, so it is sharp at any size: its width and height are its size. It is free.

Group: Ready-made · Default size: 40 × 20 · Style parts: Main · Arduino and ESP-IDF

A dropped Battery icon: a small green battery three quarters full.
A Battery icon as it is dropped: 75%, charged.
Battery icon settings: Level 75, Charging off, Orientation lying down, Low at 30, Critical at 10, Outline grey, Fill: charged green, Fill: low orange, Fill: critical red, Fill: charging blue, Bolt while charging ticked, Bolt colour white.
Its settings: the level and charge it starts with, how it lies, the thresholds, the outline’s colour and a fill colour for each state.
FillWhenColour to start with
ChargingCharging is on, whatever the level. With Bolt while charging ticked, a bolt in the bolt colour is drawn over the middle.Blue
CriticalThe level is at or below Critical at.Red
LowThe level is at or below Low at.Orange
ChargedAbove Low at.Green

The level is a whole per cent, 0 to 100. Below 0 it shows empty, which is what a power chip with no battery fitted reads (-1); above 100 it shows full. The outline and the nub are the Outline colour, grey to start with, whatever the level. Orientation lays it down with the nub on the right, or stands it up with the nub on top and the fill rising from the bottom.

Two of its properties can be bound, under Data bindings: Level (0-100 %) and Charging. On a board with a power chip (an AXP2101 or an AXP192), add two variables on the Data tab with their Source set to the chip's Battery charge and Charging, and bind one to each. A battery read on an analog pin works too: a variable with that pin as its source and a formula that turns its reading into a per cent. The board redraws the icon only when what it is told differs from what it shows. Arduino and ESP-IDF exports; MicroPython and ESPHome do not have it, and a Bar bound to the same reading shows the level there.

Example: the charge, from a variable

  1. On the Data tab, add a variable battery, an Integer starting at 20, and a variable charging, a Boolean. On a board with a power chip, set their Source to its Battery charge and Charging.
  2. Drag a Battery icon onto the screen, name it Charge and make it 80 × 40.
  3. Under Data bindings, add a binding from battery that drives Level (0-100 %), and one from charging that drives Charging.
  4. Drag a Label beside it with a font size of 20 px, and bind it to battery driving Text, with % after it.
  5. Press Preview: at 20 the battery is low, and its fill orange.
An orange battery with a short fill, and 20 % beside it.
In Preview: 20%, so the Low colour.
The Battery icon's Data bindings: from the variable battery, driving Level (0-100 %); from the variable charging, driving Charging.
Both of its properties bound.