Written by Andrew Pasika
As described in the Rule Engine Getting Started, a trigger is an event or condition monitor that initiates rule execution. For a trigger to execute a rule, it must be attached to the rule. The same trigger can be attached to none, one, or many rules.
If a trigger is not attached to any rule, it is passive because it has nothing to execute. If a trigger is attached to one or more rules, it is active, meaning it will execute the rule(s) once the monitored condition occurs, e.g., a device posted telemetry.
As you may recall from Rule Engine Getting Started, a rule is always executed for a particular endpoint. The trigger is responsible for determining that endpoint.
A trigger always monitors conditions for an endpoint or a set of endpoints. An exception can only be a schedule trigger, which can run standalone—meaning not for a specific endpoint—if configured accordingly. If a trigger is configured for a specific endpoint, it monitors the condition only for that endpoint. If a trigger is configured for an application or application version, it monitors the condition for all endpoints belonging to that application or version.
All trigger types, among others, share a common set of fields:
Only one of these three options must be specified: either Application, Application version name, or Endpoints. These fields define for which endpoint(s) the attached rule(s) must be executed.
Executes a rule once the endpoint metadata is updated on a monitored endpoint. Metadata can be updated either via the UI or by the endpoint itself.
Executes a rule once an endpoint posts telemetry via the MQTT device API or the HTTP device API.
Executes a rule once the monitored time series value is updated.
Executes a rule once a monitored command type (e.g., SWITCH_ON
) is dispatched to an endpoint.
Commands are dispatched from the UI or via the REST API.
Executes a rule once an endpoint reports an executed command via the MQTT device API or the HTTP device API.
Executes a rule once a monitored alert lifecycle event occurs. Available alert lifecycle events:
HIGH
to CRITICAL
.CRITICAL
to HIGH
.Executes a rule based on a cron expression or at a specified interval.
The trigger can be configured without specifying an “Application”, “Application version name”, or “Endpoints” field.
If configured this way, it will execute the attached rule(s) only once — not for a specific endpoint — and ctx.endpoint
will not be available in the rule context.
If the application, application version name, or endpoints are specified, the schedule executes the attached rules for specified endpoints. However, because of the configured activating schedule, rules can be executed without relation to endpoints. In this case, the rule will be executed in a standalone mode, i.e., without endpoint-related context. It can be handy for periodic tasks, e.g., sending a report, data analysis, etc.