Skip to main content

Conditions

The conditions field of a rule represents the set of conditions that must be simultaneously verified for that rule to be applied. In other words, this implements the AND operation between conditions: to implement the OR operation, it is sufficient to create multiple rules.

Each condition is characterized by a status, analogous to what has already been described for the rules. As already stated, the status of a rule will be determined based on the status of all the conditions that make up the rule itself.

The type of condition is identified by the type field, whereas all the specific information of that condition is contained within the params object.

Threshold conditions

A threshold condition is defined by:

export interface CptThresholdCondition {
id: string;
type: CptConditionType;
params: {
metric: string;
comparisonOperator: CptComparisonOperator;
unit: string;
threshold: number;
durationSecs: number | 0;
activeWindow?: {
from: string;
to: string;
timezone: string;
};
};
status: CptActivityStatus;
createdAt?: string;
updatedAt?: string;
deletedAt?: string;
}

In particular:

  • metric identifies the URN to be analyzed. This field carries information about:
    • device
    • timeseries
  • comparisonOperator defines the type of comparison (e.g. greater than, less than, etc.)

It is defined as an enum:

export enum CptComparisonOperator {
GreaterThan = '>',
GreaterThanOrEqual = '>=',
LessThan = '<',
LessThanOrEqual = '<=',
Equal = '==',
NotEqual = '!=',
}
  • durationSecs defines for how long the condition must be verified before being considered active. In the case where this value equals zero, the first sample of the selected metric for which the comparison is satisfied will trigger the condition
  • activeWindow represents the time interval (UTC time, e.g. "12:00") within which the condition must be evaluated. The timezone attribute allows to specify the user's timezone at the moment of rule creation.

For correlation conditions, the data structure is analogous: N threshold conditions are passed, allowing you to identify from each metric field the device and the timeseries of interest.

Delta conditions

Delta conditions are similar to Threshold conditions, and they are used to detect whether a certain metric has changed (or not) by a certain amount in a certain time window.

For example, you can create a delta condition to monitor the temperature rise when your home boiler is working: if the temperature does not rise by a certain amount, something may be wrong.

export interface CptDeltaCondition {
id: string;
type: CptConditionType;
params: {
metric: string;
comparisonOperator: CptComparisonOperator;
unit: string;
delta: number;
durationSecs: number | 0;
activeWindow?: {
from: string;
to: string;
timezone: string;
};
};
status: CptActivityStatus;
createdAt?: string;
updatedAt?: string;
deletedAt?: string;
}

Offline device conditions

An offline device condition is defined based upon how long it has been since the last message was sent.

export interface CptLastMessageOlderThanCondition {
id: string;
type: CptConditionType;
params: {
channelId: string;
durationSecs: number;
};
status: CptActivityStatus;
createdAt?: string;
updatedAt?: string;
deletedAt?: string;
}

In particular, in addition to what has already been seen for the threshold conditions:

  • channelId uniquely identifies the publisher. This is the id of the data topic of the device, if connected via MQTT

External matching conditions

This API is currently not exposed, but it is accessible only from within the Connhex Rules Engine service.

Notifications

Connhex Rules Engine leverages the Connhex Notifications service to send notifications. The supported formats and details are reported in the Connhex Notifications section.