Я решил это так.пожалуйста, посмотрите на мой код узла.Также, пожалуйста, предложите, если это может быть сделано каким-то другим лучшим способом.
[
{
"id": "b6c9b219.90a478",
"type": "function",
"z": "a3d6aff.bd4935",
"name": "",
"func": "var i = 0;\nfunction increment(){\n i = i + 1;\n msg={value:i};\n node.send(msg);\n if(global.get(\"a\")===\"off\"){\n clearInterval(interval);\n }\n}\n\nif(msg.payload===true){\nvar interval = setInterval( increment, 1000);\n}",
"outputs": 1,
"noerr": 0,
"x": 450.5000305175781,
"y": 508,
"wires": [
[
"12f2090c.587347"
]
]
},
{
"id": "12f2090c.587347",
"type": "debug",
"z": "a3d6aff.bd4935",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"x": 699.5,
"y": 686.9999694824219,
"wires": []
},
{
"id": "26abbbf.05cf944",
"type": "inject",
"z": "a3d6aff.bd4935",
"name": "",
"topic": "",
"payload": "true",
"payloadType": "bool",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 305.8833312988281,
"y": 430.2833557128906,
"wires": [
[
"b6c9b219.90a478",
"4fdb56dd.8ef"
]
]
},
{
"id": "880341a0.dcab2",
"type": "inject",
"z": "a3d6aff.bd4935",
"name": "",
"topic": "",
"payload": "false",
"payloadType": "bool",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 207.88333129882812,
"y": 666.0999450683594,
"wires": [
[
"4fdb56dd.8ef",
"b6c9b219.90a478"
]
]
},
{
"id": "4fdb56dd.8ef",
"type": "function",
"z": "a3d6aff.bd4935",
"name": "",
"func": "if(msg.payload===false){\n global.set(\"a\",\"off\");\n}\nif (msg.payload===true){\n global.set(\"a\",\"on\");\n}\nmsg={payload:global.get(\"a\")}\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 202.26666259765625,
"y": 554.2332458496094,
"wires": [
[]
]
}
]