[{"id":"e92f49ff.42fec8","type":"Xiaomi BLE","z":"3780f1f9.595fce","name":"Miflora","address":"","scanningTimeout":60,"x":470,"y":180,"wires":[["d236d076.46815"]]},{"id":"173175c0.a9b83a","type":"function","z":"3780f1f9.595fce","name":"add msg.address","func":"//Requires:\n//a message in the format PlantX/payload where X\n// is the numeric indicator of the sensor to be queried\n// and the payload is the mac address of the deice to be queried.\n//Returns:\n// a message in the same format as recieved\n// after the message address property has been touched\n//(not quite sure whats needed here so msg.address is set to the mac addy too)\n//Results\n// no expected side effets beyond\n// the message topic identifying the sensor is \n// saved in the flow variable plant as te next node \n// overwrites the message topic and looses this crucial data.\nvar plant = flow.get('plant')||'PlantX';\nflow.set(\"plant\", msg.topic)\nmsg.address = msg.payload;\nreturn msg;","outputs":1,"noerr":0,"x":310,"y":180,"wires":[["e92f49ff.42fec8"]]},{"id":"1caa0f41.5dbc11","type":"inject","z":"3780f1f9.595fce","name":"Plant1 inj","topic":"Plant1","payload":"C4:7C:8D:64:43:F5","payloadType":"str","repeat":"3600","crontab":"","once":true,"onceDelay":"","x":110,"y":80,"wires":[["173175c0.a9b83a"]]},{"id":"1ec32429.28c63c","type":"inject","z":"3780f1f9.595fce","name":"Plant2 inj","topic":"Plant2","payload":"C4:7C:8D:64:43:C8","payloadType":"str","repeat":"3600","crontab":"","once":true,"onceDelay":"300","x":110,"y":120,"wires":[["173175c0.a9b83a"]]},{"id":"bb86328e.39713","type":"inject","z":"3780f1f9.595fce","name":"Plant3 inj","topic":"Plant3","payload":"C4:7C:8D:64:43:6F","payloadType":"str","repeat":"3600","crontab":"","once":true,"onceDelay":"600","x":110,"y":160,"wires":[["173175c0.a9b83a"]]},{"id":"fe342446.9dce18","type":"inject","z":"3780f1f9.595fce","name":"Plant4 inj","topic":"Plant4","payload":"C4:7C:8D:64:47:A7","payloadType":"str","repeat":"3600","crontab":"","once":true,"onceDelay":"900","x":110,"y":200,"wires":[["173175c0.a9b83a"]]},{"id":"f1ce3ea5.b6ec6","type":"inject","z":"3780f1f9.595fce","name":"Plant5 inj","topic":"Plant5","payload":"C4:7C:8D:64:43:AE","payloadType":"str","repeat":"3600","crontab":"","once":true,"onceDelay":"1200","x":110,"y":240,"wires":[["173175c0.a9b83a"]]},{"id":"fd76dc24.e5778","type":"inject","z":"3780f1f9.595fce","name":"Plant6 inj","topic":"Plant6","payload":"C4:7C:8D:64:43:61","payloadType":"str","repeat":"3600","crontab":"","once":true,"onceDelay":"1500","x":110,"y":280,"wires":[["173175c0.a9b83a"]]},{"id":"d236d076.46815","type":"function","z":"3780f1f9.595fce","name":"Notification machine","func":"Requires:\n// A sensor id saved in the flow variable 'plant'\n// And a message with a payload containing Json tupples\n// of metric:reading\n// Returns\n// a set (array) of 4 messages with the topic drived from\n// both the plant/sensor id and the metric the data represents\n// in the format Notify/Plant/X(plantid)/metric\n//Results\n// no expected side effects\nvar plant = flow.get('plant')||'PlantY';\nvar part1 = plant.slice(0,5);\nvar part2 = plant.slice(-1);\nplant = part1 +'/' + part2;\nvar msg1 = { payload: msg.payload.moisture };\nvar msg2 = { payload: msg.payload.battery };\nvar msg3 = { payload: msg.payload.temperature };\nvar msg4 = { payload: msg.payload.conductivity };\n//moisture msg1\n//msg1.payload = msg.payload.moisture;\nmsg1.topic = 'Notify/'+ plant +'/M';\n// battery msg2\n//msg2.payload = msg.payload.battery;\nmsg2.topic = 'Notify/'+ plant +'/B';\n// Temp msg3\n//msg3.payload = msg.payload.temperature; //.payload.temperature;\nmsg3.topic = 'Notify/'+ plant +'/T';\n//EC msg4\n//msg4.payload = msg.payload.conductivity;\nmsg4.topic = 'Notify/'+ plant +'/EC';\nreturn [[msg1,msg2,msg3,msg4]]","outputs":1,"noerr":0,"x":640,"y":180,"wires":[["4272f32c.02468c"]]},{"id":"4272f32c.02468c","type":"mqtt out","z":"3780f1f9.595fce","name":"Notify!","topic":"","qos":"","retain":"","broker":"6b77dcc0.90e0c4","x":810,"y":180,"wires":[]},{"id":"d22587cd.bfed08","type":"mqtt in","z":"3780f1f9.595fce","name":"","topic":"Notify/Plant/#","qos":"2","broker":"6b77dcc0.90e0c4","x":290,"y":280,"wires":[["8936e1e.b30cd2"]]},{"id":"8936e1e.b30cd2","type":"function","z":"3780f1f9.595fce","name":"Warnings Generator","func":"//WORK IN PROGRESS\n// only looking at sensors atm, other notifications to be catered for later\n// Battery, temperature, and EC warning levels are\n// hard coded until moisture gui is sorted.. \n//Requires;\n// a notification message, its topic prefixed with 'Notify/'\n// Sensor data:\n// sensor data topics will follow 'Notify/' with 'Plant/'\n// the next 2 topic keys are the sensor/plant area number and the metric code\n// the payload is the data referenced by the topic\n//Returns:\n// any message recieved failing any conditions tested a suitable\n// warning/error/action message will be issued.\n//Results:\n// no unexpected side effects\nvar plantid = msg.topic.split(\"/\")[2];\nvar metric = msg.topic.split(\"/\")[3];\nswitch(metric) {\n case 'M': // moisture\n var pxmml = 'P' + plantid + 'MML';\n var mml = global.get(pxmml)||30;\n if (msg.payload < mml) {\n msg.topic = 'Action/Water';\n msg.payload = plantid; \n return msg;\n }\n break;\n case 'B': //Battery level\n if(msg.payload < 15){\n msg.topic = 'Warning/Plants/' + plantid + '/Low battery level';\n return msg;\n }\n break;\n case 'T': // Temperature\n if(msg.payload < 10){\n msg.topic = 'Warning/Plants/' + plantid + '/Low Temperature';\n return msg;\n }\n if(msg.payload > 35) {\n msg.topic = 'Warning/Plants/' + plantid + '/High Temperature';\n return msg;\n }\n break;\n case 'EC': // EC\n if(msg.payload < 150) {\n msg.topic = 'Warning/Plants/' + plantid + '/Low EC Level';\n return msg;\n }\n break;\n default:\n msg,topic = 'Happy/Happy';\n msg.payload ='Joy/Joy';\n return msg;\n}\n","outputs":1,"noerr":0,"x":480,"y":280,"wires":[["b736068f.4ecef8"]]},{"id":"b736068f.4ecef8","type":"mqtt out","z":"3780f1f9.595fce","name":"Issue warnings etc","topic":"","qos":"","retain":"","broker":"6b77dcc0.90e0c4","x":710,"y":280,"wires":[]},{"id":"5e96f51d.3a77ec","type":"mqtt in","z":"3780f1f9.595fce","name":"Respond To Water Action Messages","topic":"Action/Water","qos":"2","broker":"4405e653.095428","x":160,"y":360,"wires":[["63933883.be31b8","10df2125.c3f84f"]]},{"id":"63933883.be31b8","type":"function","z":"3780f1f9.595fce","name":"Water indicated area","func":"msg.topic = 'tasmota/sonoff-mypump' + msg.payload + '/cmnd/Power1';\nmsg.payload = 1;\nreturn msg;","outputs":1,"noerr":0,"x":450,"y":360,"wires":[["cb0cc82a.7a7698"]]},{"id":"cb0cc82a.7a7698","type":"mqtt out","z":"3780f1f9.595fce","name":"Issue water command","topic":"","qos":"","retain":"","broker":"6b77dcc0.90e0c4","x":700,"y":360,"wires":[]},{"id":"431ef56b.60f91c","type":"mqtt in","z":"3780f1f9.595fce","name":"Respond to warnings issued","topic":"Warning/Plants/#","qos":"2","broker":"6b77dcc0.90e0c4","x":140,"y":440,"wires":[["10df2125.c3f84f"]]},{"id":"10df2125.c3f84f","type":"function","z":"3780f1f9.595fce","name":"construct email warning","func":"msg.topic = msg.topic + ' ' + msg.payload ;\nmsg.payload = 'Dear Sucker, your getting this cos NodeRedAdmin@PizeroW0 has you on the naughty list';\nreturn msg;","outputs":1,"noerr":0,"x":410,"y":440,"wires":[["b292f17e.a76bf"]]},{"id":"6b77dcc0.90e0c4","type":"mqtt-broker","z":"","name":"","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"4405e653.095428","type":"mqtt-broker","z":"","name":"","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","willTopic":"","willQos":"0","willPayload":""}]