Nodes/comfyui-mqtt-node/MQTT Publish Image
ComfyUI Node

MQTT Publish Image

Get Your ComfyUI Images Onto the MQTT Bus

By eljefe80·Created 8 months ago·Updated 8 months ago· 0
MQTT Publish Image
  • image
  • image
  • status
broker_urllocalhost
broker_port1883
topiccomfyui/image
use_tlsfalse
image_format
quality95
username
password
client_idcomfyui_mqtt_client
qos1
retainfalse

MQTT is the quiet lingua franca of the home lab: the small pub/sub protocol that carries a temperature reading from one Pi to another. This node is the ComfyUI side of that story. It takes the image sitting on your graph, packs it up, and puts it on the MQTT topic of your choice - so every render your sampler finishes shows up on the bus for whatever is listening. A wall-mounted dashboard, a phone notification, a second machine that collects your output gallery, a Home Assistant automation that pings you when the queue is done. That's the whole point of reaching for it.

What it is not: a cloud API call, an uploader, or anything that needs an account. You're publishing to a broker you run or rent, and the only credentials involved are the broker's own username/password - no API key, no metered per-image cost. It's a plumbing node in the best sense, the kind that moves data around your workflow rather than touching pixels.

How it works

The mechanism is a short, honest pipeline. The node takes your image tensor, keeps the first frame of the batch, converts it to a PIL image, encodes it as JPEG (at your quality) or PNG, base64-encodes the bytes, and hands the resulting text to paho-mqtt, which publishes it to your topic with the QoS and retain flags you set. Then it disconnects. That's all of it.

One detail is worth knowing before you build a subscriber around this: the payload on the wire is base64 text, not a raw image file. A subscriber has to base64-decode it back to bytes before writing it to disk. The README's own test command pipes the topic straight into a .jpg, which will not produce a viewable file - pipe it through base64 -d first:

mosquitto_sub -h localhost -t "comfyui/image" -F "%I" | base64 -d > received.jpg

The inputs that matter

You'll actually set four of them:

  • broker_url / broker_port - your broker's address. Defaults are localhost:1883, which is exactly right for a local mosquitto; TLS brokers usually live on 8883.
  • topic - where the message lands (default comfyui/image). Keep it matching whatever your subscriber listens on.
  • image_format / quality - JPEG is the small-and-fast default at quality 95; PNG is lossless and larger. Quality only applies to JPEG.
  • use_tls - flip on for 8883; you'll also need username/password on most real brokers.

The optional qos (0, 1, or 2 - the default 1 is the right call), retain (the broker keeps the last image for new subscribers), and client_id round it out.

Outputs: image passes your tensor through unchanged so the render can keep flowing after publishing, and status is a string - the node's ✓ Published to … or ✗ MQTT Error: … message, handy to log or display.

Installing

Standard custom-node fare, and there are no models to download - the only real dependency beyond what ComfyUI already ships is paho-mqtt:

cd ComfyUI/custom_nodes
git clone https://github.com/eljefe80/comfyui-mqtt-node
cd comfyui-mqtt-node
pip install -r requirements.txt

Then restart ComfyUI. ComfyUI Manager finds it if you search "comfyui-mqtt-node". The repo also documents a Kubernetes install via an initContainer on pod startup - clearly the home-lab/automation crowd this pack is aimed at.

Where people get burned

The big one is a genuine bug in the shipped code: the image node calls base64.b64encode but never imports base64, so every publish dies with a status of MQTT Error: name 'base64' is not defined. The node swallows the exception, so ComfyUI keeps running - you just never see the image on the bus. The fix is a one-liner: add import base64 to mqtt_node.py and restart. It's that dumb, and it's real in the current release.

After that, the usual suspects: connection refused (broker not running - check with netstat -an | grep 1883) and TLS failures. TLS uses CERT_REQUIRED with TLSv1.2 and no way to point at a CA file, so self-signed certificates won't connect and the broker's hostname must match its cert. And since this node ships your images and broker password out onto the network by design, it's the exact shape of thing worth eyeballing before you run it - keep real credentials out of shared workflow files. It's a small pack from an author with essentially no community footprint, and the README itself admits it's AI-generated and lightly hand-edited, so trust the console output over the docs and test against a local mosquitto first.

Categoryimage/mqtt

Inputs (12)

NameTypeDefaultDescription
imageIMAGE
broker_urlSTRINGlocalhost
broker_portINT18831–65535
topicSTRINGcomfyui/image
use_tlsBOOLEANfalse
image_formatCOMBO2 options: JPEG, PNG
qualityINT951–100
usernameoptSTRING
passwordoptSTRING
client_idoptSTRINGcomfyui_mqtt_client
qosoptINT10–2
retainoptBOOLEANfalse

Outputs (2)

NameTypeDescription
imageIMAGE
statusSTRING