Advertisement
Guest User

AutoPi Node-Red

a guest
Apr 26th, 2019
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.52 KB | None | 0 0
  1. [
  2. {
  3. "id": "207111fc.39d516",
  4. "type": "http request",
  5. "z": "de854356.27206",
  6. "name": "login",
  7. "method": "POST",
  8. "ret": "obj",
  9. "url": "https://api.autopi.io/auth/login/",
  10. "tls": "",
  11. "x": 310,
  12. "y": 760,
  13. "wires": [
  14. [
  15. "377eeb2a.982804"
  16. ]
  17. ]
  18. },
  19. {
  20. "id": "be7c6baa.bdb1f8",
  21. "type": "inject",
  22. "z": "de854356.27206",
  23. "name": "send login data",
  24. "topic": "",
  25. "payload": "{\"email\":\"<your e-mail>\",\"password\":\"<your password>\"}",
  26. "payloadType": "json",
  27. "repeat": "14400",
  28. "crontab": "",
  29. "once": false,
  30. "onceDelay": 0.1,
  31. "x": 130,
  32. "y": 760,
  33. "wires": [
  34. [
  35. "207111fc.39d516"
  36. ]
  37. ]
  38. },
  39. {
  40. "id": "377eeb2a.982804",
  41. "type": "function",
  42. "z": "de854356.27206",
  43. "name": "saveLoginInfo",
  44. "func": "var token = { payload: msg.payload.token };\nflow.set(\"currentToken\", token.payload);\nvar deviceid = { payload: msg.payload.user.devices[0].id };\nflow.set(\"device_id\", deviceid.payload);\nvar unitid = { payload: msg.payload.user.devices[0].unit_id };\nflow.set(\"unit_id\", unitid.payload);\nreturn [token, deviceid, unitid];",
  45. "outputs": 3,
  46. "noerr": 0,
  47. "x": 460,
  48. "y": 760,
  49. "wires": [
  50. [
  51. "c615b916.6045"
  52. ],
  53. [
  54. "162f9b50.f8c3a5"
  55. ],
  56. [
  57. "d15b94d.563ad68"
  58. ]
  59. ],
  60. "outputLabels": [
  61. "token",
  62. "device_id",
  63. "unit_id"
  64. ]
  65. },
  66. {
  67. "id": "c615b916.6045",
  68. "type": "debug",
  69. "z": "de854356.27206",
  70. "name": "token",
  71. "active": false,
  72. "tosidebar": true,
  73. "console": false,
  74. "tostatus": false,
  75. "complete": "true",
  76. "targetType": "full",
  77. "x": 650,
  78. "y": 700,
  79. "wires": []
  80. },
  81. {
  82. "id": "162f9b50.f8c3a5",
  83. "type": "debug",
  84. "z": "de854356.27206",
  85. "name": "device_id",
  86. "active": false,
  87. "tosidebar": true,
  88. "console": false,
  89. "tostatus": false,
  90. "complete": "true",
  91. "targetType": "full",
  92. "x": 660,
  93. "y": 740,
  94. "wires": []
  95. },
  96. {
  97. "id": "d15b94d.563ad68",
  98. "type": "debug",
  99. "z": "de854356.27206",
  100. "name": "unit_id",
  101. "active": false,
  102. "tosidebar": true,
  103. "console": false,
  104. "tostatus": false,
  105. "complete": "true",
  106. "targetType": "full",
  107. "x": 650,
  108. "y": 780,
  109. "wires": []
  110. },
  111. {
  112. "id": "b46446ff.a25058",
  113. "type": "moment",
  114. "z": "de854356.27206",
  115. "name": "-1h",
  116. "topic": "",
  117. "input": "",
  118. "inputType": "date",
  119. "inTz": "Europe/Ljubljana",
  120. "adjAmount": "1",
  121. "adjType": "hours",
  122. "adjDir": "subtract",
  123. "format": "ISO8601",
  124. "locale": "C",
  125. "output": "from_utc",
  126. "outputType": "msg",
  127. "outTz": "Europe/Ljubljana",
  128. "x": 610,
  129. "y": 860,
  130. "wires": [
  131. [
  132. "24d252b1.194726"
  133. ]
  134. ]
  135. },
  136. {
  137. "id": "bc886b32.2beae8",
  138. "type": "inject",
  139. "z": "de854356.27206",
  140. "name": "batt_power+current+volts",
  141. "topic": "",
  142. "payload": "soc_display!batt_power!batt_current!batt_volts",
  143. "payloadType": "str",
  144. "repeat": "5",
  145. "crontab": "",
  146. "once": false,
  147. "onceDelay": 0.1,
  148. "x": 160,
  149. "y": 880,
  150. "wires": [
  151. [
  152. "72f326f4.de27a"
  153. ]
  154. ]
  155. },
  156. {
  157. "id": "88629479.a89ca",
  158. "type": "www-request",
  159. "z": "de854356.27206",
  160. "name": "get data",
  161. "method": "GET",
  162. "ret": "obj",
  163. "url": "",
  164. "follow-redirects": true,
  165. "tls": "",
  166. "x": 360,
  167. "y": 980,
  168. "wires": [
  169. [
  170. "d9540f9e.84663"
  171. ]
  172. ]
  173. },
  174. {
  175. "id": "24d252b1.194726",
  176. "type": "function",
  177. "z": "de854356.27206",
  178. "name": "storage > read > list (get PID)",
  179. "func": "msg.headers = {};\nmsg.headers['Authorization'] = 'bearer '+flow.get(\"currentToken\");\nmsg.device_id = flow.get(\"device_id\");\nmsg.url = \"https://api.autopi.io/logbook/storage/read/?from_utc=\"+msg.from_utc+\"&\"+\"field=obd.\"+msg.pid_id+\".value\"+\"&\"+\"field_type=json\"+\"&\"+\"device_id=\"+flow.get(\"device_id\")+\"&\"+\"interval=1s\"+\"&\"+\"end_utc=now\";\nreturn msg;",
  180. "outputs": 1,
  181. "noerr": 0,
  182. "x": 550,
  183. "y": 920,
  184. "wires": [
  185. [
  186. "88629479.a89ca"
  187. ]
  188. ]
  189. },
  190. {
  191. "id": "d9540f9e.84663",
  192. "type": "function",
  193. "z": "de854356.27206",
  194. "name": "dataProcessor",
  195. "func": "// poglej če ima array vsaj 1 podatek, če ne, vrni null\nvar outraw = {}\nvar textout = {}\nif (msg.payload.length >= 1){\n // battery power v kW (V*A)\n if (msg.pid_id == \"batt_power\"){\n outraw.payload = Number((msg.payload[msg.payload.length-1].value).toFixed(2));\n outraw.topic = \"stat/autopi/\"+msg.pid_id;\n textout = null;\n }\n // battery tok v A\n else if (msg.pid_id == \"batt_current\"){\n outraw.payload = Number((msg.payload[msg.payload.length-1].value).toFixed(2));\n outraw.topic = \"stat/autopi/\"+msg.pid_id;\n textout = null;\n }\n // battery tok v V\n else if (msg.pid_id == \"batt_volts\"){\n outraw.payload = Number((msg.payload[msg.payload.length-1].value).toFixed(2));\n outraw.topic = \"stat/autopi/\"+msg.pid_id;\n textout = null;\n }\n // SOC display\n else if (msg.pid_id == \"soc_display\"){\n outraw.payload = Number((msg.payload[msg.payload.length-1].value).toFixed(2));\n outraw.topic = \"stat/autopi/\"+msg.pid_id;\n textout = { payload: \"Stanje akumulatorja: \" + msg.payload[msg.payload.length-1].value.toFixed(2) + \" %\" };\n }\n // battery SOH\n else if (msg.pid_id == \"soh\"){\n outraw.payload = Number(msg.payload[msg.payload.length-1].value.toFixed(2));\n outraw.topic = \"stat/autopi/\"+msg.pid_id;\n textout = null;\n }\n // temperatura sklopa 1\n else if (msg.pid_id == \"batt_temp1\"){\n outraw.payload = Number((msg.payload[msg.payload.length-1].value).toFixed(2));\n outraw.topic = \"stat/autopi/\"+msg.pid_id;\n textout = null;\n }\n // temperatura sklopa 2\n else if (msg.pid_id == \"batt_temp2\"){\n outraw.payload = Number((msg.payload[msg.payload.length-1].value).toFixed(2));\n outraw.topic = \"stat/autopi/\"+msg.pid_id;\n textout = null;\n }\n // temperatura sklopa 3\n else if (msg.pid_id == \"batt_temp3\"){\n outraw.payload = Number((msg.payload[msg.payload.length-1].value).toFixed(2));\n outraw.topic = \"stat/autopi/\"+msg.pid_id;\n textout = null;\n }\n // temperatura sklopa 4\n else if (msg.pid_id == \"batt_temp4\"){\n outraw.payload = Number((msg.payload[msg.payload.length-1].value).toFixed(2));\n outraw.topic = \"stat/autopi/\"+msg.pid_id;\n textout = null;\n }\n // temperatura sklopa 5\n else if (msg.pid_id == \"batt_temp5\"){\n outraw.payload = Number((msg.payload[msg.payload.length-1].value).toFixed(2));\n outraw.topic = \"stat/autopi/\"+msg.pid_id;\n textout = null;\n }\n // temperatura sklopa 6\n else if (msg.pid_id == \"batt_temp6\"){\n outraw.payload = Number((msg.payload[msg.payload.length-1].value).toFixed(2));\n outraw.topic = \"stat/autopi/\"+msg.pid_id;\n textout = null;\n }\n // temperatura sklopa 7\n else if (msg.pid_id == \"batt_temp7\"){\n outraw.payload = Number((msg.payload[msg.payload.length-1].value).toFixed(2));\n outraw.topic = \"stat/autopi/\"+msg.pid_id;\n textout = null;\n }\n // temperatura sklopa 8\n else if (msg.pid_id == \"batt_temp8\"){\n outraw.payload = Number((msg.payload[msg.payload.length-1].value).toFixed(2));\n outraw.topic = \"stat/autopi/\"+msg.pid_id;\n textout = null;\n }\n // temperatura sklopa 9\n else if (msg.pid_id == \"batt_temp9\"){\n outraw.payload = Number((msg.payload[msg.payload.length-1].value).toFixed(2));\n outraw.topic = \"stat/autopi/\"+msg.pid_id;\n textout = null;\n }\n // temperatura sklopa 10\n else if (msg.pid_id == \"batt_temp10\"){\n outraw.payload = Number((msg.payload[msg.payload.length-1].value).toFixed(2));\n outraw.topic = \"stat/autopi/\"+msg.pid_id;\n textout = null;\n }\n // temperatura sklopa 22\n else if (msg.pid_id == \"batt_temp11\"){\n outraw.payload = Number((msg.payload[msg.payload.length-1].value).toFixed(2));\n outraw.topic = \"stat/autopi/\"+msg.pid_id;\n textout = null;\n }\n // temperatura sklopa 23\n else if (msg.pid_id == \"batt_temp12\"){\n outraw.payload = Number((msg.payload[msg.payload.length-1].value).toFixed(2));\n outraw.topic = \"stat/autopi/\"+msg.pid_id;\n textout = null;\n }\n else {\n outraw = null;\n textout = null;\n }\n}\nelse {\n outraw = null;\n textout = null;\n}\nreturn [outraw, textout]",
  196. "outputs": 2,
  197. "noerr": 0,
  198. "x": 560,
  199. "y": 980,
  200. "wires": [
  201. [
  202. "56aad096.3322c8",
  203. "720b7c4d.3962b4"
  204. ],
  205. [
  206. "4182ad79.fe7c4c",
  207. "865643df.82c22"
  208. ]
  209. ],
  210. "outputLabels": [
  211. "outRaw",
  212. "TelegramOut"
  213. ]
  214. },
  215. {
  216. "id": "720b7c4d.3962b4",
  217. "type": "mqtt out",
  218. "z": "de854356.27206",
  219. "name": "AutoPi out",
  220. "topic": "",
  221. "qos": "0",
  222. "retain": "false",
  223. "broker": "9c9e2d3f.25de88",
  224. "x": 950,
  225. "y": 960,
  226. "wires": []
  227. },
  228. {
  229. "id": "56aad096.3322c8",
  230. "type": "debug",
  231. "z": "de854356.27206",
  232. "name": "",
  233. "active": false,
  234. "tosidebar": true,
  235. "console": false,
  236. "tostatus": false,
  237. "complete": "true",
  238. "targetType": "full",
  239. "x": 770,
  240. "y": 920,
  241. "wires": []
  242. },
  243. {
  244. "id": "bc11f57a.a03c5",
  245. "type": "change",
  246. "z": "de854356.27206",
  247. "name": "move to pid_id",
  248. "rules": [
  249. {
  250. "t": "move",
  251. "p": "payload",
  252. "pt": "msg",
  253. "to": "pid_id",
  254. "tot": "msg"
  255. }
  256. ],
  257. "action": "",
  258. "property": "",
  259. "from": "",
  260. "to": "",
  261. "reg": false,
  262. "x": 420,
  263. "y": 860,
  264. "wires": [
  265. [
  266. "b46446ff.a25058"
  267. ]
  268. ]
  269. },
  270. {
  271. "id": "316b2d84.64e75a",
  272. "type": "telegrambot-notify",
  273. "z": "de854356.27206",
  274. "name": "IoniqBot",
  275. "bot": "6776ad8c.1cf8e4",
  276. "chatId": "128829131",
  277. "message": "",
  278. "parseMode": "",
  279. "x": 940,
  280. "y": 1020,
  281. "wires": []
  282. },
  283. {
  284. "id": "4182ad79.fe7c4c",
  285. "type": "rbe",
  286. "z": "de854356.27206",
  287. "name": "",
  288. "func": "rbei",
  289. "gap": "",
  290. "start": "",
  291. "inout": "out",
  292. "property": "payload",
  293. "x": 770,
  294. "y": 1020,
  295. "wires": [
  296. [
  297. "316b2d84.64e75a"
  298. ]
  299. ]
  300. },
  301. {
  302. "id": "8ff29e2.7c3876",
  303. "type": "inject",
  304. "z": "de854356.27206",
  305. "name": "",
  306. "topic": "",
  307. "payload": "soh",
  308. "payloadType": "str",
  309. "repeat": "3600",
  310. "crontab": "",
  311. "once": false,
  312. "onceDelay": 0.1,
  313. "x": 90,
  314. "y": 960,
  315. "wires": [
  316. [
  317. "bc11f57a.a03c5"
  318. ]
  319. ]
  320. },
  321. {
  322. "id": "865643df.82c22",
  323. "type": "debug",
  324. "z": "de854356.27206",
  325. "name": "",
  326. "active": false,
  327. "tosidebar": true,
  328. "console": false,
  329. "tostatus": false,
  330. "complete": "true",
  331. "targetType": "full",
  332. "x": 770,
  333. "y": 1060,
  334. "wires": []
  335. },
  336. {
  337. "id": "12770b91.f25e04",
  338. "type": "inject",
  339. "z": "de854356.27206",
  340. "name": "batt_temp1-12",
  341. "topic": "",
  342. "payload": "batt_temp1!batt_temp2!batt_temp3!batt_temp4!batt_temp5!batt_temp6!batt_temp7!batt_temp8!batt_temp9!batt_temp10!batt_temp11!batt_temp12",
  343. "payloadType": "str",
  344. "repeat": "30",
  345. "crontab": "",
  346. "once": false,
  347. "onceDelay": 0.1,
  348. "x": 120,
  349. "y": 920,
  350. "wires": [
  351. [
  352. "72f326f4.de27a"
  353. ]
  354. ]
  355. },
  356. {
  357. "id": "72f326f4.de27a",
  358. "type": "split",
  359. "z": "de854356.27206",
  360. "name": "",
  361. "splt": "!",
  362. "spltType": "str",
  363. "arraySplt": 1,
  364. "arraySpltType": "len",
  365. "stream": false,
  366. "addname": "",
  367. "x": 290,
  368. "y": 920,
  369. "wires": [
  370. [
  371. "bc11f57a.a03c5"
  372. ]
  373. ]
  374. },
  375. {
  376. "id": "9c9e2d3f.25de88",
  377. "type": "mqtt-broker",
  378. "z": "",
  379. "name": "HASS",
  380. "broker": "localhost",
  381. "port": "1883",
  382. "clientid": "node-red",
  383. "usetls": false,
  384. "compatmode": true,
  385. "keepalive": "60",
  386. "cleansession": true,
  387. "birthTopic": "",
  388. "birthQos": "0",
  389. "birthPayload": "",
  390. "closeTopic": "",
  391. "closeQos": "0",
  392. "closePayload": "",
  393. "willTopic": "",
  394. "willQos": "0",
  395. "willPayload": ""
  396. },
  397. {
  398. "id": "6776ad8c.1cf8e4",
  399. "type": "telegrambot-config",
  400. "z": "",
  401. "botname": "IoniqBot",
  402. "usernames": "",
  403. "chatIds": "",
  404. "pollInterval": "300"
  405. }
  406. ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement