sum of 2 num

PHOTO EMBED

Tue Apr 08 2025 18:40:07 GMT+0000 (Coordinated Universal Time)

Saved by @salam123

[
    {
        "id": "72c82f5f84d17524",
        "type": "tab",
        "label": "Flow 2",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "inject_num1",
        "type": "inject",
        "z": "72c82f5f84d17524",
        "name": "Inject Number 1",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "5",
        "payloadType": "num",
        "x": 140,
        "y": 160,
        "wires": [
            [
                "change_num1"
            ]
        ]
    },
    {
        "id": "inject_num2",
        "type": "inject",
        "z": "72c82f5f84d17524",
        "name": "Inject Number 2",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "7",
        "payloadType": "num",
        "x": 140,
        "y": 220,
        "wires": [
            [
                "change_num2"
            ]
        ]
    },
    {
        "id": "change_num1",
        "type": "change",
        "z": "72c82f5f84d17524",
        "name": "Set msg.num1",
        "rules": [
            {
                "t": "set",
                "p": "num1",
                "pt": "msg",
                "to": "payload",
                "tot": "msg"
            }
        ],
        "x": 330,
        "y": 160,
        "wires": [
            [
                "function_sum"
            ]
        ]
    },
    {
        "id": "change_num2",
        "type": "change",
        "z": "72c82f5f84d17524",
        "name": "Set msg.num2",
        "rules": [
            {
                "t": "set",
                "p": "num2",
                "pt": "msg",
                "to": "payload",
                "tot": "msg"
            }
        ],
        "x": 330,
        "y": 220,
        "wires": [
            [
                "function_sum"
            ]
        ]
    },
    {
        "id": "function_sum",
        "type": "function",
        "z": "72c82f5f84d17524",
        "name": "Add Two Numbers",
        "func": "var a = msg.num1 || flow.get(\"num1\");\nvar b = msg.num2 || flow.get(\"num2\");\n\nflow.set(\"num1\", a);\nflow.set(\"num2\", b);\n\nif (a !== undefined && b !== undefined) {\n    var s = a + b;\n    msg.payload = `sum of ${a} and ${b} is ${s}`;\n    return msg;\n}\nreturn null;\n",
        "outputs": 1,
        "timeout": "",
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 550,
        "y": 190,
        "wires": [
            [
                "debug_sum"
            ]
        ]
    },
    {
        "id": "debug_sum",
        "type": "debug",
        "z": "72c82f5f84d17524",
        "name": "Show Sum",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 740,
        "y": 190,
        "wires": []
    }
]
content_copyCOPY