Skip to main content
Preview
DEFINE THING is a preview feature. It ships in broker 2.22. The syntax and behaviour may still change.

Why build with Things

Whether you run ten identical sensors on a factory floor, a fleet of solar inverters across a substation, or hundreds of street lights across a city district, copying and pasting separate connectors, models, and actions quickly becomes hard to maintain. With a Thing, you describe the asset once as a template and deploy as many instances as you need from a root.
Like a cookie cutter for your equipment. The template is the cutter that defines the shape once, and each Thing root stamps out a complete, ready-to-run set of connectors, models, and actions for a real asset.

When to use these patterns


The examples below are complete and ready to deploy. Send each block to $SYS/Coreflux/Command with -addThing, or test it first with -addThing --dryRun to inspect the expanded children without changing the broker.

Two sensors on one machine

Start with the simplest pattern: a TempSensor template with a default alarm limit, and an Oven root that creates two sensors (inlet and outlet). The outlet sensor overrides the default limit of 80 with 120:
When you deploy both blocks together, TempSensor is stored as a template and Oven expands into four children:
Double braces like {{path}} and {{limit}} are replaced when the broker expands the Thing. Single braces like {temp} are runtime action variables and stay untouched.

Reusable PLC template

When a whole machine is one instance of a template, use DEFINE THING <name> OF <template> to deploy it directly without an extra nesting level. Here, the plc template bundles a Modbus TCP connector, a status model, a heartbeat action, and an access rule. press1 and press2 stamp out two presses with different IP addresses:
Because ip has no default value in plc, every root must pass WITH PARAM ip. The slave parameter defaults to 1 unless overridden.

Helper action inside a Thing

Clauses inside the same Thing can refer to each other by their short local name. The broker rewrites those references to the expanded child names automatically. In this example, OnReading calls the sibling callable action Normalize to scale a raw sensor reading by 0.1 before publishing:
When tank1 is deployed, CALL ACTION Normalize is rewritten to CALL ACTION tank1_level_Normalize. Publishing 250 to tank1/level/raw publishes 25 to tank1/level/value.

Production line with multiple machines

Templates can instantiate other templates to model physical hierarchies such as factory → line → press. This example builds on the plc template above. Each line has two presses, and each press derives its IP address from its line’s baseIp parameter ({{baseIp}}.11 and {{baseIp}}.12):
Notice how press declares WITH PARAM ip and does not need to pass it to controller: required parameters automatically inherit from the nearest enclosing instance that defines them.

Intelligent Things

A Thing can bundle an AI agent (WITH AGENT), a diagnostic action (CALL AGENT), and a dashboard (WITH PANEL) inside the same template, turning a physical machine into an Intelligent Thing. When you nest Intelligent Things inside a parent station, a station supervisor agent can delegate to each child’s agent using relative dotted paths (WITH AGENTS "p1.Assistant, p2.Assistant").
Use WITH PARAM llm AS CONNECTOR to pass an existing TYPE LLM connector into the template. Before deploying this example, make sure the PlantLLM connector and the broker user agent-north exist on your broker:
Deploying north creates:
  • north_p1_Assistant (AGENT): scoped to read only north/p1/# topics, using the shared PlantLLM connector.
  • north_p1_DiagnoseAlarm (ACTION): calls north_p1_Assistant.execute whenever an alarm arrives on north/p1/alarm and publishes the advice to north/p1/advice.
  • north_p1_Dashboard (PANEL): a published dashboard titled "Pump p1" bound to north/p1/advice.

Energy use cases

Power grids, renewable generation sites, and EV charging hubs all rely on repeated assets that share the same telemetry schema and safety rules.
Poll multiple solar inverters over Modbus TCP, publish a unified telemetry model for each inverter, and raise an alarm if grid frequency drops below a safe threshold (minFreq, default 49.8 Hz):
Setting WITH PARAM path "grid/solar/west" on the solar_west root places all inverter topics under grid/solar/west/inv1/… and grid/solar/west/inv2/…:

Smart cities use cases

Municipal IoT deployments manage identical sensors and controllers across streets, parks, and school zones, where only topic paths or safety thresholds change per location.
Adjust street light brightness automatically from ambient light (lux) readings. Pedestrian crossings or park avenues can override luxThreshold to turn on earlier at dusk:
When ambient light on city/lights/downtown/park_ave/lux drops below 50, downtown_lights_park_ave_AutoDim sets brightness to 100%; on main_st, it waits until light drops below 30.

Verify your deployment

1

Preview with a dry run

Send -addThing --dryRun <DEFINE THING …> to $SYS/Coreflux/Command. The response on $SYS/Coreflux/Command/Output shows every child (add, update, adopt, remove, or unchanged) and its expanded LoT code without modifying the broker.
2

Deploy the Thing

Send -addThing <DEFINE THING …> to $SYS/Coreflux/Command. All children deploy together as one atomic unit.
3

Inspect the live tree and status

Use MQTT Explorer or Coreflux HUB to subscribe to $SYS/Coreflux/Things/<name>/tree (the expanded instance tree) and $SYS/Coreflux/Things/<name>/status (ok, degraded, or error).

Best practices

Write {{limit}} and {{path}} for Thing parameters replaced at deploy time. Keep single braces like {temp} for runtime action variables and {payload} for connector event placeholders.
Children deployed by a Thing are protected against direct edits. To change a child action, model, or connector, update the DEFINE THING source and run -addThing again.
Resolved parameter values are published on $SYS/Coreflux/Things/<name>/tree. Always read credentials inside clause bodies with GET SECRET or GET ENV instead of passing them through WITH PARAM.

Next steps

Thing Syntax

Full reference for templates, clauses, parameters, references, and permissions.

Things Overview

Learn how Things group assets and how -addThing manages their lifecycle.
Last modified on October 22, 2026