# Automatic sprinkler system

**URL:** <https://discourse.nodered.org/t/automatic-sprinkler-system/30301>\
**Category:** General\
**Created:** [18 July 2020 20:13 UTC](https://discourse.nodered.org/t/automatic-sprinkler-system/30301 "2020-07-18T20:13:34Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vlak](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/vlak/32/26888_2.png) [@Vlak](https://discourse.nodered.org/u/Vlak)\
**Post date:** [18 July 2020 20:13 UTC](https://discourse.nodered.org/t/automatic-sprinkler-system/30301/1 "2020-07-18T20:13:34Z")

</div>

Dear people can anyone help me with the following. Il recently installed a rain gauge. Now I want to link my irrigation system to this. What I want to do with this is quite simple and I do the following.  
I want to take a measurement at the beginning of the day and then at the end of the day to do another 1 there is a difference of 15mm of rain between the two measurements, then my sprinkler system may remain off, because there has been enough rain. Does anyone know with which node I can do this. Preferably by writing as little code as possible.

So a node that gets a start value has an end value, if it is more than 15mm then it must give an output with which I can block the sprinkling.

gr Vlak

---

<div class="post-metadata">

**Author:** ![ristomatti](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ristomatti/32/5857_2.png) [@ristomatti](https://discourse.nodered.org/u/ristomatti)\
**Post date:** [18 July 2020 21:13 UTC](https://discourse.nodered.org/t/automatic-sprinkler-system/30301/2 "2020-07-18T21:13:08Z")

</div>

I have a rain gauge which outputs a constantly increasing number. I've used [node-red-contrib-totaliser](https://flows.nodered.org/node/node-red-contrib-totaliser) to give hourly and daily rain values. I have configured it to output a diff between the start and end value within the given time frame.

---

<div class="post-metadata">

**Author:** ![Vlak](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/vlak/32/26888_2.png) [@Vlak](https://discourse.nodered.org/u/Vlak)\
**Post date:** [19 July 2020 07:44 UTC](https://discourse.nodered.org/t/automatic-sprinkler-system/30301/3 "2020-07-19T07:44:58Z")

</div>

Hi ristomatti, can you show me your flow. and especially your totaliser settings

---

<div class="post-metadata">

**Author:** ![ristomatti](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ristomatti/32/5857_2.png) [@ristomatti](https://discourse.nodered.org/u/ristomatti)\
**Post date:** [19 July 2020 08:36 UTC](https://discourse.nodered.org/t/automatic-sprinkler-system/30301/4 "2020-07-19T08:36:07Z")

</div>

Here's an example flow:

```auto
[{"id":"300a494.de2d8b6","type":"totaliser","z":"a9d2ff30.566fd","output":"diff","interval":"24","intervalUnits":"hours","name":"rain 24h","x":380,"y":60,"wires":[["759e1649.e180d8"]]},{"id":"759e1649.e180d8","type":"change","z":"a9d2ff30.566fd","name":"total","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.total","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":390,"y":120,"wires":[["377cda53.066d56"]]},{"id":"377cda53.066d56","type":"debug","z":"a9d2ff30.566fd","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":550,"y":120,"wires":[]},{"id":"38a1987d.4056e8","type":"inject","z":"a9d2ff30.566fd","name":"simulated rain start value 0ml","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"0","payloadType":"num","x":160,"y":60,"wires":[["300a494.de2d8b6"]]},{"id":"d1bc5a19.edf318","type":"inject","z":"a9d2ff30.566fd","name":"simulated rain value 8ml","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"8","payloadType":"num","x":150,"y":120,"wires":[["300a494.de2d8b6"]]}]

```

Note that the totaliser node outputs the `payload.total` value only after the set period is reached so you likely want to change the time frame in the example to for example 10 seconds for testing. I just copied part of my current flow there.

---

<div class="post-metadata">

**Author:** ![Vlak](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/vlak/32/26888_2.png) [@Vlak](https://discourse.nodered.org/u/Vlak)\
**Post date:** [19 July 2020 08:59 UTC](https://discourse.nodered.org/t/automatic-sprinkler-system/30301/5 "2020-07-19T08:59:42Z")

</div>

ok, I don't get this. I cannot read a programming language. can I copy it in the node or how should I see this?

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [19 July 2020 09:03 UTC](https://discourse.nodered.org/t/automatic-sprinkler-system/30301/6 "2020-07-19T09:03:51Z")

</div>

Here is another way to do it.

```auto
[{"id":"dc03d983.08016","type":"inject","z":"2a10ff07.234f98","name":"Start at morning","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":640,"wires":[["a7d099e2.a9ef1","b1f4786b.55af"]]},{"id":"a7d099e2.a9ef1","type":"function","z":"2a10ff07.234f98","name":"Get rain value","func":"msg.payload = 2;\nreturn msg;","outputs":1,"noerr":0,"x":350,"y":640,"wires":[["fe562e34.d05758"]]},{"id":"b1f4786b.55af","type":"delay","z":"2a10ff07.234f98","name":"Delay to afternoon","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":120,"y":690,"wires":[["2f0ca91a.61cd8e"]]},{"id":"fe562e34.d05758","type":"join","z":"2a10ff07.234f98","name":"","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":550,"y":640,"wires":[["92d6d5d5.f38818"]]},{"id":"92d6d5d5.f38818","type":"function","z":"2a10ff07.234f98","name":"Compare","func":"let difference = (msg.payload[1] - msg.payload[0]);\nmsg.payload = difference;\nreturn msg;","outputs":1,"noerr":0,"x":560,"y":690,"wires":[["7f6d53af.f083cc"]]},{"id":"7f6d53af.f083cc","type":"debug","z":"2a10ff07.234f98","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":720,"y":690,"wires":[]},{"id":"2f0ca91a.61cd8e","type":"function","z":"2a10ff07.234f98","name":"Get rain value","func":"msg.payload = 20;\nreturn msg;","outputs":1,"noerr":0,"x":350,"y":690,"wires":[["fe562e34.d05758"]]},{"id":"f136ec43.d281e","type":"comment","z":"2a10ff07.234f98","name":"Read me *","info":"The two `function` nodes are here only to simulate getting the readings.\nYou will have to use your nodes here and the signal is to get the node to send out an output.\nActually you would only need one node. I use two to return two values so as to show how it works.\n","x":350,"y":600,"wires":[]}]

```

You _use_ the code posted by clicking to the left of the area and click on the _clipboard_ icon which will appear.

 ![Screenshot from 2020-07-19 19-08-32](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/4/24c4e94e9a88531b62690c1a74fce56d9cd874ce.png)

Go to your `node-red` edit screen, select `IMPORT` and paste the code there.  
That is the top right corner the _burger_ (menu) button in `Node-Red`.

 ![Screenshot from 2020-07-19 19-05-40](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/4/f470cb4014b05233eb54f3aa0d06f9a3a0295d2c.png)

---

<div class="post-metadata">

**Author:** ![ristomatti](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ristomatti/32/5857_2.png) [@ristomatti](https://discourse.nodered.org/u/ristomatti)\
**Post date:** [19 July 2020 09:17 UTC](https://discourse.nodered.org/t/automatic-sprinkler-system/30301/7 "2020-07-19T09:17:09Z")

</div>

You'll need to copy the code and import from Node-RED menu as explained by @Trying_to_learn. This way you can experiment with it yourself.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [19 July 2020 09:18 UTC](https://discourse.nodered.org/t/automatic-sprinkler-system/30301/8 "2020-07-19T09:18:45Z")

</div>

Sorry dude, I wasn't wanting to mean your way was worse than mine.

Given @Vlak is new, adding more foreign nodes only complicates things. I know my way had a few _tricks_, but I don't think it is/was too hard.

And sorry I didn't actually look at the code you posted. But if you had those nodes needed, I wouldn't have them anyway.

---

<div class="post-metadata">

**Author:** ![ristomatti](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ristomatti/32/5857_2.png) [@ristomatti](https://discourse.nodered.org/u/ristomatti)\
**Post date:** [19 July 2020 09:21 UTC](https://discourse.nodered.org/t/automatic-sprinkler-system/30301/9 "2020-07-19T09:21:01Z")

</div>

I believe contrib nodes have their place. Especially handling dates is somewhat cumbersome in function nodes and at least I would have found using a contrib node easier than a function node of I was new to Node-RED. 🙂

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [19 July 2020 09:22 UTC](https://discourse.nodered.org/t/automatic-sprinkler-system/30301/10 "2020-07-19T09:22:39Z")

</div>

Yeah, fair enough.

Anyway, so long as a working solution is found: that's all that matters, huh?

---

<div class="post-metadata">

**Author:** ![Vlak](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/vlak/32/26888_2.png) [@Vlak](https://discourse.nodered.org/u/Vlak)\
**Post date:** [22 July 2020 19:35 UTC](https://discourse.nodered.org/t/automatic-sprinkler-system/30301/11 "2020-07-22T19:35:00Z")

</div>

ok, thanks guys.  
I think i should be able to deal with this.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [20 September 2020 19:35 UTC](https://discourse.nodered.org/t/automatic-sprinkler-system/30301/12 "2020-09-20T19:35:06Z")

</div>

Closed on 20 September 2020 19:35 UTC

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
