Skip to content

TOPIC Entity

Feature Since Version Notes
TOPIC "<topicPath>" >v1.4.4 Represents an MQTT topic path
Wildcards (+, #) --- For subscriptions/rules

The TOPIC entity represents a specific MQTT topic path.

Usage

TOPIC is used in various contexts:

  1. ON TOPIC: Specifying the trigger topic for an ACTION.
  2. PUBLISH TOPIC: Specifying the destination topic for a message.
  3. GET TOPIC: Specifying the topic whose value needs to be retrieved.
  4. WITH TOPIC: In MODEL definitions, specifying input or output topics.
  5. FOR ... TO TOPIC: In RULE definitions, specifying the scope of the rule.
  6. SOURCE_TOPIC/DESTINATION_TOPIC: In ROUTE definitions, for mapping topics between brokers.

Syntax

TOPIC "<topicPath>"
  • <topicPath>: A string representing the MQTT topic hierarchy, using / as a separator.

Wildcards

Wildcards can be used in topic paths for subscriptions (ON TOPIC, GET TOPIC in some contexts) and rule definitions (FOR ... TO TOPIC):

  • + (Single-Level Wildcard): Matches any single topic level.
    • sensors/+/temperature matches sensors/livingroom/temperature but not sensors/livingroom/main/temperature.
  • # (Multi-Level Wildcard): Matches any number of topic levels at the end of a topic path.
    • alerts/# matches alerts/system, alerts/system/cpu, etc.
    • Must be the last character in the topic path.

Examples

1. Triggering an Action:

ON TOPIC "commands/light/set" DO
    // ... statements ...
END ACTION

2. Publishing Data:

PUBLISH TOPIC "status/light/state" WITH "ON"

3. Getting a Topic Value:

GET TOPIC "config/threshold"

4. In a Model Definition:

DEFINE MODEL SensorModel WITH TOPIC "processed/sensor"
    ADD "rawValue" WITH TOPIC "raw/sensor/value" AS TRIGGER

5. In a Rule Definition (with wildcard):

DEFINE RULE AllowSensorPublish WITH PRIORITY 1 FOR Publish TO TOPIC "sensors/+/data"
    IF USER IS "sensor_device" THEN ALLOW
    ELSE DENY

6. In a Route Mapping (with wildcard):

DEFINE ROUTE BridgeRoute WITH TYPE MQTT_BRIDGE
    // ... configs ...
    ADD MAPPING Telemetry
        WITH SOURCE_TOPIC "local/telemetry/#"
        WITH DESTINATION_TOPIC "cloud/device1/telemetry/#"
        WITH DIRECTION "out"

Related Documentation