电池小组件
最多八台设备的电量,以圆环形式呈现。最适合智能家居电池、传感器,以及任何你不希望发现已耗尽的东西。
本节介绍的功能来自一个正在等待 App Store 审核的应用更新。更新上线后,此处会自动解锁。
The battery template renders one ring per device, in the same idiom as Apple's own
Batteries widget. It is the right shape for any set of things that each have a percentage and a
name — smart-home batteries, sensor nodes, UPS units, tool packs.
Fields
| Field | Type | Notes |
|---|---|---|
template | string | Required. Must be "battery" |
devices | object[] | Required. Between 1 and 8 device objects, rendered in the order you send them |
devices[].name | string | Required. Must not be empty. Max 32 characters |
devices[].level | float | Required. Charge percentage, 0 to 100 |
devices[].charging | boolean | Overlays a charging bolt on the ring |
devices[].icon | string | SF Symbol shown inside the ring, or an MDI icon prefixed with mdi:. Max 128 characters |
devices[].color | string | Ring color — named color or hex (see Colors). Default is green, switching to red at or below 20% |
label, subtitle, icon, accent_color, background_color, text_color | string | Shared content fields — see the API reference |
Example: household devices
{
"content": {
"template": "battery",
"label": "Devices",
"icon": "battery.75percent",
"accent_color": "green",
"devices": [
{ "name": "Vacuum", "level": 68, "icon": "fan.fill" },
{ "name": "Front lock", "level": 45, "icon": "lock.fill", "charging": true },
{ "name": "Doorbell", "level": 18, "icon": "video.fill" },
{ "name": "Sensor hub", "level": 92, "icon": "sensor.fill" }
]
}
}Behavior
Each ring fills to its level and is tinted by its own color, falling back
to green — and to red at or below 20%, so a device that needs attention stands out without you
computing the color. charging: true adds the bolt overlay. Large Home Screen widgets
list all eight devices; smaller families render as many as fit, taking them from the front of the
array, so put the devices you care most about first.
The devices array is replaced wholesale by a merge patch, not merged element by element. Send the full roster on every update, including devices whose level has not changed — a patch carrying one device leaves the widget showing exactly that one device.
Add and reorder devices interactively on the playground to see how many rings each widget size shows.