Hello guys, I need some type of node, similar to trigger node. But when I switch pressed from ui-dashboard switch, that time only it will be start and it continuously run for only 10 hours. That in between 10 hour it should be trigger the function node at every 2 seconds. And after 10 hours that node should not trigger any thing and if I am press the switch again, this process should be repeat. So that purpose, Any body can help me guys.
Something like this might do it for you. For testing I have made it stop after 10 seconds.
[{"id":"603b8f572385da77","type":"trigger","z":"bdd7be38.d3b55","name":"","op1":"","op2":"0","op1type":"pay","op2type":"str","duration":"-2","extend":false,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":720,"y":5440,"wires":[["0df67c4a2ca6dcf8"]]},{"id":"2af822becbf3bb03","type":"trigger","z":"bdd7be38.d3b55","name":"Reset after 10 seconds","op1":"","op2":"0","op1type":"nul","op2type":"str","duration":"10","extend":false,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":310,"y":5520,"wires":[["68cac050c3bf512d"]]},{"id":"68cac050c3bf512d","type":"change","z":"bdd7be38.d3b55","name":"","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":540,"y":5520,"wires":[["603b8f572385da77"]]},{"id":"ee76381fe3838232","type":"inject","z":"bdd7be38.d3b55","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":140,"y":5440,"wires":[["2af822becbf3bb03","603b8f572385da77"]]},{"id":"0df67c4a2ca6dcf8","type":"debug","z":"bdd7be38.d3b55","name":"debug 2510","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":900,"y":5440,"wires":[]}]
What should happen it the switch is triggered before the end of the 10 hours?
What does the function
node and the code following that do? Is it possible that the function node and following code could take more than 2 seconds?
Actually I read the status from only ui-switch from ui-dashboard. So that requirements is once turned on, no need to trigger again until 10 hours finished and here I will use for function node also for checking the another one switch for cross-control.
So are you now saying that once the button is pushed, you want to ignore it for 10 hours?
What if the system or node-red restarted after 2 hours? Would that mean the button is ignored for the next 8 hours? How about the function, should it be restarted then?
@zenofmud yeah, As per you told if nodered is restart, then it will ignore the after 8 hours. so we go for another option. And did you knows about any timer node working same like that above flow? if you knows about that please let me know.
I would suggest you draw a flowchart of what you are trying to do. That will make it easier to determine what nodes and what kind of a flow you will need to put together.
Since you have marked the thread solved I'll wish you good luck with your solution.
@zenofmud I created flow is attached here.
[
{
"id": "23e49669ae4f38fe",
"type": "ui_button",
"z": "15aa4715eb3086a9",
"name": "",
"group": "d1175b757fdc03ac",
"order": 1,
"width": "13",
"height": "1",
"passthru": false,
"label": "start",
"tooltip": "",
"color": "",
"bgcolor": "",
"className": "",
"icon": "",
"payload": "Start",
"payloadType": "str",
"topic": "topic1",
"topicType": "msg",
"x": 4010,
"y": 160,
"wires": [
[
"2974108903c9c729",
"4f09fd58bfc8956a"
]
]
},
{
"id": "70bed949d16f2d2b",
"type": "ui_button",
"z": "15aa4715eb3086a9",
"name": "",
"group": "d1175b757fdc03ac",
"order": 2,
"width": "13",
"height": "1",
"passthru": false,
"label": "end",
"tooltip": "",
"color": "",
"bgcolor": "red",
"className": "",
"icon": "",
"payload": "End",
"payloadType": "str",
"topic": "topic1",
"topicType": "msg",
"x": 4010,
"y": 220,
"wires": [
[
"55575a4761a08baa",
"4f09fd58bfc8956a"
]
]
},
{
"id": "2974108903c9c729",
"type": "change",
"z": "15aa4715eb3086a9",
"name": "start_1",
"rules": [
{
"t": "set",
"p": "start_1",
"pt": "flow",
"to": "payload",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 4170,
"y": 140,
"wires": [
[]
]
},
{
"id": "55575a4761a08baa",
"type": "change",
"z": "15aa4715eb3086a9",
"name": "start_1",
"rules": [
{
"t": "set",
"p": "start_1",
"pt": "flow",
"to": "payload",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 4170,
"y": 240,
"wires": [
[]
]
},
{
"id": "581bafdcd30e76cf",
"type": "function",
"z": "15aa4715eb3086a9",
"name": "r1_switch",
"func": "var data = msg.payload;\nvar req = flow.get(\"start_1\");\nvar stand_req = flow.get(\"standby1\");\nvar topic = flow.get(\"top_std\");\n\nvar d = new Date;\nvar date = d.getDate() + \":\" + (d.getMonth()+1) + \":\" + d.getFullYear();\n\nif(data == \"abcde\"){\n if(req == \"Start\"){\n flow.set(\"run_flag_1\",1);\n global.set(\"file1\",1);\n msg.payload = \"Run started\";\n flow.set(\"start_1\",NaN);\n }\n else if(req == \"End\"){\n flow.set(\"run_flag_1\",0);\n global.set(\"file1\",0);\n msg.payload = \"Run ended\";\n flow.set(\"start_1\",NaN);\n global.set(\"Date\",date);\n }\n else if(stand_req == \"standby_open\")\n {\n flow.set(\"standby1\",1);\n //topic += 1;\n flow.set(\"top_std\",1);\n msg.payload = \"standby started\";\n }\n return msg;\n}\nelse if(data == \"Cancel\"){\n msg.payload = \"Please enter password\";\n return msg;\n}\nelse {\n msg.payload = \"password incorrect\";\n return msg;\n}",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 4360,
"y": 180,
"wires": [
[
"fcd3028d218c6ddb",
"c7bcfc5f64c86b13"
]
]
},
{
"id": "fcd3028d218c6ddb",
"type": "ui_toast",
"z": "15aa4715eb3086a9",
"position": "dialog",
"displayTime": "3",
"highlight": "",
"sendall": true,
"outputs": 1,
"ok": "OK",
"cancel": "",
"raw": false,
"className": "",
"topic": "",
"name": "",
"x": 4530,
"y": 180,
"wires": [
[]
]
},
{
"id": "4f09fd58bfc8956a",
"type": "ui_toast",
"z": "15aa4715eb3086a9",
"position": "prompt",
"displayTime": "3",
"highlight": "",
"sendall": false,
"outputs": 1,
"ok": "OK",
"cancel": "Cancel",
"raw": false,
"className": "",
"topic": "",
"name": "",
"x": 4170,
"y": 180,
"wires": [
[
"581bafdcd30e76cf"
]
]
},
{
"id": "eb145bd575a7327d",
"type": "comment",
"z": "15aa4715eb3086a9",
"name": "start end switches",
"info": "",
"x": 4190,
"y": 80,
"wires": []
},
{
"id": "f915258907835694",
"type": "function",
"z": "15aa4715eb3086a9",
"name": "2_sec_data_standby",
"func": "var filepath = \"/home/Desktop/\";\n\nvar d = new Date;\n\nvar date = d.getDate() + \":\" + (d.getMonth()+1) + \":\" + d.getFullYear();\n\nvar filename = date + \"_standby_data.csv\";\n\nmsg.file = filepath + filename;\n\nvar count2 = flow.get(\"run_flag_1\");\n\nvar topic = flow.get(\"top_std\");\n\nif(count2 == 1){\n flow.set(\"standby1\",0);\n}\n\nvar count1 = flow.get(\"standby1\");\n\nif(count1 == 1 && (count2 == 0 || count2 == 2))\n{\n if(topic == 1)\n {\n msg.payload = \"Date\" + \",\" + \"Time\" + \",\" + \"volt_R1_a\" + \",\" + \"volt_R1_b\" + \",\" + \"volt_R1_c\" + \",\" + \"curr_R1_a\" + \",\" + \"curr_R1_b\" + \",\" + \"curr_R1_c\" + \",\" + \n \"volt_R2_a\" + \",\" + \"volt_R2_b\" + \",\" + \"volt_R2_c\" + \",\" + \"curr_R2_a\" + \",\" + \"curr_R2_b\" + \",\" + \"curr_R2_c\" + \",\" + \n \"volt_R3_a\" + \",\" + \"volt_R3_b\" + \",\" + \"volt_R3_c\" + \",\" + \"curr_R3_a\" + \",\" + \"curr_R3_b\" + \",\" + \"curr_R3_c\" + \",\" + \n \"volt_R4_a\" + \",\" + \"volt_R4_b\" + \",\" + \"volt_R4_c\" + \",\" + \"curr_R4_a\" + \",\" + \"curr_R4_b\" + \",\" + \"curr_R4_c\" + \",\" + \n \"RX1_pt\" + \",\" + \"RX2_pt\" + \",\" + \"RX3_pt\" + \",\" + \"RX4_pt\" + \",\" + \"flow1\" + \",\" + \"flow2\";\n // global.set(\"file1\",2);\n //flow.set(\"standby1\",2);\n //global.set(\"Date\",date);\n flow.set(\"top_std\",0);\n return msg;\n }\n else\n {\n var time = d.getHours() + \":\" + d.getMinutes() + \":\" + d.getSeconds();\n //RX1 Datas\n var v_R1_a = flow.get(\"Volt_R1_a\") || 0;\n var v_R1_b = flow.get(\"Volt_R1_b\") || 0;\n var v_R1_c = flow.get(\"Volt_R1_c\") || 0;\n var c_R1_a = flow.get(\"Curr_R1_a\") || 0;\n var c_R1_b = flow.get(\"Curr_R1_b\") || 0;\n var c_R1_c = flow.get(\"Curr_R1_c\") || 0;\n var pt_R1 = flow.get(\"RX1_PT\") || 0;\n\n //RX2 Datas\n var v_R2_a = flow.get(\"Volt_R2_a\") || 0;\n var v_R2_b = flow.get(\"Volt_R2_b\") || 0;\n var v_R2_c = flow.get(\"Volt_R2_c\") || 0;\n var c_R2_a = flow.get(\"Curr_R2_a\") || 0;\n var c_R2_b = flow.get(\"Curr_R2_b\") || 0;\n var c_R2_c = flow.get(\"Curr_R2_c\") || 0;\n var pt_R2 = flow.get(\"RX2_PT\") || 0;\n\n //RX3 Datas\n var v_R3_a = flow.get(\"Volt_R3_a\") || 0;\n var v_R3_b = flow.get(\"Volt_R3_b\") || 0;\n var v_R3_c = flow.get(\"Volt_R3_c\") || 0;\n var c_R3_a = flow.get(\"Curr_R3_a\") || 0;\n var c_R3_b = flow.get(\"Curr_R3_b\") || 0;\n var c_R3_c = flow.get(\"Curr_R3_c\") || 0;\n var pt_R3 = flow.get(\"RX3_PT\") || 0;\n\n //RX4 Datas\n var v_R4_a = flow.get(\"Volt_R4_a\") || 0;\n var v_R4_b = flow.get(\"Volt_R4_b\") || 0;\n var v_R4_c = flow.get(\"Volt_R4_c\") || 0;\n var c_R4_a = flow.get(\"Curr_R4_a\") || 0;\n var c_R4_b = flow.get(\"Curr_R4_b\") || 0;\n var c_R4_c = flow.get(\"Curr_R4_c\") || 0;\n var pt_R4 = flow.get(\"RX4_PT\") || 0;\n\n //flow Datas\n var f1 = flow.get(\"Flow1\") || 0;\n var f2 = flow.get(\"testFlow\") || 0;\n var csv;\n csv = date + \",\" + time + \",\" + v_R1_a + \",\" + v_R1_b + \",\" + v_R1_c + \",\" + c_R1_a + \",\" + c_R1_b + \",\" + c_R1_c + \",\" + v_R2_a + \",\" +\n v_R2_b + \",\" + v_R2_c + \",\" + c_R2_a + \",\" + c_R2_b + \",\" + c_R2_c + \",\" + v_R3_a + \",\" + v_R3_b + \",\" + v_R3_c + \",\" + c_R3_a + \",\" + c_R3_b + \",\" + c_R3_c + \",\" +\n v_R4_a + \",\" + v_R4_b + \",\" + v_R4_c + \",\" + c_R4_a + \",\" + c_R4_b + \",\" + c_R4_c + \",\" + pt_R1 + \",\" + pt_R2 + \",\" + pt_R3 + \",\" + pt_R4 + \",\" + f1 + \",\" + f2;\n\n msg.payload = csv;\n return msg;\n }\n \n}\n// else if(count1 == 2 && (count2 == 0 || count2 == 2))\n// {\n// var time = d.getHours()+\":\"+d.getMinutes()+\":\"+d.getSeconds();\n// //RX1 Datas\n// var v_R1_a = flow.get(\"Volt_R1_a\")||0;\n// var v_R1_b = flow.get(\"Volt_R1_b\")||0;\n// var v_R1_c = flow.get(\"Volt_R1_c\")||0;\n// var c_R1_a = flow.get(\"Curr_R1_a\")||0;\n// var c_R1_b = flow.get(\"Curr_R1_b\")||0;\n// var c_R1_c = flow.get(\"Curr_R1_c\")||0;\n// var pt_R1 = flow.get(\"RX1_PT\")||0;\n\n// //RX2 Datas\n// var v_R2_a = flow.get(\"Volt_R2_a\")||0;\n// var v_R2_b = flow.get(\"Volt_R2_b\")||0;\n// var v_R2_c = flow.get(\"Volt_R2_c\")||0;\n// var c_R2_a = flow.get(\"Curr_R2_a\")||0;\n// var c_R2_b = flow.get(\"Curr_R2_b\")||0;\n// var c_R2_c = flow.get(\"Curr_R2_c\")||0;\n// var pt_R2 = flow.get(\"RX2_PT\")||0;\n\n// //RX3 Datas\n// var v_R3_a = flow.get(\"Volt_R3_a\")||0;\n// var v_R3_b = flow.get(\"Volt_R3_b\")||0;\n// var v_R3_c = flow.get(\"Volt_R3_c\")||0;\n// var c_R3_a = flow.get(\"Curr_R3_a\")||0;\n// var c_R3_b = flow.get(\"Curr_R3_b\")||0;\n// var c_R3_c = flow.get(\"Curr_R3_c\")||0;\n// var pt_R3 = flow.get(\"RX3_PT\")||0;\n\n// //RX4 Datas\n// var v_R4_a = flow.get(\"Volt_R4_a\")||0;\n// var v_R4_b = flow.get(\"Volt_R4_b\")||0;\n// var v_R4_c = flow.get(\"Volt_R4_c\")||0;\n// var c_R4_a = flow.get(\"Curr_R4_a\")||0;\n// var c_R4_b = flow.get(\"Curr_R4_b\")||0;\n// var c_R4_c = flow.get(\"Curr_R4_c\")||0;\n// var pt_R4 = flow.get(\"RX4_PT\")||0;\n\n// //flow Datas\n// var f1 = flow.get(\"Flow1\")||0;\n// var f2 = flow.get(\"testFlow\")||0;\n// var csv;\n// csv = date + \",\" + time + \",\" + v_R1_a + \",\" + v_R1_b + \",\" + v_R1_c + \",\" + c_R1_a + \",\" + c_R1_b + \",\" + c_R1_c + \",\" + v_R2_a + \",\" + \n// v_R2_b + \",\" + v_R2_c + \",\" + c_R2_a + \",\" + c_R2_b + \",\" + c_R2_c + \",\" + v_R3_a + \",\" + v_R3_b + \",\" + v_R3_c + \",\" + c_R3_a + \",\" + c_R3_b + \",\" + c_R3_c + \",\" +\n// v_R4_a + \",\" + v_R4_b + \",\" + v_R4_c + \",\" + c_R4_a + \",\" + c_R4_b + \",\" + c_R4_c + \",\" + pt_R1 + \",\" + pt_R2 + \",\" + pt_R3 + \",\" + pt_R4 + \",\" + f1 + \",\" + f2; \n\n// msg.payload = csv;\n// return msg;\n// }\n\n",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 3460,
"y": 280,
"wires": [
[
"a6e924355b2449f9"
]
]
},
{
"id": "a6e924355b2449f9",
"type": "file",
"z": "15aa4715eb3086a9",
"name": "RX1_standby_file",
"filename": "file",
"filenameType": "msg",
"appendNewline": true,
"createDir": false,
"overwriteFile": "false",
"encoding": "none",
"x": 3690,
"y": 280,
"wires": [
[
"42f4e7a798565ff0"
]
]
},
{
"id": "42f4e7a798565ff0",
"type": "debug",
"z": "15aa4715eb3086a9",
"name": "debug 93",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 3860,
"y": 280,
"wires": []
},
{
"id": "e3f7e3e9a482a506",
"type": "trigger",
"z": "15aa4715eb3086a9",
"name": "2 sec",
"op1": "",
"op2": "0",
"op1type": "pay",
"op2type": "str",
"duration": "-2",
"extend": false,
"overrideDelay": false,
"units": "s",
"reset": "",
"bytopic": "all",
"topic": "topic",
"outputs": 1,
"x": 3590,
"y": 400,
"wires": [
[
"f915258907835694"
]
]
},
{
"id": "c7bcfc5f64c86b13",
"type": "function",
"z": "15aa4715eb3086a9",
"name": "function 12",
"func": "var message = msg.payload;\nif(message == \"standby started\")\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 3410,
"y": 440,
"wires": [
[
"e3f7e3e9a482a506",
"7e7ecdd84d0068ef"
]
]
},
{
"id": "7e7ecdd84d0068ef",
"type": "trigger",
"z": "15aa4715eb3086a9",
"name": "18 hrs",
"op1": "",
"op2": "1",
"op1type": "nul",
"op2type": "num",
"duration": "18",
"extend": true,
"overrideDelay": false,
"units": "hr",
"reset": "",
"bytopic": "all",
"topic": "topic",
"outputs": 1,
"x": 3590,
"y": 500,
"wires": [
[
"f7b8188c99360504",
"fcfda73e9f767272"
]
]
},
{
"id": "f7b8188c99360504",
"type": "change",
"z": "15aa4715eb3086a9",
"name": "",
"rules": [
{
"t": "set",
"p": "reset",
"pt": "msg",
"to": "true",
"tot": "bool"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 3760,
"y": 500,
"wires": [
[
"e3f7e3e9a482a506"
]
]
},
{
"id": "fcfda73e9f767272",
"type": "function",
"z": "15aa4715eb3086a9",
"name": "path_for_copy_std",
"func": " var path = flow.get(\"path\");\n\n var file = flow.get(\"file\");\n var d = new Date;\n var date = d.getDate() + \":\" + (d.getMonth()+1) + \":\" + d.getFullYear();\n\n msg.srcpath = \"/home/Desktop\standby_data/\";\n\n msg.srcfile = date + \"_standby_data.csv\";\n msg.despath = \"/home/Desktop\";\n msg.desfile = date + \"_standby_data.csv\";\n msg.payload = \"File Uploaded\";\n return msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 3770,
"y": 600,
"wires": [
[
"30440f4e02d4e57b"
]
]
},
{
"id": "30440f4e02d4e57b",
"type": "fs-ops-copy",
"z": "15aa4715eb3086a9",
"name": "file_copy_std",
"sourcePath": "srcpath",
"sourcePathType": "msg",
"sourceFilename": "srcfile",
"sourceFilenameType": "msg",
"destPath": "despath",
"destPathType": "msg",
"destFilename": "desfile",
"destFilenameType": "msg",
"link": false,
"overwrite": false,
"x": 3830,
"y": 760,
"wires": [
[]
]
},
{
"id": "d1175b757fdc03ac",
"type": "ui_group",
"name": "RX1_RUN",
"tab": "124874b9cd336f6c",
"order": 1,
"disp": true,
"width": "27",
"collapse": true,
"className": ""
},
{
"id": "124874b9cd336f6c",
"type": "ui_tab",
"name": "Reactor Status",
"icon": "dashboard",
"order": 4,
"disabled": false,
"hidden": false
}
]
This flow output is I expect.
- When you export a flow to share, please export it in condensed format:
- Here is how to post code:
In order to make code readable and usable it is necessary to surround your code with three backticks (also known as a left quote or backquote ```
)
```
code goes here
```
I edited and correct your post by clicking the pencil icon and making the changes.
See this post for more details - How to share code or flow json
3) Your flow will not import: SyntaxError: JSON Parse error: Invalid escape character
You need to fix this.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.