Skip to main content
An alarm definition says what to watch (its kind and query), when it fires (condition_cel), when it resolves, and how long each must hold. This page is the reference for those fields. For the concepts behind them, see Alarms overview. For a guided first rule, see the first alarm walkthrough.

Kinds

Set kind on the definition. An empty kind is treated as event.
condition_cel is required by the API for every kind. For an event rule with a query and for a staleness rule, the evaluator never runs it. Send "true" — the Console does the same.

Threshold

A threshold rule runs its SQL every evaluation interval against the dataspace’s read view. Each row the query returns is evaluated on its own:
  1. The row’s columns are exposed to CEL as event.<column>.
  2. condition_cel decides whether that row is breaching.
  3. The values of the labels_by columns identify which alarm instance the row belongs to.
Shape the query so it returns one row per thing you want to alarm on — for example one row per device with GROUP BY device_id, and labels_by: ["device_id"]. A column named value is special: when present and numeric, it is recorded as the instance’s trigger value and is what the deadband compares against.

Event

An event rule works in one of two ways, depending on whether it has a query.
The rule runs query_spec.sql every evaluation interval. If the query returns at least one row, the condition is met. If it returns no rows, the condition is not met. CEL is not evaluated on the result.There is one instance for the definition’s asset_id, or a single project-wide instance when asset_id is empty. Use this when “any row matches” is the alarm — for example any error-level log line in the last five minutes.

Staleness (device offline)

A staleness rule fires for each device that has been disconnected longer than staleness_window_seconds.
LoRaWAN, HTTP, and OPC-UA devices hold no broker connection, so they are never “offline” in this sense. To catch a device that stops sending data, use a threshold rule over max(event_ts). The Console’s Telemetry stops arriving template builds that query for you — see Telemetry stops arriving below.

Query spec

query_spec carries the native SQL a threshold rule (or an event rule with a query) runs:
Name the read view in FROM, not the dataspace name. Copy it from the dataspace catalog’s read_view field (it looks like ds_read_<hex>). The Console shows it above the SQL editor. See Dataspaces overview.

Query limits

Every scheduled query must stay small, because rules share one evaluator. When you create or update a definition, the SQL is checked and rejected if it breaks any of these rules: Accepted window forms:

CEL expressions

condition_cel, resolve_cel, and clear_cel are CEL expressions. Each must evaluate to a boolean, or the definition fails to evaluate. The CEL math and strings extensions are available.
A bare column such as event.alarm_active is not known to be a boolean and is rejected. Compare it explicitly: event.alarm_active == true.
Examples:

Deciding when an alarm resolves

The resolve candidate is chosen in this order:
  1. resolve_cel — if set, the alarm starts resolving when this is true. Use it for an asymmetric band: fire at event.value > 80.0, resolve at event.value < 70.0.
  2. clear_cel — if set (and resolve_cel is not), the alarm starts resolving when this is true.
  3. deadband — if neither expression is set, and both deadband and a setpoint in metadata are greater than zero, the alarm starts resolving when the row’s value is at or below setpoint - deadband.
  4. Otherwise — the alarm starts resolving when condition_cel is false.
resolve_cel, clear_cel, and deadband apply to threshold rules and to event rules without a query. Scheduled event rules resolve when the query returns no rows. staleness rules resolve when the device reconnects.

Timing and hysteresis

Hold times are measured from the instance’s own timestamps, so they survive restarts. On scheduled rules a hold can only mature on an evaluation, so the effective delay rounds up to the next evaluation.
If the condition goes false while an instance is still pending, the instance closes without ever firing. A resolved instance that breaches again fires again immediately — for_seconds gates only fresh activations.

No data handling

on_no_data decides what happens to an open instance when its labelset produces no row on a threshold evaluation, or when its row is deleted on an event rule without a query. No data only affects labelsets that already have an open instance. A labelset that has never produced a row cannot raise an alarm through alert. Scheduled event rules and staleness rules always have data and ignore this field.

Labels

labels_by lists the result columns whose values identify an instance on a threshold rule. Rows with the same values for those columns update the same instance; a new combination opens a new one. The values are stored on the instance as its labels and shown on the board. Every column in labels_by should appear in the query’s SELECT.

Scoping to assets

staleness rules always cover every enabled MQTT device in the project.

Examples

Send any of these to POST /projects/{project_id}/alarm-definitions — see API reference.

Telemetry stops arriving

For devices that have no broker connection, alarm on silence with a threshold rule. This is the query the Console’s Telemetry stops arriving template generates for a 20-minute window:
Pair it with condition_cel: "true", labels_by: ["device_id"], and on_no_data: "resolve". A device appears in the result only while it is quiet, so it resolves as soon as rows resume.
Because the window is capped at 24 hours, a device silent for longer than a day drops out of the result and its alarm resolves. Use a staleness rule for MQTT devices where that matters.

Next steps

Notifications

Get paged when an instance fires, with re-notify and escalation.

Silences and shelving

Suppress alarms during maintenance or known faults.

Console guide

Author definitions in Alarms → Definitions.

Troubleshooting

Rules that never fire, rejected queries, and flapping alarms.