Skip to content

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 "..."). The AS 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:
    ADD "<propertyName>" WITH TOPIC "<topicPath>" AS TRIGGER
    

Parameters

  • This keyword modifies an ADD statement within a DEFINE MODEL. It doesn't take parameters itself but follows the WITH 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
Note: In this example, the model recalculates only when 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 with AS TRIGGER.
  • This is how the LOT engine knows when to execute the model's logic.