Valve and IrrigationSystem
See original GitHub issueBased on this great wiki post. I have LC Tech 4ch relay (esp8266) running Tasmota and the article above does not fits my needs (no OpenSprinkler device or software).
So here is my workaround (heavily commented) with fully working timer.
[{"id":"2d469ba1.82003c","type":"tab","label":"вода","disabled":false,"info":""},{"id":"3becee57.bd9272","type":"homekit-service","z":"2d469ba1.82003c","isParent":true,"bridge":"bdd4551c.5849d","parentService":"","name":"Sprinkler1","serviceName":"Valve","topic":"","filter":false,"manufacturer":"ptath","model":"Ротор Irritrol 550","serialNo":"00001","characteristicProperties":"{\n \"ValveType\":\n {\n \"minValue\":1,\n \"maxValue\":1\n },\n \n \"SetDuration\":\n {\n \"minValue\":0,\n \"maxValue\":3600,\n \"validValues\": [300,600,1200,2400,3600]\n }\n}","x":244,"y":288,"wires":[["f4c45dca.981af8","8aacc164.a83628"]]},{"id":"8aacc164.a83628","type":"function","z":"2d469ba1.82003c","name":"Timer Handler","func":"// if timer changes in Home.app, set new duration\n// WARNING!!! this is NOT persistent, settings will gone after nodered restart\n// you should store it somewhere to production use, for example in file or DB\n// or set default timer value in HomeKit node (SetDuration minValue > 0)\n\nvar SetDuration, Valve1 = global.get(\"Valve1\");\n\nif(msg.hap.context !== undefined){\n if (msg.payload.SetDuration) {\n SetDuration = msg.payload.SetDuration; // seconds\n Valve1.SetDuration = SetDuration; // seconds\n global.set(\"Valve1\", Valve1);\n\n node.warn(\"New SetDuration is set: \" + global.get(\"Valve1\").SetDuration)\n }\n}\n\n// no output","outputs":1,"noerr":0,"x":448,"y":256,"wires":[[]]},{"id":"f4c45dca.981af8","type":"function","z":"2d469ba1.82003c","name":"On/Off Handler","func":"var RemainingDuration, newMsg, newpayload = {};\nvar Valve1 = global.get(\"Valve1\");\n\nif (msg.payload.Active === 1){\n\n if (Valve1.SetDuration) { // if duration is set while valve is turning on\n RemainingDuration = Valve1.SetDuration; // payload to HomeKit\n Valve1.StopTimer = Date.now() + RemainingDuration*1000; // milliseconds\n global.set(\"Valve1\", Valve1);\n\n node.warn(\"Turning ON Valve1 with timer \" + RemainingDuration + \" seconds\");\n // first output is MQTT node (Power1 ON), second — HomeKit node (RemainingDuration)\n return [{\"payload\": 1}, {\"payload\": {\"RemainingDuration\": RemainingDuration}}];\n }\n\n node.warn(\"Turning ON Valve1 with NO timer\");\n return [{\"payload\": 1},null];\n \n} else if (msg.payload.Active === 0) {\n\n node.warn(\"Turning OFF Valve1\");\n return [{\"payload\": 0},null];\n}\n","outputs":2,"noerr":0,"x":448,"y":296,"wires":[["309a41fa.97ce0e"],["1418cf19.aab189"]]},{"id":"309a41fa.97ce0e","type":"mqtt out","z":"2d469ba1.82003c","name":"Valve ON/OFF","topic":"cmnd/watering/POWER1","qos":"2","retain":"","broker":"119575ac.bc37e2","x":688,"y":296,"wires":[]},{"id":"736ec258.c7f4b4","type":"mqtt in","z":"2d469ba1.82003c","name":"Valve STAT","topic":"stat/watering/POWER1","qos":"2","datatype":"auto","broker":"119575ac.bc37e2","x":84,"y":192,"wires":[["5547a9f2.837248"]]},{"id":"5547a9f2.837248","type":"function","z":"2d469ba1.82003c","name":"State to HomeKit","func":"// pulling state from MQTT to HomeKit\n\nvar newMsg, newpayload = {};\nvar Valve1 = global.get(\"Valve1\");\n\nif (msg.payload == \"ON\"){\n newpayload.InUse = true;\n //newpayload.Active = true;\n Valve1.InUse = true;\n global.set(\"Valve1\", Valve1)\n} else if (msg.payload == \"OFF\") {\n newpayload.InUse = false;\n newpayload.Active = false;\n Valve1.InUse = false;\n global.set(\"Valve1\", Valve1)\n}\n\nnewMsg = { \"payload\": newpayload }\nreturn newMsg;","outputs":1,"noerr":0,"x":458,"y":192,"wires":[["3becee57.bd9272"]]},{"id":"2f61a5e4.75db3a","type":"link in","z":"2d469ba1.82003c","name":"","links":["1418cf19.aab189","bb840899.f99f8"],"x":119,"y":312,"wires":[["3becee57.bd9272"]]},{"id":"1418cf19.aab189","type":"link out","z":"2d469ba1.82003c","name":"Timer data","links":["2f61a5e4.75db3a"],"x":623,"y":352,"wires":[]},{"id":"106c6f7c.9b3ae1","type":"inject","z":"2d469ba1.82003c","name":"Timer check","topic":"","payload":"","payloadType":"date","repeat":"1","crontab":"","once":false,"onceDelay":0.1,"x":256,"y":352,"wires":[["a317f2c5.adb958"]]},{"id":"a317f2c5.adb958","type":"function","z":"2d469ba1.82003c","name":"Timer OFF Handler","func":"var Valve1 = global.get(\"Valve1\");\n\nif ((global.get(\"Valve1\").StopTimer <= Date.now()) &&\n (global.get(\"Valve1\").InUse === true)) \n {\n node.warn(\"Turning OFF Valve1 by timer\");\n // first output is MQTT, second — HomeKit\n return [{\"payload\": 0}, {\"payload\": {\"Active\": 0}}];\n} else {\n return [null, null];\n}\n","outputs":2,"noerr":0,"x":458,"y":336,"wires":[["309a41fa.97ce0e"],["1418cf19.aab189"]]},{"id":"bca42b7f.b1e5d","type":"mqtt in","z":"2d469ba1.82003c","name":"Valve TELE","topic":"tele/watering/STATE","qos":"2","datatype":"json","broker":"119575ac.bc37e2","x":84,"y":96,"wires":[["84958af.1eaa9f8"]]},{"id":"84958af.1eaa9f8","type":"change","z":"2d469ba1.82003c","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"POWER1","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":248,"y":144,"wires":[["a70a02f2.385c6"]]},{"id":"c70209be.7ddf1","type":"inject","z":"2d469ba1.82003c","name":"Global","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":true,"onceDelay":0.1,"x":74,"y":48,"wires":[["cbbaf292.c55eb"]]},{"id":"cbbaf292.c55eb","type":"function","z":"2d469ba1.82003c","name":"Set global Valve1 (empty)","func":"// global variable Valve1 to store state and settings\n\nvar Valve1 = {};\nglobal.set(\"Valve1\", Valve1);","outputs":1,"noerr":0,"x":278,"y":48,"wires":[[]]},{"id":"a70a02f2.385c6","type":"rbe","z":"2d469ba1.82003c","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":354,"y":96,"wires":[["5547a9f2.837248"]]},{"id":"43304657.98a99","type":"rbe","z":"2d469ba1.82003c","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":266,"y":192,"wires":[[]]},{"id":"bdd4551c.5849d","type":"homekit-bridge","z":"","bridgeName":"DRAGON-RED","pinCode":"111-11-111","port":"","allowInsecureRequest":false,"manufacturer":"ptath","model":"Raspberry Pi 3B+","serialNo":"0000","customMdnsConfig":false,"mdnsMulticast":true,"mdnsInterface":"","mdnsPort":"","mdnsIp":"","mdnsTtl":"","mdnsLoopback":true,"mdnsReuseAddr":true},{"id":"119575ac.bc37e2","type":"mqtt-broker","z":"","name":"LOCAL","broker":"192.168.1.10","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthRetain":"false","birthPayload":"","closeTopic":"","closeQos":"0","closeRetain":"false","closePayload":"","willTopic":"","willQos":"0","willRetain":"false","willPayload":""}]
I’m not so good in nodered so any comments or suggestions will be appreciated =) For example in this case I should repeat this code 4 times for every valve and change global variables to Valve(1-4) and this is annoying.
I found IrrigationSystem in HAP-NodeJS (and NRCHKB too), but no idea how to make it work. This is simple empty icon with no input and output, how to put my valves to it?
Issue Analytics
- State:
- Created 4 years ago
- Comments:10 (6 by maintainers)
Top Results From Across the Web
Sprinkler Valves - The Home Depot
Get free shipping on qualified Sprinkler Valves products or Buy Online Pick Up in Store today in the Outdoors Department.
Read more >How Do Sprinkler Valves Work? Rain Bird Irrigation - YouTube
Have you ever wondered how irrigation control valves work? In this short video, we'll take you on a tour inside a Rain Bird...
Read more >About sprinkler systems and how they work - Rachio Support
A master valve is an electric valve installed at the main water supply for the irrigation system. A master valve will greatly reduce...
Read more >Sprinkler System Valves - Amazon.com
Hunter 1" PGV Valve · Rain Bird CP075 In-Line Automatic Sprinkler Valve, 3/4" Threaded Female x Female · 3/4 Inline Sprinkler Valve ·...
Read more >Irrigation Valve Buying Guide
Irrigation Valves are used to create various watering zones in an irrigation system. This separation allows for different watering devices ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I am closing this as it’s pretty inactive. Please feel free to comment or open a new issue if required.
This “feature” is available from opensprinkler. I just made that one button send an HTTP request that starts the opensprinkler program…
The Home app is only ever displaying what opensprinkler is up to. I run opensprinkler and this homekit bridge on the same pi - I poll the opensprinkler api every second to keep things up to date in the Home app… The output of pressing a Home app sprinkler button is always to send an API request. Homekit has no part in the logic.