MQTT publishing

Hey @Lars_Andersson!

Below are some screenshots on how you can set a custom MQTT topic and set up a workflow to report state for devices. It is important to note that for this example, the MQTT message included a “devices” array in the message.

First, with an MQTT node, you can set the custom MQTT topic.

Once you’re sending MQTT messages to that topic, you can use a JSON: Decode node to format the string to an Object.

Using a Loop Node, you can loop through all the devices in the “devices” array sent along with the MQTT package.

The Loop Node can then report state to each deviceID listed in the “devices” array.

Here’s the example payload that was used to trigger this workflow.

{
  "devices": [ 
{
"deviceId":"5d35d2ece9bcf1000957fa02",
    "temperature": 72
  },
{
"deviceId":"5dcedf089285680007ea7974",
    "temperature": 40
  } 
] 
}

And, here’s the workflow export:
mqtt-state-ingest-develop.flow (3.2 KB)

Thanks,
Heath