Skip to main content

General

Rule Expression Syntax

Complete reference for writing automation rules using the Criteria Language.

Proxus uses a powerful Criteria Language to evaluate rules against incoming data. The rule engine supports four event types:

  1. DataReceived (TransportData) - Device telemetry and sensor data
  2. StatusChanged (DeviceStatus) - Device connection status changes
  3. LogReceived (Log) - System log messages for monitoring and alerting
  4. MetricsReceived (ProxusActorMetrics) - Actor performance metrics

Each event type evaluates criteria against a different data model.

Prefer a graphical interface? See the Visual Rule Editor.

Data Access Syntax

The rule engine evaluates conditions against collections of data. You use the bracket [...] syntax to filter these collections.

CollectionDescriptionAccess Pattern
PayloadList of metrics (e.g., Temperature, Voltage).[Payload][Key = 'Temp' AND NumericValue > 50]
MetaDataList of device metadata (e.g., DeviceId).[MetaData][Key = 'Location' AND Value = 'Zone1']
AttributesDictionary of extra attributes.[Attributes][Key = 'Priority' AND Value = 'High']
TopicThe message topic (String).[Topic] = 'Device123'

Important: Bracket Logic

When you place multiple conditions inside a single bracket block, they must apply to the same item in the collection.

  • Correct: [Payload][Key = 'Temp' AND NumericValue > 50]
  • (Find an item where Key is 'Temp' AND its Value is > 50)
  • Incorrect: [Payload][Key = 'Temp'] AND [Payload][NumericValue > 50]
  • (Find an item where Key is 'Temp', AND find ANY item where Value is > 50. These might be different items!)

Operators & Functions

Comparison & Logic

OperatorDescriptionExample
=, !=, <>Equality[Topic] = 'Gen1'
>, >=, <, <=Numeric ComparisonNumericValue > 100
AND, OR, NOTLogical OperatorsCondition1 AND NOT Condition2
[v] BETWEEN(min, max)Range CheckNumericValue BETWEEN(10, 20)
[v] IN(list)List CheckValue IN ('A', 'B', 'C')

String Functions

FunctionDescriptionExample
Contains(str, substr)Checks for substring.Contains(Value, 'Error')
StartsWith(str, prefix)Checks prefix.StartsWith(Value, 'Sensor')
EndsWith(str, suffix)Checks suffix.EndsWith(Value, '.log')
Len(str)String length.Len(Value) > 5
Upper(str), Lower(str)Case conversion.Upper(Value) = 'OK'
Replace(str, old, new)Replace text.Replace(Value, '-', '')

Date & Time Functions

FunctionDescriptionExample
Now()Current server time.Time > AddMinutes(Now(), -5)
AddMinutes(date, n)Add/Subtract minutes.Time < AddMinutes(PreviousValueTime, 10)
AddHours(date, n)Add/Subtract hours.Time >= AddHours(Now(), -1)
AddDays(date, n)Add/Subtract days.Time >= AddDays(Now(), -1)
GetYear(date)Extract year.GetYear(Time) = 2024

Utility Functions

FunctionDescriptionExample
Iif(cond, true, false)Inline If.Iif(NumericValue > 10, 'High', 'Low')
IsNullOrEmpty(str)Check for null/empty.IsNullOrEmpty(Value)
ToDouble(str)Convert string to number.ToDouble(Value) > 5.5
Abs(n)Absolute value.Abs(NumericValue) > 10

Common Scenarios

1. Simple Threshold

Trigger if the "Temperature" tag is above 80.

[Payload][Key = 'Temperature' AND NumericValue > 80]

2. Device & Value Filter

Trigger if "Pressure" is low AND it comes from a specific device.

[MetaData][Key = 'DeviceName' AND Value = 'Pump01']
AND
[Payload][Key = 'Pressure' AND NumericValue < 10]

3. Change Detection (Delta)

Trigger if "Speed" changed by more than 5 units compared to the previous value.

