SET Functional Keyword
| Feature | Since Version | Notes | 
|---|---|---|
| SET | >v1.5.6 | Defines temporary variables | 
1. Overview
- Description:
    Defines a temporary variable within the current execution scope (e.g., within a single run of an ACTION'sDOblock). Variables created withSETare not persistent across different trigger events.
2. Signature
- Syntax:
3. Parameters
- "<variableName>": The name of the temporary variable to define (string).
- <value>: The value to assign. Can be a literal, an Entity, the result of- GET TOPIC, or an Expression.
4. Accessing Variables
Once set, variables are accessed by enclosing the variable name in curly braces {}.
5. Usage Examples
Basic Example
Set a variable and use it in a publish command.
DEFINE ACTION ProcessData
ON TOPIC "input/data" DO
    SET "processedValue" = (PAYLOAD * 10)
    PUBLISH TOPIC "output/processed" WITH {processedValue}
Intermediate Example
Retrieve topic values, store them in variables, perform calculations, and publish the result.
DEFINE ACTION CalculateSum
ON TOPIC "trigger/calculate" DO
    SET "valueA" = GET TOPIC "inputs/a"
    SET "valueB" = GET TOPIC "inputs/b"
    // Check if values were retrieved successfully
    IF {valueA} != EMPTY AND {valueB} != EMPTY THEN
        SET "sumResult" = {valueA} + {valueB}
        PUBLISH TOPIC "outputs/sum" WITH {sumResult}
    ELSE
        PUBLISH TOPIC "log/error" WITH "Missing input value(s)"
Advanced Example
Using variables to build a dynamic topic path and message.
DEFINE ACTION DynamicPublish
ON TOPIC "device/+/event" DO
    // Assuming payload is the device ID, e.g., "sensor01"
    SET "deviceID" = PAYLOAD
    SET "targetTopic" = "processed/" + {deviceID} + "/status"
    SET "messageContent" = "Device " + {deviceID} + " reported event at " + TIMESTAMP "ISO"
    PUBLISH TOPIC {targetTopic} WITH {messageContent}
6. Notes & Additional Information
- Variables defined by SETare temporary and local to the current action execution.
- They are useful for breaking down complex logic, storing intermediate results, or improving readability.
- Use KEEP TOPICif you need to store state persistently between action executions.