bbreukelen / node-rainbird

Rainbird controller in Node.js
GNU General Public License v3.0
17 stars 2 forks source link

Node Red usage #7

Open StofLE opened 2 years ago

StofLE commented 2 years ago

Hi,

it would be cool to use it with Node Red because I have sensors or online weather services. So I could more automate it (e.g. startZone depending on moisture sensors or setRainDelay when rain is coming...).

Maybe somebody can help with an example flow or (with skills) even better a node red module...

Stefan

mbrackjr commented 2 years ago

Hi Stefan,

Perhaps you've already figured it out yourself, but for anyone interested to use this nice node from within NodeRED, here's a code snippet. Change IP and PIN inside the function to the ones of your Rainbird LNK-Wifi module and check the start and stop nodes for details.

Manfred

[{"id":"52683fa8b55a1549","type":"tab","label":"rainbird","disabled":false,"info":"","env":[]},{"id":"d9c0719442696b69","type":"function","z":"52683fa8b55a1549","name":"Rainbird","func":"var rainbird = new RainBirdClass(\"ip_address_here\", \"pincode_here\");\nmsg1={};\n\nswitch (msg.payload.zone) {\n case 'zone_1':\n var zone_decimal = 1; break;\n case 'zone_2':\n var zone_decimal = 2; break;\n case 'zone_3':\n var zone_decimal = 3; break;\n case 'zone_4':\n var zone_decimal = 4; break;\n}\n\nif (msg.topic == 'rainbird/start') {\n rainbird\n .startZone(zone_decimal, msg.payload.duration)\n .then(rainbird => {\n msg1.topic = \"homekit/irrigation/\" + msg.payload.zone;\n msg1.payload = { \"InUse\" : 1 };\n node.send(msg1);\n node.status({fill:\"green\",shape:\"dot\",text:\"zone: \"+msg.payload.zone+\" / \"+msg.payload.duration+\" minutes\"});\n })\n .catch(rainbird => {\n node.status({fill:\"blue\",shape:\"dot\",text:rainbird});\n })\n ;\n}\n\nif (msg.topic == 'rainbird/stop') {\n rainbird\n .stopIrrigation()\n .then(rainbird => {\n msg1.topic = \"homekit/irrigation/\" + msg.payload.zone;\n msg1.payload = { \"InUse\" : 0 };\n node.send(msg1);\n node.status({fill:\"red\",shape:\"dot\",text:\"off\"});\n })\n .catch(rainbird => {\n node.status({fill:\"blue\",shape:\"dot\",text:rainbird});\n })\n ;\n}\n\nreturn;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[{"var":"RainBirdClass","module":"node-rainbird"}],"x":490,"y":250,"wires":[["af4cb3cc5e38abd5"]],"icon":"font-awesome/fa-tint"},{"id":"d6e7cd59351e52eb","type":"inject","z":"52683fa8b55a1549","name":"start zone_4","props":[{"p":"topic","vt":"str"},{"p":"payload.zone","v":"zone_4","vt":"str"},{"p":"payload.duration","v":"2","vt":"num"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"rainbird/start","x":310,"y":220,"wires":[["d9c0719442696b69"]]},{"id":"af4cb3cc5e38abd5","type":"debug","z":"52683fa8b55a1549","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":680,"y":250,"wires":[]},{"id":"f1fd7c886e2fcb12","type":"inject","z":"52683fa8b55a1549","name":"stop zone_4","props":[{"p":"topic","vt":"str"},{"p":"payload.zone","v":"zone_4","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"rainbird/stop","x":310,"y":280,"wires":[["d9c0719442696b69"]]}]