[Payload][Key = 'Speed' AND Abs(NumericValue - ToDouble(PreviousValue)) > 5]

4. Deadband / Range

Trigger if "Voltage" is outside the safe range (220-240).

[Payload][Key = 'Voltage' AND NOT (NumericValue BETWEEN(220, 240))]

5. Time Gap (Stale Data)

Trigger if the new value arrived more than 10 minutes after the previous one.

[Payload][Key = 'Heartbeat' AND Time >= AddMinutes(PreviousValueTime, 10)]

Device Status Rules

When the Rule Event is set to Status Changed, criteria are evaluated against the DeviceStatus object (not TransportData).

PropertyDescription
DeviceIdUnique ID of the device.
DeviceNameName of the device.
CurrentConnectionStatusConnected or Disconnected.
PreviousConnectionStatusConnected or Disconnected.
ConnectionDurationDuration in seconds in the current state (Double).

Example: Device Disconnected

CurrentConnectionStatus = 'Disconnected'

Log-Based Rules

When the Rule Event is set to Log Received, criteria are evaluated against the Log object. This allows you to monitor system logs and trigger alerts based on specific log patterns.

PropertyDescription
MessageThe log message content (String).
LevelLog severity: Trace, Debug, Information, Warning, Error, Critical.
CategoryLog category/source (e.g., Proxus.ProtocolDrivers or Proxus.SystemCore).
SourceLog source identifier.
TimeTimestamp of the log entry (DateTime).
warning
Infinite Loop Prevention

CRITICAL: Log rules can trigger actions (like notifications) that themselves generate logs. To prevent infinite loops:

  • Use strict criteria (specific categories, levels, or message patterns)
  • Apply rate limiting (e.g., max 10 actions per 60 seconds)
  • Avoid overly broad criteria like Level = 'Error'

The platform automatically filters out rule engine logs to prevent self-triggering.

Example 1: Critical Errors

Level = 'Critical' OR Level = 'Error'

Metrics-Based Rules

When the Rule Event is set to Metrics Received, criteria are evaluated against the ProxusActorMetrics object. This enables monitoring of actor performance and data quality metrics.

PropertyDescription
DeviceDevice or service identifier (String).
TotalRequestsTotal number of requests processed (Int64).
SuccessfulRequestsNumber of successful requests (Int64).
FailedRequestsNumber of failed requests (Int64).
TotalDataReceivedTotal data packets received (Int64).
AverageResponseTimeAverage response time in milliseconds (Double).
ResponseCountTotal valid responses received (Int64).
ProcessedDataCountTotal unique data points processed (Int64).
ReadErrorCountNumber of protocol read errors (Int64).
ReadErrorPercentagePercentage of requests that failed (0-100).
DataAccuracyData quality metric: accuracy percentage (0-100).
DataCompletenessData quality metric: completeness percentage (0-100).
DataFreshnessData quality metric: freshness percentage (0-100).
DataIntegrityData quality metric: integrity percentage (0-100).
DataConsistencyData quality metric: consistency percentage (0-100).
ConnectionErrorCountNumber of connection errors (Int64).
SleepModeTransitionCountNumber of times device entered sleep mode (Int64).
LastCommunicationTimeLast communication timestamp (DateTime).
LastDataReceivedTimeLast valid data packet timestamp (DateTime).
info
Performance Monitoring

Metrics rules are ideal for:

  • Monitoring service health and performance
  • Detecting degraded service quality
  • Alerting on high error rates
  • Tracking data quality trends

Recommended Rate Limiting: Max 5 actions per 300 seconds (5 minutes)


Anomaly Detection

For statistical analysis over a sliding window (e.g., Z-Score, Moving Average), select the Anomaly Detection mode in the Rules Engine.

In Anomaly Detection mode, you can still use Criteria Expressions to act as a pre-filter. Only data matching the criteria will be fed into the statistical model (e.g., [Payload][Key='Vibration']).