Skip to content

LOT Actions

1. Introduction

The Coreflux LOT scripting language is used to define Actions—small logic blocks that react to events (time-based or topic-based) and publish data to topics. This document details each element of the syntax so you can understand how LOT interprets your code.

1.1 Overall Structure

Each Action starts with the keyword:

DEFINE ACTION <ActionName>

followed by one of the event triggers (e.g., ON EVERY ..., ON TOPIC ..., etc.) and a logic block describing what to do when that event occurs. Within the logic block, you can use IF statements, or simply do one or more PUBLISH instructions.

Example structure:

DEFINE ACTION MyAction
ON EVERY 5 SECONDS DO
    IF <expression> THEN
        PUBLISH ...
    ELSE
        PUBLISH ...

1.2 Indentation

LOT uses indentation to visually separate blocks of code and highlight logic flow. While indentation levels can be set by tabs or spaces, be consistent.

  • Top-level lines (like DEFINE ACTION MyAction and ON EVERY 5 SECONDS DO) begin at the leftmost column.
  • Nested lines (the statements inside the DO block, or inside an IF THEN or ELSE block) are indented.

This helps LOT (and readers) understand which statements belong to which blocks.


2. Event Triggers

An Action is activated by specifying the condition or event that should trigger its execution. Some common triggers are:

  1. ON EVERY <time> – runs on a repeating interval.
  2. Example: ON EVERY 5 SECONDS DO executes the block every 5 seconds.
  3. Other intervals can be MINUTES, HOURS, etc.

  4. ON TOPIC <topic> – runs whenever the specified topic is published to.

  5. Example: ON TOPIC "myTopic" DO executes whenever a message arrives on "myTopic".

3. Expressions in LOT

LOT expressions can retrieve data from a topic, compare values, or perform mathematical operations.

3.1 GET TOPIC "<topic>"

Retrieves the most recent payload of a specific MQTT topic.

Example:

GET TOPIC "my/sensor/temperature"

3.2 Mathematical Operations

The following operators are supported on numeric values:

  • + (addition)
  • - (subtraction)
  • * (multiplication)
  • / (division)
  • % (modulo, returns the remainder of a division)

Example:

(GET TOPIC "some/number" + 1)
(GET TOPIC "some/number" % 2)

3.3 Comparisons

You can compare values using ==, !=, <, >, <=, >=, etc.

Example:

IF GET TOPIC "switchState" == "on" THEN ...
IF (GET TOPIC "some/number" % 2) = 0 THEN ...

(Both == and = can be used in certain comparisons; it depends on your broker’s LOT version. Check your Coreflux documentation.)


4. The IF THEN ELSE Logic

LOT supports conditional logic through an IF <expression> THEN and optional ELSE:

IF <condition> THEN
    <statements if condition is true>
ELSE
    <statements if condition is false>
  • Condition: A boolean expression (e.g., GET TOPIC "switchState" == "off").
  • THEN block: One or more PUBLISH statements (or other logic).
  • ELSE block (optional): Executed when the condition is not met.

Example:

IF GET TOPIC "my/light" == "off" THEN
    PUBLISH TOPIC "my/light" WITH "on"
ELSE
    PUBLISH TOPIC "my/light" WITH "off"

5. Special Keywords

5.1 PAYLOAD

PAYLOAD refers to the value that triggered the Action in an ON TOPIC event. Whenever an action is triggered by a topic publication, PAYLOAD holds that newly published value.

For instance, in an action triggered by ON TOPIC "input2/topic":

DEFINE ACTION MyAction
ON TOPIC "input2/topic" DO
    PUBLISH TOPIC "some/otherTopic" WITH (PAYLOAD + 1)
  • Here, PAYLOAD is the last message content published to input2/topic.
  • (PAYLOAD + 1) increments that value, then publishes the result.

5.2 TIMESTAMP

TIMESTAMP is used to insert the current date/time (in UTC or local format, depending on your syntax) into the published data.

