πŸ“¦ Archived documentation: r1 (committed 2026-07-24) View current documentation β†’

alm

Register and evaluate alarm conditions with trigger/clear delays, grouping, acknowledgement and priority queries.

The alm object turns raw conditions into managed alarms: each fault has a group, a title, a priority, a trigger delay (the condition must hold this long before the alarm activates) and an optional automatic-clear behaviour. State changes are automatically recorded in the event log, including the fault's attached value.

Priority constants β€” used by alm.e() and the extended form of log():

Constant Meaning
alm.ok Normal / no alarm
alm.info Informational
alm.warn Warning
alm.crit Critical

Custom numeric priorities (0–255) can be used as well.

Typical pattern β€” set the group, evaluate each condition every loop, then read the aggregate state:

while(run()){
  alm.g("UV");                          // current alarm group
  alm.e(alm.crit, "Reactor A Run Failure", pressure > limit, 5, true, 0, pressure);

  let worst = alm.max();                // highest active priority overall
  waitMS(1000);
}

See the Alarm Conditions example for a complete script including resets and acknowledgement.

Functions

alm.g()

alm.g(group)

Sets the current alarm group; subsequent alm.e() evaluations register under it.

Alarms are organised into named groups (e.g. one per machine or subsystem). Call alm.g() before evaluating conditions to select which group the following alm.e() calls belong to.

Arguments

NameTypeRequiredDefaultDescription
group string yes β€” Group name, e.g. "UV".

Example

alm.g("UV"); // conditions evaluated next belong to the "UV" group

alm.e()

alm.e(priority, title, condition, triggerDelay, clearable, clearDelay, [value]) β†’ number

Evaluates an alarm condition with trigger/clear delays; returns the alarm’s current priority, or 0 when not alarming.

Registers and evaluates one fault under the current group (alm.g()). Call it every loop iteration with the live condition β€” alm.e() handles the debouncing, state tracking and event-log records for you:

  • The condition must stay true for triggerDelay seconds before the alarm activates.
  • If clearable is true, the alarm clears automatically once the condition has been false for clearDelay seconds; otherwise it stays latched until reset with alm.rst().
  • The optional value (e.g. a reservoir level or pressure) is included in the log messages automatically recorded when the fault changes state.

Returns the alarm's current priority while active, or 0 when not alarming.

Arguments

NameTypeRequiredDefaultDescription
priority number | alm constant yes β€” Alarm priority β€” alm.ok/alm.info/alm.warn/alm.crit or 0–255.
title string yes β€” Alarm title, unique within the group.
condition boolean yes β€” The live fault condition, evaluated every call.
triggerDelay number (s) yes β€” Condition must be true this many seconds before the alarm activates.
clearable boolean yes β€” Whether the alarm may clear automatically when the condition recovers.
clearDelay number (s) yes β€” Condition must be false (and the alarm clearable) this many seconds before it auto-clears.
value number optional β€” Current value attached to the fault (e.g. level, pressure) β€” recorded in state-change log entries.

Returns

number Current priority of the alarm while active, 0 when not alarming.

Example

let startTime = now();

while(run()){
  alm.g("UV"); // current alarm group

  let value = alm.e(
    alm.crit,                                        // priority
    "Reactor A Run Failure",                         // title
    startTime.sAgo() > 5 && startTime.sAgo() < 12,   // condition
    5,      // trigger delay (s)
    true,   // automatically clearable?
    0,      // clearing delay (s)
    startTime // optional attached value, logged on state changes
  );

  print("Run Time:", startTime.sAgo(), "  Fault Value:", value);
  waitMS(1000);
}

alm.v()

alm.v(group, [group2, …]) β†’ number

Returns the highest-priority active alarm within the given group(s).

If multiple faults exist in a group, returns the priority of the highest active one. Additional groups can be passed as extra arguments to aggregate across them.

Arguments

NameTypeRequiredDefaultDescription
group… string yes β€” One or more group names.

Returns

number Highest active priority in the group(s), 0 if none alarming.

Example

let groupValue = alm.v("UV");

alm.fV()

alm.fV(group, title) β†’ number

Returns the value of one specific fault.

Arguments

NameTypeRequiredDefaultDescription
group string yes β€” Group name, e.g. "UV".
title string yes β€” Fault title within the group.

Returns

number The fault’s current value.

Example

let faultValue = alm.fV("UV", "Reactor A Run Failure");

alm.list()

alm.list() β†’ object

Returns the status of every registered alarm, organised by group.

Returns

object e.g. {"UV":{"Reactor A Run Failure":0}} β€” 0 means not alarming; otherwise the active priority.

Example

let faults = alm.list();
print(string(faults)); // {"UV":{"Reactor A Run Failure":0}}

alm.max()

alm.max() β†’ number

Returns the highest active alarm priority across all groups.

A one-call health summary β€” useful for driving the status LED or a summary output:

setEnv("led", alm.max() >= alm.warn ? "red" : "green");

Returns

number Highest active priority overall, 0 when nothing is alarming.

Example

let max = alm.max();

alm.rst()

alm.rst([group, title])

Resets all faults, or one specific fault.

With no arguments, resets every registered fault. Pass a group and title to reset a single fault (e.g. a latched, non-clearable alarm after the cause has been fixed).

Arguments

NameTypeRequiredDefaultDescription
group string optional β€” Group of the fault to reset. Omit to reset everything.
title string optional β€” Title of the fault to reset.

Example

alm.rst();                              // reset all faults
alm.rst("UV", "Reactor A Run Failure"); // reset one fault

alm.ack()

alm.ack([group, title, [cancel]])

Acknowledges all faults, or one specific fault; pass false to cancel an acknowledgement.

With no arguments, acknowledges every fault. Pass a group and title to acknowledge a single fault. An optional false appended as the last argument cancels the acknowledgement.

Arguments

NameTypeRequiredDefaultDescription
group string optional β€” Group of the fault. Omit to acknowledge everything.
title string optional β€” Title of the fault.
cancel boolean optional true Pass false to cancel the acknowledgement.

Example

alm.ack();                                     // acknowledge all faults
alm.ack("UV", "Reactor A Run Failure");        // acknowledge one fault
alm.ack("UV", "Reactor A Run Failure", false); // cancel the acknowledgement