MQTT is the default nervous system for IoT — lightweight pub/sub, works on flaky networks, and every major smart-home stack speaks it. This article walks through three real patterns teams build in Nodlyn, not another property-by-property connector tour.
For Inspector settings and node outputs, use the Knowledge Base: MQTT Event (trigger) and MQTT Publish. For a hands-on first workflow, see Your First Workflow.
Pattern 1 — Temperature threshold alert
A factory stores chillers on a local Mosquitto broker. Sensors publish to plant/chiller/+/temperature.
- MQTT Event trigger — subscribe to the wildcard topic.
- Condition — compare parsed payload against
{{$var.tempLimit}}(see Global Variables). - Notification — Slack or email when the limit is exceeded.
Why MQTT here instead of polling HTTP? The PLC gateway already publishes; Nodlyn reacts in milliseconds without opening firewall holes.
Pattern 2 — Command-and-ack loop
A warehouse roller door is controlled via Zigbee2MQTT. Operations wants audit logs in Google Sheets.
- Webhook from the WMS when a truck arrives.
- MQTT Publish —
zigbee2mqtt/door_main/setwith{"state":"OPEN"}. - MQTT Event (or a second branch) — wait for
.../stateconfirmation. - HTTP Request — append row to Sheets with timestamp and correlation id.
Bidirectional MQTT (listen + command) is the bread-and-butter of home automation and light industrial glue code.
Pattern 3 — Edge broker on a gateway
Air-gapped site: no cloud, broker runs on the same Raspberry Pi as Nodlyn Runtime.
- Design and validate in Studio on a laptop.
- Export Runtime — see Deploying Workflows to the Edge.
- Agent subscribes to localhost MQTT; external PLCs publish to the same broker VLAN.
Schedules, variables, and MQTT subscriptions survive reboots because they ship inside the runtime manifest.
Topic design tips (from the field)
- Hierarchical topics:
site/building/device/metric— easier routing and ACLs. - QoS 1 for telemetry you cannot afford to lose once; QoS 0 for high-frequency noise.
- Keep JSON payloads small — one reading per message beats giant batches on constrained links.
- Use
{{$var.mqttHost}}so dev/staging/prod brokers swap without editing every node.
When not to use MQTT
If the vendor only offers REST webhooks, start with Webhook. If you need request/response semantics with auth headers, HTTP Request is simpler. MQTT shines for fire-and-forget events and fan-out.
Next steps
- MQTT Event · MQTT Publish — reference docs
- MQTT & Home Assistant ecosystems — integration story
- Device Discovery — find brokers and devices on the LAN