Skip to main content

Overview

Every Action needs a trigger—the event that starts its execution. Choosing the right trigger type determines how your automation responds to real-world conditions.
Think of triggers like different ways to start your car. A time-based trigger is like an auto-start that warms up your car every morning at 7 AM. A topic-based trigger is like pushing the start button when you get in. A callable action is like asking someone else to start it for you.

When to Use Each Type


Time-Based Triggers

LoT supports several time-based trigger forms. All of them use the ON keyword and run the action’s DO block automatically—no MQTT message is required to fire them. Together they cover recurring intervals, calendar rules (a specific weekday, Monday–Friday, or Saturday–Sunday), daily wall-clock times, and single one-shot executions.

Quick reference

Time zone: For HH:mm and HH:mm:ss in ON EVERY … AT and in daily ON TIMESTAMP, values are interpreted in the local time of the machine running the broker, then converted to UTC internally. The action is scheduled for the correct wall-clock time across daylight saving changes. The one-shot form dd-MM-yyyy HH:mm:ss is interpreted as UTC, as described below.
Structured payloads: PUBLISH TOPIC does not support inline JSON object literals. For multi-field records, define a COLLAPSED model and use PUBLISH MODEL … TO … WITH (see Publishing Models). The timed-action examples below use that pattern.

1. ON EVERY N UNIT — fixed interval

Fires repeatedly every N units of time. Common for monitoring, polling, and heartbeats.

Supported units

Singular and plural unit names are interchangeable (for example, 1 SECOND and 1 SECONDS). ON EVERY 1 DAY fires every 24 hours from the last run; for the same clock time every calendar day, use daily ON TIMESTAMP instead.

2. ON EVERY DAY AT — weekly, specific day

Fires once per week on the named weekday at the given local time. Use "HH:mm" or "HH:mm:ss"; seconds are optional.

3. ON EVERY WEEKDAY AT — Monday–Friday

Fires Monday through Friday at the same local time—one action instead of five separate daily schedules.

4. ON EVERY WEEKEND AT — Saturday and Sunday

Fires on both weekend days at the specified local time—useful for maintenance windows or weekend-only reporting.

5. ON TIMESTAMP — daily fixed time

Fires every day at the given local wall-clock time. Unlike ON EVERY 1 DAY, this tracks clock time, not elapsed time since the broker or last run started.
"HH:mm" without seconds is accepted.

6. ON TIMESTAMP — one-shot, exact date and time

Fires once at the exact instant given, then never again (the scheduler moves the next run far into the future). Format is strictly dd-MM-yyyy HH:mm:ss (day–month–year). The timestamp is treated as UTC.

Combination patterns

Real systems often split schedules across several actions—one trigger per concern.

Error handling

If a time string does not match an expected format, the broker logs an error similar to: Invalid DATE_TIME format: <value>. Expected formats:
  • dd-MM-yyyy HH:mm:ss (one-time)
  • HH:mm:ss / HH:mm (daily)
  • Weekly forms using a day name with AT and a time string
Errors are also published (retained) to: $SYS/Coreflux/Actions/<ActionName>/Error Subscribe to $SYS/Coreflux/Actions/+/Error to observe failures from any action.

At a glance — valid time triggers

More examples


Topic-Based Triggers

MQTT-driven actions use a topic trigger — the condition that tells the broker when to run the action body. Both triggers share the same topic patterns and wildcards; the difference is whether repeated identical payloads should be ignored.

ON TOPIC — react to every message

Use ON TOPIC when each publish matters: commands, alarms, counters, or any flow where duplicate payloads still need processing.
Key characteristics:
  • Any client (or route) that publishes to a matching topic runs the action.
  • Publishing the same value twice runs the action twice.
  • Wildcard + matches one topic level (same rules as MQTT wildcards).

ON CHANGE — react only when the value changes

Use ON CHANGE for telemetry, status fields, or setpoints that are published often but only need logic when the reading actually changes. This reduces CPU load, database writes, and downstream noise.
Key characteristics:
  • The first message on a given topic always runs the action (there is no previous value yet).
  • Later messages run the action only if the payload bytes are not identical to the last message on that exact topic name.
  • Example: sensors/line1/temperature and sensors/line2/temperature are tracked separately.
  • Wildcard patterns work the same as ON TOPIC; change is evaluated per real topic, not per pattern.
What counts as “changed”? Comparison is on the raw message body (bytes), not on parsed numbers or JSON. 25 and 25.0 are different payloads. {"temp":25} and {"temp": 25} (different spacing) are different payloads. If you need semantic equality (for example, treat 25 and 25.0 as the same), handle that inside an ON TOPIC action with your own logic.

Choosing between ON TOPIC and ON CHANGE

You can deploy two actions on the same topic pattern: one with ON TOPIC and one with ON CHANGE. The broker runs ON TOPIC every time and skips the ON CHANGE action when the payload is unchanged.

Side-by-side example

