Skip to main content

Overview

Actions are executable logic blocks that run directly inside the Coreflux MQTT broker. They react to events—incoming messages, time intervals, or manual triggers—and perform operations like data transformation, routing, and alerting.
Think of Actions like a mail sorting machine. When a letter (message) arrives, the machine reads the address (topic), decides where it should go (routing logic), and sends it to the right mailbox (publishes to a topic). All of this happens instantly, without needing a person to manually sort each letter.

Action Capabilities

CapabilityDescription
Event-Driven ExecutionTrigger on MQTT messages with wildcard support for flexible topic matching
Time-Based SchedulingExecute at regular intervals—seconds to weeks—for monitoring and reporting
Data TransformationExtract JSON fields, perform calculations, and restructure payloads inline
Conditional LogicRoute data, set thresholds, and make decisions with IF/THEN/ELSE

When to Use Each Pattern

PatternUse When
Time-Based (ON EVERY)Periodic tasks: heartbeats, polling, scheduled reports
Topic-Based (ON TOPIC)Event-driven processing: sensor data, commands, alerts
Callable (no trigger)Reusable utilities invoked by other actions or commands
Python-Extended (CALL PYTHON)Complex calculations, external libraries, data validation

In This Section


Action Types

LoT supports three action patterns:

Time-Based Actions

Execute at regular intervals using ON EVERY:
DEFINE ACTION SystemHeartbeat
ON EVERY 5 SECONDS DO
    PUBLISH TOPIC "system/status" WITH "online"
    PUBLISH TOPIC "system/timestamp" WITH TIMESTAMP "UTC"
Like an alarm clock that rings every 5 minutes. Time-based actions don’t wait for anything to happen—they just run on a schedule. Use them for tasks like “check if the system is still alive” or “send a status report every hour.”
Key characteristics:
  • Runs on a schedule regardless of incoming data
  • Useful for monitoring, polling, and periodic reports
  • Supported units: SECONDS, MINUTES, HOURS, DAYS, WEEKS

Topic-Based Actions

Execute when MQTT messages arrive using ON TOPIC:
DEFINE ACTION TemperatureProcessor
ON TOPIC "sensors/+/temperature" DO
    SET "sensor_id" WITH TOPIC POSITION 2
    SET "temp" WITH (GET JSON "value" IN PAYLOAD AS DOUBLE)
    
    IF {temp} > 80 THEN
        PUBLISH TOPIC "alerts/high_temp/" + {sensor_id} WITH PAYLOAD
    ELSE
        PUBLISH TOPIC "processed/" + {sensor_id} WITH PAYLOAD
Like a doorbell that triggers a camera. When someone presses the doorbell (a message arrives), the camera turns on and records (the action runs). Topic-based actions wait for specific messages and react immediately.
Key characteristics:
  • Triggers instantly when matching messages arrive
  • Supports + (single-level) and # (multi-level) MQTT wildcards
  • Access payload data via PAYLOAD and GET JSON
  • Extract topic segments with TOPIC POSITION

Callable Actions

Actions without triggers are invoked manually or by other actions:
DEFINE ACTION CalculateAverage
INPUT value1 AS DOUBLE
INPUT value2 AS DOUBLE
DO
    SET "avg" WITH (({value1} + {value2}) / 2)
RETURN
    OUTPUT avg
Like a calculator app on your phone. It doesn’t do anything until you open it and type numbers. Callable actions are reusable tools that other actions can “call” when they need help with a specific task.
Key characteristics:
  • No automatic trigger—must be invoked explicitly
  • Can accept input parameters and return values
  • Invoked via $SYS/Coreflux/Command or CALL ACTION
  • Ideal for reusable utility functions
Learn more about invoking callable actions in Action Triggers.

Core Operations

Actions use these operations to process data:
SET, GET TOPIC, GET JSON, PUBLISH, and IF/THEN are the core operations for working with data in actions. See the Operations Reference for complete details.
Operations are the verbs of LoT. Just like in English you “read,” “write,” and “decide,” in LoT you GET data, PUBLISH messages, and use IF/THEN to make decisions.
Create and use variables within an action:
SET "sensor_id" WITH TOPIC POSITION 2
SET "temperature" WITH (GET TOPIC "sensors/temp" AS DOUBLE)
SET "humidity" WITH (GET JSON "humidity" IN PAYLOAD AS DOUBLE)

PUBLISH TOPIC "output/" + {sensor_id} WITH {temperature}

Example: Complete Sensor Processor

This example combines topic matching, JSON extraction, conditional routing, and state updates in a realistic sensor processing action.
DEFINE ACTION SensorDataProcessor
ON TOPIC "sensors/+/raw" DO
    // Extract sensor ID from topic path
    // Topic: sensors/temp001/raw → POSITION 2 = "temp001"
    SET "sensor_id" WITH TOPIC POSITION 2
    
    // Parse JSON payload
    SET "temp_value" WITH (GET JSON "temperature" IN PAYLOAD AS DOUBLE)
    SET "humidity" WITH (GET JSON "humidity" IN PAYLOAD AS DOUBLE)
    
    // Conditional routing based on thresholds
    IF {temp_value} > 80 THEN
        PUBLISH TOPIC "alerts/high_temp/" + {sensor_id} WITH PAYLOAD
    ELSE IF {temp_value} < 10 THEN
        PUBLISH TOPIC "alerts/low_temp/" + {sensor_id} WITH PAYLOAD
    ELSE
        PUBLISH TOPIC "sensors/normal/" + {sensor_id} WITH PAYLOAD
    
    // Always update the processed output
    PUBLISH TOPIC "sensors/processed/" + {sensor_id} WITH PAYLOAD
    
    // Record the last update timestamp
    PUBLISH TOPIC "sensors/" + {sensor_id} + "/last_update" WITH TIMESTAMP "UTC"
What this does:
  1. Triggers when any message arrives at sensors/*/raw
  2. Extracts the sensor ID from the topic path
  3. Parses temperature and humidity from the JSON payload
  4. Routes alerts based on temperature thresholds
  5. Publishes processed data and timestamps

Actions vs. Models

Actions and Models serve different purposes in LoT:
AspectActionsModels
PurposeProcess and route dataStructure and format data
ExecutionEvent-driven logicSchema definition
OutputAny MQTT operationStructured JSON
ComplexityConditionals, loops, PythonField mapping, calculations
Best ForRouting, alerting, transformationData aggregation, formatting
Actions are the workers, Models are the forms. Actions do the work (process, route, decide), while Models define what the finished paperwork looks like (structured JSON output). Use them together: Actions fill out and submit Model forms.

Next Steps