Deleting a device: delete_device / confirm_delete_device
:::note Deleting a plant is different
When a plant is deleted on the HTTP server, its devices are not deleted. They go back to stock with their history erased, keep their logger and their batteries, and keep reporting. See Plant deletion.
:::
What else goes with the device (2026-11-20):
- Its batteries. Every battery on the device is deleted with it.
- Its share of the plant's analytics. The plant's daily and monthly
energy totals and its day curves are rebuilt without the device for every
date it has history in.
- When:
persistence-workerdoes this on its next fleet-rollup run after the erasure (within about 5 minutes). - Days left empty: a day only this device had data for disappears from the plant's history, and so does a month left with no day.
- What is not rebuilt: availability (outage) figures already measured for kept days stay as they were. They came from connection history that no longer exists.
- Live figures never counted the device after deletion, because they are rebuilt every run.
- When:
Permanently and irreversibly erases a device: every telemetry reading
and parameter-history row, its rolled-up 15-minute and daily totals, its
alerts, tariff rates, daily financials, Activity Trail history, its logger
history and the recorded sightings of every logger it has had, and the
device row itself. (A logger it had before a swap that is now fitted to
another device keeps its sighting of that device; only one naming this
device's inverter goes.) It also disposes
of the physical logger — only the one fitted to the device now (its
loggerId): a logger it had before a
logger swap may since be someone
else's, and is left alone — the next time it
connects: the server overwrites the logger's WiFi settings with a network
that doesn't exist, so it drops off the network, stops dialling in, and no
longer holds the owner's WiFi credentials. Getting that hardware back
requires provisioning it again over BLE, after which it registers as a
brand-new device.
This is the exact same operation an operator's deviceadmin delete CLI
command performs (see Server behavior); exposing it here
does not make it any less destructive or any more undoable. There is no
reversible "remove from my account" message on this API — taking a device
out of service without erasing it (revoke) is an operator action.
This is a two-step flow, not one message, specifically because it's this destructive:
// → client: step 1, request deletion
{"type": "delete_device", "deviceKey": "3f2504e0-4f89-41d3-9a0c-0305e82c3301", "userId": "17833b2e-a851-4a17-a764-62524d667959",
"plantId": "01JABCDEFGHJKMNPQRSTVWXYZ0"}
// ← server
{"type": "delete_device_confirm_required", "ok": true,
"deviceKey": "3f2504e0-4f89-41d3-9a0c-0305e82c3301", "plantId": "01JABCDEFGHJKMNPQRSTVWXYZ0",
"confirmToken": "3f9a...(64 hex chars)...", "expiresInSeconds": 300}
Nothing is deleted yet. Step 1 checks ownership exactly like write does,
so it fails with device not found or not authorized to control this device for a device the userId doesn't own. plantId is required, and
step 1 also fails with device is not in this plant unless the device is
stored in that plant (a device with no plant is in none), so a delete tapped
on one plant's screen cannot erase a device that has since moved to another.
This is a safety check, not authorization, and plantId: "all" is refused
here. Since 2026-11-23 step 1 also fails with this device's plant is blocked; contact support when the device's plant is blocked (Block B), or
when your ticket lists the plant as frozen (xp). A stranger still gets
not authorized to control this device, not the block. delete_device_confirm_required, delete_device_started and
delete_device_result carry the plantId the deletion was requested in, so
the app knows which plant's list to remove the device from.
delete_device_progress carries no plantId. The token is single-use and
expires in 5 minutes; request again if it lapses. Show the user an explicit,
unambiguous confirmation screen — naming the device and stating plainly
that this cannot be undone — before sending step 2:
// → client: step 2, confirm
{"type": "confirm_delete_device", "deviceKey": "3f2504e0-4f89-41d3-9a0c-0305e82c3301",
"userId": "17833b2e-a851-4a17-a764-62524d667959", "confirmToken": "3f9a...(64 hex chars)..."}
// ← server, immediately
{"type": "delete_device_started", "ok": true, "deviceKey": "3f2504e0-4f89-41d3-9a0c-0305e82c3301", "plantId": "01JABCDEFGHJKMNPQRSTVWXYZ0"}
If the token is unknown, expired, already used, or was issued for a
different deviceKey/userId, the reply is ok: false with invalid or expired confirmation; request deletion again. Step 2 also re-checks the
plant: if the device was moved to another plant after step 1, the reply is
ok: false with the device has moved to another plant; request deletion again, and nothing is deleted. If the plant was blocked (or frozen for your
ticket) after step 1, the reply is ok: false with this device's plant is blocked; contact support, and nothing is deleted. Any confirm attempt consumes the token —
even a mismatched or refused one — so on failure always go back to step 1.
A token issued before this server release doesn't carry over: confirming one
gets the same invalid or expired confirmation; request deletion again. So
does confirming a token issued by the new release while a request lands on a
server still running the old one during a rolling deploy. Either way nothing
is deleted and requesting deletion again works.
ok: true here means the deletion has begun, not finished. The device
is taken out of service first (it immediately shows status: "revoked" in
get_devices and a watch of it is refused), its live connection is
closed, and then its telemetry is erased in 30-day batches, which can
take a while for a long history (the server gives up after 30 minutes,
leaving a state an operator can resume). Progress messages follow — one per
non-empty batch, then a final one with telemetryDone: true — and then
exactly one result:
// ← server, zero or more times
{"type": "delete_device_progress", "deviceKey": "3f2504e0-4f89-41d3-9a0c-0305e82c3301", "rowsErased": 8600, "totalErased": 8600, "windowStart": "2026-01-01"}
...
{"type": "delete_device_progress", "deviceKey": "3f2504e0-4f89-41d3-9a0c-0305e82c3301", "rowsErased": 0, "totalErased": 43120, "telemetryDone": true}
// ← server, exactly once
{"type": "delete_device_result", "ok": true, "deviceKey": "3f2504e0-4f89-41d3-9a0c-0305e82c3301",
"telemetryRows": 43120, "aggregateRows": 1417, "activityRows": 12}
Each count in delete_device_result is omitted when it is zero
(sightingRows above). On failure the result carries ok: false and one
of two messages — no counts:
deletion could not be completed; it may be partially applied and the device is out of service either way — contact supporta deletion for this device is already in progress(see below)
The confirmation token does not, by itself, close the "unverified userId"
gap every message on this page inherits (see Known gaps) —
userId is still whatever the client claims, not cryptographically
verified. What the token adds is a second, deliberate step: a single
malformed or accidental message can no longer trigger an irreversible,
physically-destructive action by itself. Treat delete_device_confirm_required
as something to show a real "are you sure" screen for, not something to
auto-confirm.
If the client disconnects mid-deletion, the deletion keeps running to
completion (or fails into the same safely-resumable state the CLI's
interrupted erasures do) — it does not depend on the WebSocket connection
staying open, only on having been confirmed. Reconnecting does not resume
the progress stream; use get_devices instead — the device shows
revoked while the deletion runs and is gone from the list once it
finishes.
delete_device_result can come back ok: false with
"a deletion for this device is already in progress" — this means a
prior confirmed deletion for the same device is still running (this can
happen if a user manages to confirm twice, e.g. two devices/tabs open on
the same account). It is not a failure of the request that got this
reply; the device is still being erased by the other one either way. See
Messaging for
why this can only be enforced correctly at the database layer, not by the
confirmation token alone.