PUBLISH TOPIC "my/topic" WITH TIMESTAMP "UTC"
  • This sends a message to "my/topic" that contains a JSON object or string with the current UTC time (exact format may depend on your Coreflux version).

6. Example Actions

Below are four sample Actions demonstrating the syntax.

6.1 StrokeGenerator

DEFINE ACTION StrokeGenerator
ON EVERY 5 SECONDS DO
    IF GET TOPIC "Coreflux/Porto/MeetingRoom/Light1/command/switch:0" == "off" THEN
        PUBLISH TOPIC "Coreflux/Porto/MeetingRoom/Light1/command/switch:0" WITH "on"
        PUBLISH TOPIC "Coreflux/Porto/MeetingRoom/Light1/command/switch:0/counter" WITH (GET TOPIC "Coreflux/Porto/MeetingRoom/Light1/command/switch:0/counter" + 1)
    ELSE
        PUBLISH TOPIC "Coreflux/Porto/MeetingRoom/Light1/command/switch:0" WITH "off"
  • Trigger: Every 5 seconds.
  • Logic:
  • Retrieves the current state of "Coreflux/Porto/MeetingRoom/Light1/command/switch:0".
  • If that state is "off", turn it "on" and increment its counter.
  • Otherwise, turn it "off".

6.2 ChangeOfTopic

DEFINE ACTION ChangeOfTopic
ON TOPIC "input2/topic" DO
    PUBLISH TOPIC "input2/topic" WITH (PAYLOAD + 1)
  • Trigger: A message is published to "input2/topic".
  • Logic:
  • Whatever the PAYLOAD is (assuming it’s numeric), increment it by 1, then publish the new value back to the same topic.

6.3 SHOWTIMEEVERY5SECONDS

DEFINE ACTION SHOWTIMEEVERY5SECONDS
ON EVERY 5 SECONDS DO
    PUBLISH TOPIC "input2/topic" WITH TIMESTAMP "UTC"
  • Trigger: Every 5 seconds.
  • Logic:
  • Publish the current UTC time to "input2/topic".

6.4 CheckIfPar

DEFINE ACTION CheckIfPar
ON EVERY 1 MINUTE DO
    IF (GET TOPIC "input2/topic" % 2) = 0 THEN
        PUBLISH TOPIC "teste" WITH "pair"
    ELSE
        PUBLISH TOPIC "teste" WITH "odd"
  • Trigger: Every 1 minute.
  • Logic:
  • Checks the value of input2/topic.
  • If that value is even (% 2 = 0), publish "pair" to teste. Otherwise, publish "odd".

7. Adding or Removing Actions

To add an Action in Coreflux, you publish its entire DEFINE ACTION snippet to the special system topic "$SYS/Coreflux/Command", using the parameter -addAction.

Example: Add StrokeGenerator:

Topic: $SYS/Coreflux/Command
Payload:
publish -addAction 
DEFINE ACTION StrokeGenerator
ON EVERY 5 SECONDS DO
    IF GET TOPIC "Coreflux/Porto/MeetingRoom/Light1/command/switch:0" == "off" THEN
        PUBLISH ...
    ...

Once accepted, the broker will store and run this Action. You can confirm it by checking "$SYS/Coreflux/Actions".

Removing Actions

Similarly, to remove an existing Action, publish to the same system topic with -removeAction <ActionName>:

Topic: $SYS/Coreflux/Command
Payload:
publish -removeAction StrokeGenerator

8. Important

  • Indentation clarifies logic blocks and nested statements.
  • Expressions let you retrieve topic payloads, do math, and compare values.
  • IF THEN ELSE controls logic flow based on your conditions.
  • PAYLOAD references incoming data; TIMESTAMP injects the current time.
  • Events can be triggered by time intervals (ON EVERY) or by topic messages (ON TOPIC).

With these fundamentals, you can create custom Actions to automate logic within the Coreflux broker using LOT.