AS TRIGGER Functional Keyword
Feature | Since Version | Notes |
---|---|---|
AS TRIGGER |
>v1.4.6 | Marks trigger property in Models |
Overview
- Description:
Used exclusively within
DEFINE MODEL
blocks when adding a property that references an input topic (ADD "prop" WITH TOPIC "..."
). TheAS TRIGGER
modifier designates this specific property's input topic as the trigger for the model's recalculation. When a new message arrives on this trigger topic, the model re-evaluates all its properties and publishes the results.
Signature
- Syntax:
Parameters
- This keyword modifies an
ADD
statement within aDEFINE MODEL
. It doesn't take parameters itself but follows theWITH TOPIC
part.
Usage Examples
Basic Example
Define a model where changes to raw/temperature
trigger updates.
DEFINE MODEL TemperatureConverter WITH TOPIC "processed/temperature"
// When "raw/temperature" changes, the model runs:
ADD "celsius" WITH TOPIC "raw/temperature" AS TRIGGER
// These properties are calculated based on the new 'celsius' value:
ADD "fahrenheit" WITH (celsius * 9/5 + 32)
ADD "kelvin" WITH (celsius + 273.15)
Intermediate Example (Multiple Inputs, One Trigger)
A model can have multiple input topics, but only one is marked AS TRIGGER
.
DEFINE MODEL PowerCalculation WITH TOPIC "power/output"
ADD "voltage" WITH TOPIC "sensor/voltage" // Input, but not trigger
ADD "current" WITH TOPIC "sensor/current" AS TRIGGER // Trigger!
ADD "power_watts" WITH (voltage * current) // Calculated when 'current' changes
sensor/current
receives an update. It uses the last known value of sensor/voltage
(retrieved via GET TOPIC
implicitly by the model engine).
Notes & Additional Information
- A
DEFINE MODEL
block must have exactly one property marked withAS TRIGGER
. - This is how the LOT engine knows when to execute the model's logic.