battery
Battery status snapshot.
Battery status snapshot. Emitted by providers whose device reports a battery (DeviceFeature.BatteryOperated): battery cameras, sensors, buttons. Whether the device SLEEPS is low-power-sleep, not this cap. Consumers build their own "low battery" alerting on top — the cap deliberately does NOT enforce a threshold.
At a glance
| Capability | battery |
| Provided by | The device's own driver provides it: each device registers its own provider. |
| Active providers per device | one |
| Device types | camera, sensor, button, switch, pet-feeder, container, climate, event-emitter |
| Source | packages/types/src/capabilities/battery.cap.ts |
Methods
This capability declares no methods.
Runtime state
The state Dominevo keeps for each device with this capability, readable without calling the provider.
Runtime-state slice — every provider that registers this cap stores the same shape under device.runtimeState[battery]. Cross-provider uniformity: a Reolink Argus, a sensor proxy, an ONVIF battery cam all read/write the same keys. Consumers (BatteryBadge, snapshot wrapper sleep gate) read once via device.runtimeState.getCapState('battery') regardless of the underlying driver.
| Field | Type | Required | Description |
|---|---|---|---|
level | number | null | yes | 0..100 inclusive, firmware-reported. null means NOT YET KNOWN — the provider has registered the capability but no reading has landed. It is nullable because it was not, and the only value a provider could seed with was 0. A battery camera behind an NVR therefore announced itself at 0% on every start and corrected itself a moment later, which is indistinguishable from a real flat battery: it fires the low-battery alert every time the hub restarts. Unknown is not empty, and on a battery reading the difference is an alarm. vacuum-control and lawn-mower-control already model it this way. Consumers must SKIP a null rather than coerce it — battery-band already declines to band a non-finite reading, which is the correct shape. |
charging | "dc" | "solar" | "none" | "unknown" | yes | Charging source. 'dc' covers wall/USB adapters; 'solar' is Reolink-specific for the Solar Panel 2 accessory (will become common on other battery cams). 'none' means running on battery alone — a NEGATIVE the firmware actually reported. 'unknown' is the absence of an answer: the provider has not read the power fields yet, or the firmware reported neither. Consumers SKIP it (no charger state published, no glyph, no HomeKit ChargingState) rather than coerce it either way. |
sleeping | boolean | yes | True when the camera firmware has gone into low-power mode. Battery providers MUST avoid polling during sleep — reading the battery wakes the camera up and drains charge. |
lastUpdated | number | yes | Ms epoch of the last observation. Lets consumers reason about freshness. |
voltage | number | null | no | Battery voltage in volts, for a cell the firmware reports as voltage rather than a percentage (Ecowitt capacitor packs). Absent on cameras that only report charge. A second reading on this cap, not a second numeric-sensor on the same device. |
lastContactAt | number | no | Ms epoch of the last time the device PROVED it was reachable — a completed firmware round-trip, an observed wake, or an inbound push (firmware event, email). 0/absent = never since this slice was born. This is the ONLY input that separates "asleep" from "gone", and it is fed exclusively by PASSIVE signals: nothing may write it by reaching for the radio, because a poll that confirms reachability is the same poll that drains the battery. See { single derivation every consumer must use; no surface computes its own. It is deliberately NOT a clock in the scripts/check-runtime-state-durability.ts sense: it is the observation itself, and it is the only thing a 30-hour silence is visible in. Writers quantise it (see CONTACT_WRITE_QUANTUM_MS in the Reolink provider) so a value that means "recently" cannot cost a SQLite commit per round-trip. |
lastFullRefreshAt | number | no | Ms epoch of the last COMPLETE scheduled refresh — every fact the provider holds for the device (level, charging, link, device info, state slices) and its cached snapshot, read together. Absent = never since this slice was born. Unlike lastUpdated (any write, even a push of one field) this is the staleness an operator can trust: the provider owns the device fact and so owns the window on its age. Not a clock in the runtime-state-durability sense: it moves once per window and must survive a restart, or every restart would owe the camera a wake. |
binary | boolean | no | True when the source is a BINARY low-battery indicator (HA binary_sensor device_class=battery / LOW_BAT) that has no real charge level — level is then a coarse stand-in (100 = normal, sub-threshold = low). UI MUST render "Normal"/"Low" instead of a misleading exact percentage. Absent/false → genuine 0–100 % reading. |
Events
onStatusChanged
Emitted whenever the cached status changes (firmware push OR poll observes a delta). The DeviceEventPropagator mirrors this event on the parent chain — subscribing to a camera's source receives battery events from child accessories automatically.
| Field | Type | Required | Description |
|---|---|---|---|
deviceId | number | yes | |
status | { level: number | null; charging: "dc" | "solar" | "none" | "unknown"; sleeping: boolean; lastUpdated: number; voltage?: number | null; lastContactAt?: number; lastFullRefreshAt?: number; binary?: boolean } | yes |