Multiple topics in single functin node - how to parse

Hello good day

I would like to ask for your advice, I would need to process more msg.payload from several topics in 1 functional node and then publish it. I don't know how to parse it. I have multiple topics like mete/hum, meteo/temp, meteo/wind and each of them sending value by msg.payload. I need to catch these values and publish to domoticz/in in a single function node. Is that possible?

I have allready did somethinh like this, but it doesnt work

Hi, welcome to the forum.

NB: Best to show code in a pre-formatted text block </> rather than an image. It makes it easier to read and for people to copy/change/paste.

So I assume that you are getting multiple messages, each with a different msg.topic? And you want to do different processing depending on the topic?

If that is so, something like this might be helpful:

switch (msg.topic) {
    case 'meteo/temp': {
        // ...
        break
    }

    case 'meteo/hum: {
        // ...
        break
    }

    default: {
        // If you want to handle an unknown topic, you can use this section
        break
    }
}

return msg

But take care reusing the input msg as output as you will need to ensure that you are doing things in the right order. If in doubt, create a new msg with const msg2 = {} and set everything on that then do return msg2 at the end.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.