PUBLISH TOPIC Functional Keyword
| Feature | Since Version | Notes |
|---|---|---|
PUBLISH TOPIC |
>v1.4.4 | Core command to send data |
1. Overview
- Description: Instructs the broker to publish (broadcast) a message with a specified payload to a specified MQTT topic. Subscribed clients will receive this message.
2. Signature
- Syntax:
3. Parameters
"<topicPath>": The destination topic path (string) for the message.<value>: The payload of the message. Can be a literal (string, number), an Entity likePAYLOADorTIMESTAMP, the result ofGET TOPIC, a{variable}, or an Expression.
4. Usage Examples
Basic Example
Publish a fixed status message.
Intermediate Example
Publish the incoming payload to a different topic.
Advanced Example
Publish a calculated value based on multiple inputs.
DEFINE ACTION CalculateAndPublish
ON TOPIC "inputs/trigger" DO
SET "temp" = GET TOPIC "sensors/temperature"
SET "humidity" = GET TOPIC "sensors/humidity"
IF {temp} != EMPTY AND {humidity} != EMPTY THEN
SET "heatIndex" = {temp} * 1.1 + {humidity} * 0.05 // Simplified example formula
PUBLISH TOPIC "weather/heat_index" WITH {heatIndex}
5. Notes & Additional Information
PUBLISH TOPICis the primary way LOT scripts interact with external MQTT clients.- Use
KEEP TOPICif you only need to store data internally within the broker.