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)`, });}
Re-invoking the rule engine
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 the topic is specified in the emit action, it will override the one specified in the custom akenza db rule action.
Rule Action - Custom Payload
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.
Emitting a timer
By emitting a timer, you can schedule a rule to run be invoked again in the future.
emit("timer", { runAt:newDate(Date.now() +60*60*1000),//the timestamp of when the rule should be invoked meta: {} //metadata that will be available during the invocation of the time });
meta can then be accessed using event.timer.meta.
Event examples
Logic Block uplink event
A decoded uplink that triggers a custom logic block, looks as follows. Note that the state is controlled by the script author (see Stateful Operations):
A time-based event that triggers a custom logic block, looks as follows. Note that the state is controlled by the script author (see Stateful Operations):