MQTT Publish Action
MQTTPublishAction (renamed from MQTTSetStateAction) publishes messages to MQTT topics through a configured MQTT connector. Both the target topic and the payload are evaluated as Spring SpEL template expressions against the action ExecutionContext, so runtime values such as the triggering event can be interpolated into the published topic and payload.
Publish Banalytics decisions to MQTT topics
The action takes a target topic, QoS, retain flag, and a SpEL-based message template. On start it parses the topic and message templates; on each invocation it evaluates them against the current execution context, publishes the UTF-8 payload through an MQTT v3 or v5 connector, and waits for publish completion.
Publish command
Send device commands such as ON, OFF, open, close, or JSON control payloads.
Retained state
Use retained messages for topics that represent latest known state or desired state.
Event bridge
Attach the action to Event Manager rules to forward Banalytics events to MQTT systems.
Adding an MQTT publishing action
Select the MQTT connector
Choose an MQTT v3 or v5 connector that is connected to the broker where the message should be published.
Set a specific topic
Use stable, explicit topics such as site/gate/mode or home/light/1/set. Avoid broad shared command topics unless all subscribers expect the same payload.
Choose QoS and retain
Use QoS 1 for most commands and state changes. Enable retain only for desired-state or latest-state topics.
Enter the SpEL message template
Plain text outside #{...} markers is published verbatim. Inside markers, expressions are evaluated against the current execution context, for example #{ #event.sourceTitle } or {"src":"#{ #event.sourceTitle }","ts":#{ #event.dateTime?.time }}.
Common MQTT publishing scenarios
Device commands
Publish simple commands to lights, relays, gates, alarm panels, PLC gateways, or other MQTT-controlled devices.
Desired state
Use retained messages for topics where new subscribers should receive the latest target state immediately.
Automation bridge
Forward Banalytics events to Node-RED, Home Assistant, cloud brokers, industrial middleware, or a local MQTTServerThing.
QoS and retain choices
Configuration parameters
| Parameter | Required | Description | Default |
|---|---|---|---|
Title | Yes | Display name of the action inside Banalytics. | None |
MQTT Connector | Yes | Reference to an MQTT connector Thing. It can be MQTTV3ConnectorThing or MQTTV5ConnectorThing. | None |
Topic | Yes | Target MQTT topic. Evaluated as a Spring SpEL template expression; plain text is published as-is, while #{...} markers are evaluated against the action ExecutionContext. | None |
QoS | Yes | Publish quality of service: 0, 1, or 2. | 1 |
Retain Message | Yes | Stores the last message on the broker so new subscribers receive it immediately. | false |
Message Template | Yes | Payload content. Evaluated as a Spring SpEL template expression against the action ExecutionContext, so values such as #event.sourceTitle or context variables can be interpolated into the published payload. | None |
Operational notes
Connector must be connected
The action fails if the selected connector is not connected when the action runs.
Publish wait time
The publish call waits up to 10 seconds for completion. Broker outages, authentication problems, TLS issues, or network timeouts can make the action fail.
SpEL template parsing
Both Topic and Message Template are parsed on action start. A syntax error in either template prevents the action from initializing; fix the expression before re-enabling the action.
Execution context variables
Templates evaluate against a SpEL StandardEvaluationContext whose root object is the action ExecutionContext. Variables registered upstream with ctx.setVar("name", value) are accessible as #name; in event-driven rules, Event Manager exposes the triggering event as #event. Use safe-navigation (?.) for optional fields.
Null-safe evaluation
A template that evaluates to null is treated as an empty string for both the topic and the payload, so the connector still receives a publish call.
Renamed from MQTTSetStateAction
The class was renamed from MQTTSetStateAction to MQTTPublishAction and the obsolete templateType selector was removed. Existing knowledge-base URLs continue to point to this page.