-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathNode-RED_hub-flow.json
1 lines (1 loc) · 7.98 KB
/
Node-RED_hub-flow.json
1
[{"id":"7d4a1686.82b5e8","type":"mqtt-broker","broker":"mqtt.opensensors.io","port":"1883","clientid":"1341"},{"id":"a342d86a.5cbd28","type":"serial-port","serialport":"/dev/tty.usbmodem000001","serialbaud":"115200","databits":"8","parity":"none","stopbits":"1","newline":"20","bin":"false","out":"time","addchar":true},{"id":"7b3e5b9.f84c1a4","type":"serial in","name":"radio","serial":"a342d86a.5cbd28","x":92,"y":63,"z":"8710d1b4.78ef3","wires":[["236c4c15.dc93b4","ad34b3e3.52cb5"]]},{"id":"236c4c15.dc93b4","type":"debug","name":"radio message","active":true,"console":"false","complete":"payload","x":889,"y":59,"z":"8710d1b4.78ef3","wires":[]},{"id":"ad34b3e3.52cb5","type":"function","name":"extract_SensorNames_lastLog","func":"context.global.sensors = context.global.sensors || { };\n\nvar result = msg.payload.match(/a(.*)CM/);\n if (result) {\n context.global.sensors[result[1]] = new Date();\n }\n \nreturn msg;","outputs":1,"valid":true,"x":324,"y":140,"z":"8710d1b4.78ef3","wires":[["d3ebd4a5.2c1428","421fdef0.bde02"]]},{"id":"c237f18e.3dc81","type":"http in","name":"/status","url":"/status","method":"get","x":266,"y":560,"z":"8710d1b4.78ef3","wires":[["d8fa8ee.f27057"]]},{"id":"c21af81f.3de508","type":"http response","name":"","x":890,"y":558,"z":"8710d1b4.78ef3","wires":[]},{"id":"8ac6f021.75391","type":"template","name":"status page","field":"payload","template":"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional/EN\">\n\n<html>\n<head>\n<meta http-equiv=\"refresh\" content=\"30\"><meta charset=\"utf-8\">\n<title>Status</title>\n</head>\n\n<H1>DEVICES</H1>\n{{{sensors}}}\n\n<H1>READINGS</H1>\n{{{readings}}}\n\n<H1>SETTINGS</H1>\n{{{settings}}}\n\n<b>Change:</b> Set new parameters and press 'submit' to confirm - <b>the form will return to defaults</b><br>\nThis could be made more fancy and visually appealing.\n<br><br> \n<form action=\"config\" method=\"post\">\n<b>Weekend sleep</b><br>\n<input type=\"radio\" name=\"ws\" value=\"YES\" checked> YES \n<input type=\"radio\" name=\"ws\" value=\"NO\"> NO\n<br><br> \n<b>Night sleep</b><br>\n<input type=\"radio\" name=\"ns\" value=\"YES\" checked> YES \n<input type=\"radio\" name=\"ns\" value=\"NO\"> NO\n<br> \n<br>\nsleep from \n<select name=\"start\">\n<option value=\"13\">1 pm</option>\n<option value=\"14\">2 pm</option>\n<option value=\"15\">3 pm</option>\n<option value=\"16\">4 pm</option>\n<option value=\"17\">5 pm</option>\n<option value=\"18\">6 pm</option>\n<option value=\"19 selected\">7 pm</option>\n<option value=\"20\">8 pm</option>\n<option value=\"21\">9 pm</option>\n<option value=\"22\">10 pm</option>\n<option value=\"23\">11 pm</option>\n</select>\n to \n<select name=\"end\">\n<option value=\"5\">5 am</option>\n<option value=\"6\">6 am</option>\n<option value=\"7\" selected>7 am</option>\n<option value=\"8\">8 am</option>\n<option value=\"9\">9 am</option>\n<option value=\"10\">10 am</option>\n</select>\n\n<button type=\"submit\">Submit</button>\n</form>\n\n</html>","x":666,"y":558,"z":"8710d1b4.78ef3","wires":[["c21af81f.3de508"]]},{"id":"d8fa8ee.f27057","type":"function","name":"gather info","func":"context.global.sensors = context.global.sensors || { };\ncontext.status = context.status || [ ];\n\nvar sensors = \"\";\n\n if (typeof msg.topic !== 'undefined') {\n context.status.unshift(msg.topic+\" \"+msg.payload+\"<BR>\");\n if (context.status.length >= 15) {\n context.status.pop();\n }\n \n } else {\n\n for (var sensor in context.global.sensors) {\n sensors += sensor+\" (last seen: \"+context.global.sensors[sensor]+\") <BR>\";\n }\n \n msg.sensors = sensors;\n msg.readings = context.status;\n msg.settings = \"<b>Currently <u>active</u> settings:</b><br>\"+\n \"Weekend sleep : \"+context.global.weekend_sleep+\"<br>\"+\n \"Night sleep : \"+context.global.night_sleep+\"<br>\"+\n \"if so, from-to : \"+context.global.begin_sleep+\"h - \"+context.global.end_sleep+\"h<br><br>\";\n return msg;\n \n }","outputs":1,"valid":true,"x":459,"y":559,"z":"8710d1b4.78ef3","wires":[["8ac6f021.75391"]]},{"id":"d3ebd4a5.2c1428","type":"function","name":"extractSensorNames_distances","func":"var result = msg.payload.match(/a(.*)CM(\\d*)/);\n\n if (result) {\n msg.topic = \"/users/boris/OccupancyHub/\"+result[1];\n msg.payload = result[2];\n \n return msg;\n }","outputs":1,"valid":true,"x":656,"y":140,"z":"8710d1b4.78ef3","wires":[["d38f6fa6.2c709"]]},{"id":"d38f6fa6.2c709","type":"mqtt out","name":"","topic":"","qos":"","retain":"","broker":"7d4a1686.82b5e8","x":911,"y":141,"z":"8710d1b4.78ef3","wires":[]},{"id":"421fdef0.bde02","type":"function","name":"queries_CHECKTIME?","func":"var result = msg.payload.match(/CHECKTIME/);\n if (result) {\n var hourEnd = parseInt(context.global.end_sleep);\n var hourStart = parseInt(context.global.begin_sleep);\n var hourNow = new Date().getHours();\n if (context.global.night_sleep === \"YES\" && (hourNow < hourEnd || hourNow >= hourStart)) {\n \n var hours = 0;\n \n if (hourNow > hourEnd) {\n hours = (24-hourNow)+hourEnd;\n } else {\n hours = (hourEnd-hourNow);\n }\n \n \n if (context.global.weekend_sleep === \"YES\") { \n var dayofWeek = new Date().getDay();\n if (dayofWeek === 5) {\n hours += 48;\n }\n if (dayofWeek === 6) {\n hours += 24;\n }\n } \n \n msg.topic = \"sleep\"; \n msg.payload = hours;\n }\n }\n \nreturn msg;","outputs":1,"valid":true,"x":291,"y":264,"z":"8710d1b4.78ef3","wires":[["34930a4a.cb6cf6"]]},{"id":"34930a4a.cb6cf6","type":"switch","name":"sleep?","property":"topic","rules":[{"t":"cont","v":"sleep"}],"checkall":"true","outputs":1,"x":535,"y":264,"z":"8710d1b4.78ef3","wires":[["46ff559e.b900ac"]]},{"id":"46ff559e.b900ac","type":"function","name":"","func":"msg.payload = msg.payload+\"SLEEP\";\nreturn msg;","outputs":1,"valid":true,"x":718,"y":264,"z":"8710d1b4.78ef3","wires":[["d952bda8.26ad4","1ab00da3.e54ff2"]]},{"id":"d952bda8.26ad4","type":"debug","name":"","active":true,"console":"false","complete":"false","x":871,"y":334,"z":"8710d1b4.78ef3","wires":[]},{"id":"1ab00da3.e54ff2","type":"serial out","name":"radio out","serial":"a342d86a.5cbd28","x":909,"y":264,"z":"8710d1b4.78ef3","wires":[]},{"id":"855a5ca4.7aa5a","type":"mqtt in","name":"","topic":"/users/boris/OccupancyHub/+","broker":"7d4a1686.82b5e8","x":301,"y":426,"z":"8710d1b4.78ef3","wires":[["d8fa8ee.f27057"]]},{"id":"7aba1c40.8545e4","type":"http in","name":"/config","url":"/config","method":"post","x":262,"y":647,"z":"8710d1b4.78ef3","wires":[["edc25984.123da8"]]},{"id":"edc25984.123da8","type":"function","name":"set config","func":"context.global.weekend_sleep = msg.req.body[\"ws\"];\ncontext.global.night_sleep = msg.req.body[\"ns\"];\ncontext.global.begin_sleep = msg.req.body[\"start\"];\ncontext.global.end_sleep = msg.req.body[\"end\"];\n\nreturn msg;","outputs":1,"valid":true,"x":451,"y":648,"z":"8710d1b4.78ef3","wires":[["8da1f62c.725e08"]]},{"id":"18c92610.e736da","type":"inject","name":"startup","topic":"","payload":"","payloadType":"string","repeat":"","crontab":"","once":true,"x":262,"y":700,"z":"8710d1b4.78ef3","wires":[["fe1d7727.01e288"]]},{"id":"fe1d7727.01e288","type":"function","name":"init config","func":"context.global.weekend_sleep = \"YES\";\ncontext.global.night_sleep = \"YES\";\ncontext.global.begin_sleep = 19;\ncontext.global.end_sleep = 7;\n\nreturn msg;","outputs":1,"valid":true,"x":450,"y":699,"z":"8710d1b4.78ef3","wires":[[]]},{"id":"8da1f62c.725e08","type":"template","name":"","field":"payload","format":"handlebars","template":"<HTML>\n <HEAD><meta http-equiv=\"refresh\" content=\"0; url=http://localhost:1880/status\" /></HEAD>\n</HTML>","x":652,"y":647,"z":"8710d1b4.78ef3","wires":[["176752d1.e898ad"]]},{"id":"176752d1.e898ad","type":"http response","name":"","x":889,"y":646,"z":"8710d1b4.78ef3","wires":[]}]