berijan

Function output selection

Jan 14th, 2024
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.90 KB | Source Code | 0 0
  1. [
  2. {
  3. "id": "47a23c1e32bc602e",
  4. "type": "tab",
  5. "label": "Traffic Light",
  6. "disabled": false,
  7. "info": "",
  8. "env": []
  9. },
  10. {
  11. "id": "6790a5e816e67fe8",
  12. "type": "junction",
  13. "z": "47a23c1e32bc602e",
  14. "x": 400,
  15. "y": 180,
  16. "wires": [
  17. [
  18. "cee5cbdc5de38a41"
  19. ]
  20. ]
  21. },
  22. {
  23. "id": "cee5cbdc5de38a41",
  24. "type": "function",
  25. "z": "47a23c1e32bc602e",
  26. "name": "",
  27. "func": "const DEFAULT_COLOR = \"grey\";\nlet statusColor = \"grey\"; // default color\n\nlet value = msg.payload;\n\n//Create a new messages and assume all signals is off.\nlet redMsg = {\n payload : \"off\",\n color : \"red\",\n value : value\n };\n\nlet yellowMsg = {\n payload: \"off\",\n color: \"yellow\",\n value: value\n};\n\nlet greenMsg = {\n payload: \"off\",\n color: \"green\",\n value: value\n};\n\n\n\n//Evaluate\nif (value >= 920) {\n redMsg.payload.red = \"on\";\n statusColor = \"red\";\n}\nelse if (value >= 800) {\n yellowMsg.payload = \"on\";\n statusColor = \"yellow\";\n}\nelse if (value >= 150) {\n greenMsg.payload = \"on\";\n statusColor = \"green\";\n\n}\n\n\nnode.status({ fill: statusColor,shape:\"dot\",text:\"Value: \" + value});\n\nreturn [redMsg, yellowMsg, greenMsg];",
  28. "outputs": 3,
  29. "timeout": "",
  30. "noerr": 0,
  31. "initialize": "",
  32. "finalize": "",
  33. "libs": [],
  34. "x": 500,
  35. "y": 180,
  36. "wires": [
  37. [
  38. "e9f6272924c0229a"
  39. ],
  40. [
  41. "f041dc561b4347fa"
  42. ],
  43. [
  44. "30dc6f071c6b04ff"
  45. ]
  46. ],
  47. "inputLabels": [
  48. "Payload = Value"
  49. ],
  50. "outputLabels": [
  51. "Red",
  52. "Yellow",
  53. "Green"
  54. ]
  55. },
  56. {
  57. "id": "770bb79258022b7e",
  58. "type": "inject",
  59. "z": "47a23c1e32bc602e",
  60. "name": "",
  61. "props": [
  62. {
  63. "p": "payload"
  64. },
  65. {
  66. "p": "topic",
  67. "vt": "str"
  68. }
  69. ],
  70. "repeat": "",
  71. "crontab": "",
  72. "once": false,
  73. "onceDelay": 0.1,
  74. "topic": "",
  75. "payload": "101",
  76. "payloadType": "num",
  77. "x": 150,
  78. "y": 120,
  79. "wires": [
  80. [
  81. "6790a5e816e67fe8"
  82. ]
  83. ]
  84. },
  85. {
  86. "id": "39c24b88990ef1c2",
  87. "type": "inject",
  88. "z": "47a23c1e32bc602e",
  89. "name": "",
  90. "props": [
  91. {
  92. "p": "payload"
  93. },
  94. {
  95. "p": "topic",
  96. "vt": "str"
  97. }
  98. ],
  99. "repeat": "",
  100. "crontab": "",
  101. "once": false,
  102. "onceDelay": 0.1,
  103. "topic": "",
  104. "payload": "450",
  105. "payloadType": "num",
  106. "x": 150,
  107. "y": 160,
  108. "wires": [
  109. [
  110. "6790a5e816e67fe8"
  111. ]
  112. ]
  113. },
  114. {
  115. "id": "c3efd8bbd9afc141",
  116. "type": "inject",
  117. "z": "47a23c1e32bc602e",
  118. "name": "",
  119. "props": [
  120. {
  121. "p": "payload"
  122. },
  123. {
  124. "p": "topic",
  125. "vt": "str"
  126. }
  127. ],
  128. "repeat": "",
  129. "crontab": "",
  130. "once": false,
  131. "onceDelay": 0.1,
  132. "topic": "",
  133. "payload": "850",
  134. "payloadType": "num",
  135. "x": 150,
  136. "y": 200,
  137. "wires": [
  138. [
  139. "6790a5e816e67fe8"
  140. ]
  141. ]
  142. },
  143. {
  144. "id": "e523ae55e8502d28",
  145. "type": "inject",
  146. "z": "47a23c1e32bc602e",
  147. "name": "",
  148. "props": [
  149. {
  150. "p": "payload"
  151. },
  152. {
  153. "p": "topic",
  154. "vt": "str"
  155. }
  156. ],
  157. "repeat": "",
  158. "crontab": "",
  159. "once": false,
  160. "onceDelay": 0.1,
  161. "topic": "",
  162. "payload": "950",
  163. "payloadType": "num",
  164. "x": 150,
  165. "y": 240,
  166. "wires": [
  167. [
  168. "6790a5e816e67fe8"
  169. ]
  170. ]
  171. },
  172. {
  173. "id": "e9f6272924c0229a",
  174. "type": "debug",
  175. "z": "47a23c1e32bc602e",
  176. "name": "dbg Red",
  177. "active": true,
  178. "tosidebar": true,
  179. "console": false,
  180. "tostatus": false,
  181. "complete": "true",
  182. "targetType": "full",
  183. "statusVal": "",
  184. "statusType": "auto",
  185. "x": 700,
  186. "y": 140,
  187. "wires": []
  188. },
  189. {
  190. "id": "f041dc561b4347fa",
  191. "type": "debug",
  192. "z": "47a23c1e32bc602e",
  193. "name": "dbg Yellow",
  194. "active": true,
  195. "tosidebar": true,
  196. "console": false,
  197. "tostatus": false,
  198. "complete": "true",
  199. "targetType": "full",
  200. "statusVal": "",
  201. "statusType": "auto",
  202. "x": 710,
  203. "y": 180,
  204. "wires": []
  205. },
  206. {
  207. "id": "30dc6f071c6b04ff",
  208. "type": "debug",
  209. "z": "47a23c1e32bc602e",
  210. "name": "dbg Green",
  211. "active": true,
  212. "tosidebar": true,
  213. "console": false,
  214. "tostatus": false,
  215. "complete": "true",
  216. "targetType": "full",
  217. "statusVal": "",
  218. "statusType": "auto",
  219. "x": 710,
  220. "y": 220,
  221. "wires": []
  222. },
  223. {
  224. "id": "2a7ac1490adc17f2",
  225. "type": "function",
  226. "z": "47a23c1e32bc602e",
  227. "name": "Random 0 - 1000",
  228. "func": "const MIN_VAL = 0;\nconst MAX_VAL = 1000;\n\nmsg.payload = Math.round(Math.random()*(MAX_VAL - MIN_VAL) + MIN_VAL);\n\nnode.status({text: \"Value: \" + msg.payload});\nreturn msg;",
  229. "outputs": 1,
  230. "timeout": 0,
  231. "noerr": 0,
  232. "initialize": "",
  233. "finalize": "",
  234. "libs": [],
  235. "x": 350,
  236. "y": 300,
  237. "wires": [
  238. [
  239. "6790a5e816e67fe8"
  240. ]
  241. ]
  242. },
  243. {
  244. "id": "4551df0b59990fe3",
  245. "type": "inject",
  246. "z": "47a23c1e32bc602e",
  247. "name": "Random",
  248. "props": [
  249. {
  250. "p": "payload"
  251. },
  252. {
  253. "p": "topic",
  254. "vt": "str"
  255. }
  256. ],
  257. "repeat": "",
  258. "crontab": "",
  259. "once": false,
  260. "onceDelay": 0.1,
  261. "topic": "",
  262. "payload": "",
  263. "payloadType": "date",
  264. "x": 160,
  265. "y": 300,
  266. "wires": [
  267. [
  268. "2a7ac1490adc17f2"
  269. ]
  270. ]
  271. }
  272. ]
Advertisement
Add Comment
Please, Sign In to add comment