Custom Logic Blocks
A Custom Logic Block can be used to evaluate complex logic that can not be implemented with a simple comparison block.
A set of example logic blocks can be found here:
If a condition is met, an action has to be emitted that will invoke the consecutive rule actions.
if (currentTemperature > threshold) {
emit("action", {
message: `temperature (${currentTemperature} °C) is above threshold (${threshold} °C)`,
});
}
It is possible to re-invoke the rule engine by enabling the setting in the rule action. This is useful, to apply another rule to the output of a custom logic block.
Note that the emit action is expected to have a specific format (same structure as the sample output in device type scripts), see Emit Function for details. This means that properties like
topic
, timestamp (optional)
and data
should be provided and will be processed in subsequent rules.if (currentTemperature > threshold) {
emit("action", {
data: { temperature, threshold, message: `temperature (${currentTemperature} °C) is above threshold (${threshold} °C)` },
topic: "alert"
});
}java
If the
topic
is specified in the emit action, it will override the one specified in the custom akenza db rule action.When using a custom payload template in the rule action, make sure to use
{{result.*}}
to access data that has been emitted as part of the rule action. For example, to store the result of a rule action that has been used to re-invoke the rule engine, use {{result.data}}
. Otherwise the whole result object will be stored as a sample meaning topic
, timestamp
, data
and meta
(if specified) will be contained in the data object.Last modified 5mo ago