Search code examples
node-red

node-red flow based on data value on json payload


I have this incoming json data from sensors, most of the sensors provide values as double, but some of them provide as string, what would be the best way to split the payload based on condition if the value is string send it different node and if numeric send it to another node then process it down stream.

here is my sample message.

        {
        "tag": "Wind/7865",
        "value": 24.82145623328888
    },
    {
        "tag": "AC 3 Phase/7995",
        "value": true
    },
   
    {
        "tag": "AC 3 Phase/7847",
        "value": "OFF"
    },
    {
        "tag": "AC Generator/7849",
        "value": "STARTING"
    }

here the tags with value OFF and STARTING need to be processed a separate flow as I can't store that on a tsdb.


Solution

  • Assuming that the example you have posted is a section of an array, then I would do the following:

    1. Pass the msg with the array into the split node to generate individual messages for each entry in the array
    2. Use a switch node with the msg.payload.value and the is of type test to output the msg's with number, string or boolean to 3 different outputs
    3. each output can then process the messages accordingly
    4. (Optional) If needed a join node can ressemble to the array
    5. feed the messages into the database node