I am experimenting with node-red, connecting it to my MQTT broker.

The input (listening to a topic) works fine.

I also would like to send to a topic some payload ipon some triggers. In the example below, this would be on a query to a webservice:

enter image description here

I did not have a place to add the payload to the published message, where can I set it up?

The documentation mentions in the inputs section:


most users prefer simple text payloads, but binary buffers can also be published.

and later

msg.payload is used as the payload of the published message. If it contains an Object it will be converted to a JSON string before being sent. If it contains a binary Buffer the message will be published as-is.

I tried to add {msg: {payload: 'on'}} or {payload: 'on'} in node settings -> inputs but the payload is not carried to the MQTT, which hows an incoming cmnd/home/room1/switch1/power {}

enter image description here

1 Answer 1


The payload comes from the incoming message. It does not make sense to define a static payload in the MQTT-out node.

The entry in the node-settings is just a mouse over label for the input, since nodes can only have 1 input it's not that useful, it's more for when nodes have multiple outputs to make it easier to identify which output is which.

In the case you have posted a screen shot ofit will take the msg.payload output from the http-in node, which would be the body of a HTTP POST.

If want to add a static payload to be published then the easiest way is to add a change node between the http-in and mqtt-out node.

e.g. to set the payload to "foo"

enter image description here

You can set JSON objects by selecting the type from the drop down on the left hand end of the to field.

  • Sorry but I do not really understand. My example was to have a trigger (a http call but it could have been anything) which would trigger a message sent to MQTT (via an MQTT-out node ( which Connects to a MQTT broker and publishes messages)). I need to send a static payload to MQTT, wouldn't that be done via an MQTT-out node?
    – WoJ
    Mar 16, 2018 at 20:33
  • OK, I got it (somehow) - I need to add a change node in order to tell mqtt-outabout its payload? (If so it is strange the payload is not defined directly on the mqtt-out node)
    – WoJ
    Mar 16, 2018 at 20:35
  • No, the node expects to be passed a payload to publish, not just publish the same message over and over. Most (all) Node-RED output nodes work this way
    – hardillb
    Mar 16, 2018 at 20:35
  • Thank you - I understand. A static payload makes sense for switches and I thought that I would have one MQTT-out per switch. If I understand correctly, I will have one for all the switches, with a payload defined upstream (= depending on the path which led to the message)
    – WoJ
    Mar 16, 2018 at 20:37
  • You can also leave the topic blank in the mqtt-out node and pass that in via the incoming msg as well
    – hardillb
    Mar 16, 2018 at 20:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.