Two devices publish temperature every second. Only 22.523.1 should trigger heavy processing.
On value change only:
Inside the action body, PAYLOAD is the content of the message that fired the trigger, and TOPIC POSITION N is segment N of the actual topic (1-based), useful with +.

Wildcard Patterns

LoT supports MQTT wildcards for flexible topic matching:
The + wildcard matches exactly one topic level:
Matches: sensors/room1/temperature, sensors/room2/temperature
Does NOT match: sensors/building1/floor2/temperature (too many levels)

Initialization Triggers

Use ON START to execute logic exactly once when the broker starts or when the action is first deployed on a live broker. This is the right place to bootstrap a Unified Namespace (UNS) structure, publish retained default configurations, and log startup events.
Key characteristics:
  • Runs once when the broker starts, and again when you first deploy (or redeploy) the action while the broker is already up — you do not need a restart to seed bootstrap topics
  • Cold-start behaviour is unchanged: every ON START action still runs once after the MQTT broker is ready. Deploying before the broker is ready defers until startup so the body is not double-run
  • A failing ON START body is logged but does not fail the deploy
  • KEEP TOPIC publishes with the retain flag so the value is delivered to any future subscriber immediately on connection
  • Use it to set default configuration values and retained state that must survive restarts
  • There is no ON STOP equivalent — ON START is the correct place for setup logic
Action PUBLISH and KEEP are ordinary MQTT publishes: the payload is on the topic and any client subscribed to that topic receives it. What they skip is the publish ACL that applies to connected MQTT users — a restrictive rule on that topic does not stop the action from publishing, so bootstrap topics from ON START (and other actions) are not silently dropped. Clients still need subscribe permission to receive those messages, and anything a client publishes itself remains fully subject to rules.

Client Lifecycle Triggers

Use ON CONNECT, ON DISCONNECT, and ON SUBSCRIBE when automation must react to MQTT session events instead of publishes. Typical uses include audit trails, connection dashboards, onboarding retained topics when a UI client connects, or tracking which topics clients subscribe to.
If no action in the broker uses ON CONNECT, ON DISCONNECT, or ON SUBSCRIBE, the broker does not dispatch those lifecycle hooks — there is no overhead when the triggers are unused.

ON CONNECT DO

Runs once after a client successfully authenticates and the broker accepts the MQTT CONNECT packet.
Key characteristics:
  • Fires for every successful client connection, including routes and HUB clients.
  • Session context variables (CLIENTID, USER, ENDPOINT, CLEANSESSION) reflect the connecting client.
  • USER IN GROUP, USER EQUALS, and USER HAS evaluate against the session user, the same way they do for ON TOPIC.

ON DISCONNECT DO

Runs when the broker detects a client disconnection — clean disconnect, unclean disconnect, or session takeover.
Key characteristics:
  • DISCONNECTREASON carries the disconnect type or MQTT reason code for the session that ended.
  • CLIENTID, USER, and ENDPOINT reflect the disconnecting session when available from the connect handshake.

ON SUBSCRIBE DO

Runs after the broker accepts a subscription and RBAC allows it. Use a topic pattern to limit which subscriptions fire the action; omit the pattern to run on every allowed subscription.
Track every allowed subscription:
Key characteristics:
  • Supports the same MQTT wildcards as ON TOPIC: + (single level) and # (multi-level).
  • SUBSCRIBETOPIC is the topic filter the client subscribed to; SUBSCRIBEQOS is the requested QoS (0, 1, or 2).
  • Lifecycle subscribe dispatch runs for all allowed subscriptions, including Visu and system topics, unless you filter them in the action body.

Session context variables

Available inside lifecycle-triggered actions (and still available on ON TOPIC / ON CHANGE for the publisher):

Not the same as Visu ON CHANGE

In dashboard / Visu (LoTV) panels, ON CHANGE DO on a slider or text field is a UI event in the browser (user edits a control). That is separate from broker ON CHANGE "topic" DO, which reacts to MQTT publishes inside the broker. Lifecycle triggers (ON CONNECT, ON DISCONNECT, ON SUBSCRIBE) are also broker-side only. The broker still publishes $SYS/Coreflux/Comms/Logins on connect for observability, but LoT lifecycle actions give you programmatic automation with session context variables.

Callable Actions

Actions without a trigger clause (ON TOPIC, ON EVERY, ON START, ON CONNECT, and so on) are callable—they run only when another ACTION calls them with CALL ACTION. Use callables for reusable logic (conversions, validation, shared math) that several trigger-based Actions need. They accept typed INPUT parameters and can RETURN one or more OUTPUT values.
Full guide: Callable ACTIONs—reusable logic, on-demand scripts, and CALL ACTION syntax.

Comparing Trigger Types


Next Steps

Callable ACTIONs

Reusable logic, on-demand scripts, and CALL ACTION.

Operations

Learn about SET, GET, PUBLISH, and conditional logic.
Last modified on August 28, 2026