IF / THEN / ELSE Functional Keywords
| Feature | Since Version | Notes | 
|---|---|---|
| IF/THEN | >v1.4.4 | Core conditional logic | 
| ELSE | >v1.4.4 | Optional alternative block | 
Overview
- Description:
    These keywords implement conditional execution flow. An IFstatement evaluates a condition; if true, theTHENblock executes. Optionally, anELSEblock can be provided to execute if the condition is false.
Signature
- Syntax (with ELSE):
- Syntax (without ELSE):
Parameters
- <condition>: An Expression that evaluates to a boolean (- trueor- false). Typically involves comparisons (- ==,- >,- <, etc.) and logical operators (- AND,- OR,- NOT).
- <statements_if_true>: One or more LOT statements to execute if the condition is true.
- <statements_if_false>: (Optional) One or more LOT statements to execute if the condition is false.
Usage Examples
Basic Example (No ELSE)
Publish an alert only if the temperature exceeds a threshold.
DEFINE ACTION TemperatureAlert
ON TOPIC "sensors/temperature" DO
    IF PAYLOAD > 30 THEN
        PUBLISH TOPIC "alerts/temp" WITH "Temperature High!"
Intermediate Example (With ELSE)
Set a status based on a value.
DEFINE ACTION SetDeviceStatus
ON TOPIC "device/input" DO
    IF PAYLOAD == "ON" THEN
        KEEP TOPIC "internal/status" WITH "Active"
    ELSE
        KEEP TOPIC "internal/status" WITH "Inactive"
Advanced Example (Nested IF and Logical Operators)
Handle multiple conditions for complex alerting.
DEFINE ACTION ComplexAlerting
ON TOPIC "system/monitor" DO
    SET "cpu" = GET TOPIC "system/cpu_usage"
    SET "mem" = GET TOPIC "system/mem_usage"
    IF {cpu} > 90 OR {mem} > 95 THEN
        PUBLISH TOPIC "alerts/system" WITH "Critical Resource Usage!"
    ELSE
        IF {cpu} > 75 OR {mem} > 80 THEN
            PUBLISH TOPIC "warnings/system" WITH "High Resource Usage"
Example in Models
Conditional property definition within a DEFINE MODEL block.
DEFINE MODEL SensorStatus WITH TOPIC "sensor/status"
    ADD "value" WITH TOPIC "sensor/raw" AS TRIGGER
    ADD "statusText" WITH IF value > 100 THEN "Overload" ELSE "Normal"
Notes & Additional Information
- Code blocks within IFandELSEare defined by indentation.
- Conditions rely heavily on Comparison and Logical Operators.
- IFstatements can be nested.