Getting Started Cameras & Video Detection & Recording Automation & Events Actions Integration & Connectivity Network & Discovery AI & Remote Control MQTT Modbus ZeroMQ System & Administration Use Cases Troubleshooting About & Legal
Home / Documentation / MQTT Set State Action
Knowledge base

MQTT Set State Action

MQTTSetStateAction publishes messages to MQTT topics through a configured MQTT connector. Use it when Banalytics rules, manual actions, or operator workflows need to send commands, desired state, or integration messages to MQTT devices and external automation systems.

Publish Banalytics decisions to MQTT topics

The action takes a target topic, QoS, retain flag, and string message template. When executed, it publishes the UTF-8 payload through an MQTT v3 or v5 connector and waits for publish completion.

PUB

Publish command

Send device commands such as ON, OFF, open, close, or JSON control payloads.

RET

Retained state

Use retained messages for topics that represent latest known state or desired state.

RULE

Event bridge

Attach the action to Event Manager rules to forward Banalytics events to MQTT systems.

Adding an MQTT publishing action

01

Select the MQTT connector

Choose an MQTT v3 or v5 connector that is connected to the broker where the message should be published.

02

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.

03

Choose QoS and retain

Use QoS 1 for most commands and state changes. Enable retain only for desired-state or latest-state topics.

04

Enter the message template

The current implementation sends the string template as the literal UTF-8 payload.

Common MQTT publishing scenarios

CMD

Device commands

Publish simple commands to lights, relays, gates, alarm panels, PLC gateways, or other MQTT-controlled devices.

STATE

Desired state

Use retained messages for topics where new subscribers should receive the latest target state immediately.

BRG

Automation bridge

Forward Banalytics events to Node-RED, Home Assistant, cloud brokers, industrial middleware, or a local MQTTServerThing.

Retain carefully: retained commands can be delivered again when a device reconnects. This is useful for desired state but risky for one-shot actions like reset, unlock, or pulse.

QoS and retain choices

QoS 0
Use for frequent, non-critical updates where occasional loss is acceptable.
QoS 1
Good default for commands and state changes where at-least-once delivery is acceptable.
QoS 2
Use only when duplicate handling is more dangerous than the extra protocol overhead.
Retain
Enable for state topics, avoid for transient button presses, alarms, or one-shot commands.

Configuration parameters

ParameterRequiredDescriptionDefault
Title
YesDisplay name of the action inside Banalytics.None
MQTT Connector
YesReference to an MQTT connector Thing. It can be MQTTV3ConnectorThing or MQTTV5ConnectorThing.None
Topic
YesTarget MQTT topic where the message will be published.None
QoS
YesPublish quality of service: 0, 1, or 2.1
Retain Message
YesStores the last message on the broker so new subscribers receive it immediately.false
Template type
YesMessage template type. Current documented type is STRING.STRING
Message Template
YesString content sent as the MQTT payload.None

Operational notes

RUN

Connector must be connected

The action fails if the selected connector is not connected when the action runs.

WAIT

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.

TPL

Literal string payload

The current implementation sends messageTemplate as a literal UTF-8 payload. Do not expect automatic event-field substitution unless that behavior is added later.

Related MQTT pages

Related tasks and pages