Change node to search for status node and return boolean

I need to setup a node that can search for the word "Polling" and return a boolean TRUE. The input payload is from a STATUS node that has an object like this: msg.status.text "Polling: HoldingRegister"

So I thought of using a change node to search for the string "Polling" and have the change node return a boolean TRUE.

An attempt to do this was the following flow, but it did not work:

[
    {
        "id": "c902de97108c71a8",
        "type": "status",
        "z": "6e8dfb6f99f4c853",
        "name": "",
        "scope": [
            "f930ef143a32d5ae"
        ],
        "x": 160,
        "y": 260,
        "wires": [
            [
                "bf8ade576c032ebf",
                "2deb05efdbde91cf"
            ]
        ]
    },
    {
        "id": "bf8ade576c032ebf",
        "type": "debug",
        "z": "6e8dfb6f99f4c853",
        "name": "debug 4",
        "active": true,
        "tosidebar": true,
        "console": true,
        "tostatus": true,
        "complete": "true",
        "targetType": "full",
        "statusVal": "payload",
        "statusType": "auto",
        "x": 390,
        "y": 260,
        "wires": []
    },
    {
        "id": "0d65803f80bce43f",
        "type": "ui-led",
        "z": "6e8dfb6f99f4c853",
        "name": "LED",
        "group": "2593d50c1273e43d",
        "order": -1,
        "width": 0,
        "height": 0,
        "label": "",
        "labelPlacement": "left",
        "labelAlignment": "left",
        "states": [
            {
                "value": "false",
                "valueType": "bool",
                "color": "#ff0000"
            },
            {
                "value": "true",
                "valueType": "bool",
                "color": "#00ff00"
            }
        ],
        "allowColorForValueInMessage": false,
        "shape": "circle",
        "showBorder": true,
        "showGlow": true,
        "x": 550,
        "y": 400,
        "wires": []
    },
    {
        "id": "2deb05efdbde91cf",
        "type": "change",
        "z": "6e8dfb6f99f4c853",
        "name": "monitor error",
        "rules": [
            {
                "t": "change",
                "p": "status.shape",
                "pt": "msg",
                "from": "Polling",
                "fromt": "re",
                "to": "true",
                "tot": "bool"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 350,
        "y": 360,
        "wires": [
            [
                "0d65803f80bce43f",
                "f6b29116d906883d"
            ]
        ]
    },
    {
        "id": "d7b533531f222b3e",
        "type": "inject",
        "z": "6e8dfb6f99f4c853",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "true",
        "payloadType": "bool",
        "x": 310,
        "y": 460,
        "wires": [
            [
                "0d65803f80bce43f"
            ]
        ]
    },
    {
        "id": "f8e6143cc006e929",
        "type": "inject",
        "z": "6e8dfb6f99f4c853",
        "name": "false",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "false",
        "payloadType": "bool",
        "x": 310,
        "y": 500,
        "wires": [
            [
                "0d65803f80bce43f"
            ]
        ]
    },
    {
        "id": "f6b29116d906883d",
        "type": "debug",
        "z": "6e8dfb6f99f4c853",
        "name": "debug 5",
        "active": false,
        "tosidebar": true,
        "console": true,
        "tostatus": true,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "payload",
        "statusType": "auto",
        "x": 570,
        "y": 480,
        "wires": []
    },
    {
        "id": "2593d50c1273e43d",
        "type": "ui-group",
        "name": "UI Group",
        "page": "d76a88afe14c7c33",
        "width": "6",
        "height": "1",
        "order": -1,
        "showTitle": true,
        "className": "",
        "visible": "true",
        "disabled": "false"
    },
    {
        "id": "d76a88afe14c7c33",
        "type": "ui-page",
        "name": "UI page",
        "ui": "f2ce66a50d362da1",
        "path": "/page1",
        "icon": "home",
        "layout": "grid",
        "theme": "d6404a5c856c6736",
        "order": -1,
        "className": "",
        "visible": "true",
        "disabled": "false"
    },
    {
        "id": "f2ce66a50d362da1",
        "type": "ui-base",
        "name": "UI Name",
        "path": "/dashboard",
        "includeClientData": true,
        "acceptsClientConfig": [
            "ui-notification",
            "ui-control"
        ],
        "showPathInSidebar": false,
        "navigationStyle": "default"
    },
    {
        "id": "d6404a5c856c6736",
        "type": "ui-theme",
        "name": "New theme",
        "colors": {
            "surface": "#ffffff",
            "primary": "#0094ce",
            "bgPage": "#eeeeee",
            "groupBg": "#ffffff",
            "groupOutline": "#cccccc"
        },
        "sizes": {
            "pagePadding": "12px",
            "groupGap": "12px",
            "groupBorderRadius": "4px",
            "widgetGap": "12px"
        }
    }
]

Thank you for your help

You do seem to have made a couple of mistakes.

Looking just at your change node:

  • If "Polling: HoldingRegister" is expected in msg.status.text, why does the change node focus on msg.status.shape?
  • You can't sensibly use a change node to alter msg.payload based on the value of msg.status.txt.
  • Polling is not really a regular expression. I suspect that if you applied your change node to msg.status.text, you would get msg.status.text "true : Holding Register" and msg.payload unaltered. polling.* is a regular expression. Using that, the output might be boolean true, but it would still not be in msg.payload. I don't think this is the right approach though.

Probably you should use a switch node and a change node.

[{"id":"92d71b5a11db9b6d","type":"inject","z":"9c67042f1f0b78de","name":"","props":[{"p":"payload"},{"p":"status","v":"{\"text\": \"Polling : Holding Register\"}","vt":"json"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":100,"y":140,"wires":[["ff56eeb92319957d"]]},{"id":"ff56eeb92319957d","type":"switch","z":"9c67042f1f0b78de","name":"msg.status.text contains Polling?","property":"status.text","propertyType":"msg","rules":[{"t":"cont","v":"Polling","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":320,"y":140,"wires":[["47e94d2a4dcf45e5"]]},{"id":"47e94d2a4dcf45e5","type":"change","z":"9c67042f1f0b78de","name":"msg.payload = true","rules":[{"t":"set","p":"payload","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":570,"y":140,"wires":[["3475851f494f2809"]]},{"id":"3475851f494f2809","type":"debug","z":"9c67042f1f0b78de","name":"debug 413","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":750,"y":140,"wires":[]}]

Thank you, that worked.

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