As mentioned in the Rule Engine Getting Started, the Rule Engine is a tool that allows you to create automated actions based on specific conditions or events generated by IoT devices.
The Rule Engine is built on three parts: trigger, rule, and action.
A trigger is an event or condition that initiates rule execution. In other words, a trigger listens for events of a particular type and, once it occurs (e.g., the device posts data), it executes the attached rule(s).
See triggers to learn more about triggers and their types.
A JavaScript expression that is executed for the endpoint. Usually, a rule returns a value, and based on this returned value, the Rule Engine decides which actions to execute next — Positive, Negative, or no actions at all.
An action is an operation performed after a rule is executed and returns a value.
Like a trigger, an action is attached to a rule.
There are two types of actions: Positive and Negative.
Positive actions are executed if the rule returns true
or any other value except false
, null
, or undefined
.
Negative actions are executed if the rule returns false
.
No actions are executed if the rule returns null
or undefined
.
Let’s put this into an example: