akenza.io
Search…
Rule Logic - Custom Logic Blocks
This page describes the Custom Logic Blocks in more detail
Custom Logic Blocks allow the implementation of more complex business logic with the akenza Rule Engine. They enable simple stateless and stateful operations upon rule trigger using custom scripts in Javascript. Custom Logic Blocks are created on organization-level and are therefore available in all workspaces and can be selected when creating a rule. Custom Logic Blocks are only available in the Expert Plan.
This webinar explains how to create Custom Rules:
Webinar about how to create Custom Rules
A Custom Logic Block consists of a definition of:
  • Inputs: the dynamic data that is evaluated during script execution (sensor data)
  • Parameters: constant values like thresholds
  • A script used to run the logic
In order to keep its usage consistent, it is not possible to edit custom logic inputs and parameters if the Custom Logic Block is assigned to an active rule.

Inputs

Inputs specify the input data sources for a Custom Logic Block and contain the dynamic data of a device. At least one input needs to be defined in order to create a Custom Logic Block.
Field
Description
Input display/ label name
The input name
Input description
An optional description
Input variable name
A variable name used to access the value inside the script
Default topic
An optional default topic that is preselected when using the logic block
Default data key
An optional default data key that is preselected when using the logic block

Parameters

Parameters represent static properties that are available during script runtime.
Field
Description
Parameter display/label name
The parameter name
Parameter variable name
A variable name used to access the parameter inside the script
Parameter Type
The data type of the parameter; Numerical, String, or Boolean
Default value
A default value for the parameter

Rule logic script

The Rule logic script defines the custom logic that is evaluated during rule runs.
1
function consume(event) {
2
var temperature = event.inputs.temperature;
3
var threshold = event.properties.tempThreshold;
4
5
if (temperature < threshold) {
6
emit("action", {
7
message: `it is too cold: the temperature is ${temperature}°C`,
8
});
9
}
10
}
Copied!
Once a Custom Logic Block is saved, it can be selected when creating a rule. Inputs need to be linked to an input device or tag and parameters need to be set. Further, one or more actions need to be defined. The templating syntax can be used to access the results of a Custom Logic Block {{result.*}}. For example, {{result.message}} for the script shown above.
Refer to Stateful Operations for more information on how to share data between runs of a rule.
Last modified 2mo ago