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:
ON TOPIC
: Specifying the trigger topic for anACTION
.PUBLISH TOPIC
: Specifying the destination topic for a message.GET TOPIC
: Specifying the topic whose value needs to be retrieved.WITH TOPIC
: InMODEL
definitions, specifying input or output topics.FOR ... TO TOPIC
: InRULE
definitions, specifying the scope of the rule.SOURCE_TOPIC
/DESTINATION_TOPIC
: InROUTE
definitions, for mapping topics between brokers.
Syntax
<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
matchessensors/livingroom/temperature
but notsensors/livingroom/main/temperature
.
#
(Multi-Level Wildcard): Matches any number of topic levels at the end of a topic path.alerts/#
matchesalerts/system
,alerts/system/cpu
, etc.- Must be the last character in the topic path.
Examples
1. Triggering an Action:
2. Publishing Data:
3. Getting a Topic Value:
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