Skip to main content

Why Paradigms Matter

LoT combines two programming approaches—imperative and declarative—each optimized for different tasks. Understanding when to use each one makes your code cleaner, more maintainable, and easier to debug.
Like a restaurant kitchen. Imperative commands are the chef shouting “Plate this now!” (immediate actions). Declarative definitions are the recipes and menu (structures that define how things work when triggered).

Two Ways to Write LoT

LoT uses two syntax styles based on what you’re doing:
Direct actions executed immediately by the broker. Use these inside Actions to do things right now.
PUBLISH TOPIC "alerts/temperature" WITH PAYLOAD
SET "counter" WITH (GET TOPIC "stats/count" + 1)
KEEP TOPIC "data/cached" WITH PAYLOAD
CALL ACTION "ProcessData"
CommandWhat it does
PUBLISHSend a message to a topic
SETStore a value in a variable
GETRetrieve a value from a topic or variable
KEEPPublish and retain a message
CALLExecute another Action

When to Use Each Paradigm

ScenarioParadigmExample
Publish a message nowImperativePUBLISH TOPIC "status" WITH "online"
React when data arrivesDeclarativeDEFINE ACTION ... ON TOPIC "input" DO
Store a calculation resultImperativeSET "total" WITH ({a} + {b})
Structure JSON outputDeclarativeDEFINE MODEL ... ADD STRING "id"
Connect to a databaseDeclarativeDEFINE ROUTE ... TO POSTGRESQL
Forward data in a loopImperativePUBLISH TOPIC "out" WITH PAYLOAD

The Four Building Blocks

Everything in LoT is built from four declarative constructs:
ConstructPurposeTrigger Types
ActionsExecute logic when events occurTime, Topic, System events, Manual
ModelsStructure MQTT data into JSON schemasTopic values, Action calls
RoutesConnect to external systemsTopic patterns
RulesControl who can publish/subscribeClient identity, Topic patterns
Actions contain your automation logic. They run when triggered:
TriggerSyntaxUse Case
Time-basedON EVERY 5 SECONDSHeartbeats, polling, scheduled tasks
Topic-basedON TOPIC "sensors/+"React to incoming data
CallableNo trigger clauseUtility functions, subroutines
SystemON START, ON STOPInitialization, cleanup
Inside an Action, you use imperative commands like PUBLISH, SET, IF/THEN, and CALL.
Models define JSON structures that auto-publish when their trigger fields update:
Field TypePurpose
STRING, INT, DOUBLE, BOOLTyped data fields
AS TRIGGERField that activates the model when it changes
FROMInherit fields from another model
Models eliminate manual JSON formatting—define the schema once, and data flows automatically.
Routes connect your MQTT infrastructure to external systems:
CategoryExamples
Data StoragePostgreSQL, MongoDB, CrateDB, OpenSearch
Data PipelineMQTT bridges, email, HTTP webhooks
IndustrialOPC-UA, Modbus, Siemens S7, Allen-Bradley
SystemBroker clustering, replication
Routes are declarative—you define what to connect, and the broker handles the how.
Rules define access control at the broker level:
ControlDescription
Publish permissionsWho can send messages to which topics
Subscribe permissionsWho can receive messages from which topics
Client identityMatch rules to specific clients or patterns
Rules enforce security policies without modifying your Actions or Models.

How They Work Together

A typical LoT solution combines all four building blocks:
-- 1. ROUTE: Connect to PostgreSQL
DEFINE ROUTE SensorDB TO POSTGRESQL
    CONNECTION "Host=db.local;Database=iot"
    TOPIC "sensors/#"

-- 2. MODEL: Structure incoming data
DEFINE MODEL SensorReading WITH TOPIC "sensors/formatted"
    ADD STRING "device_id" WITH TOPIC "sensors/id"
    ADD DOUBLE "temperature" WITH TOPIC "sensors/raw" AS TRIGGER

-- 3. ACTION: Process and alert
DEFINE ACTION TemperatureAlert
ON TOPIC "sensors/formatted" DO
    SET "temp" WITH (GET JSON "temperature" IN PAYLOAD AS DOUBLE)
    IF {temp} > 80 THEN
        PUBLISH TOPIC "alerts/high_temp" WITH PAYLOAD

-- 4. RULE: Restrict who can publish alerts
DEFINE RULE AlertAccess
    DENY PUBLISH "alerts/#" FOR ALL
    ALLOW PUBLISH "alerts/#" FOR "system-*"
StepWhat Happens
1Route stores all sensors/# data to PostgreSQL
2Model transforms raw data into structured JSON
3Action checks thresholds and publishes alerts
4Rule ensures only system clients can write alerts

Next Steps