# Greenhouse irrigation

**URL:** https://discourse.nodered.org/t/greenhouse-irrigation/965
**Category:** Share Your Projects
**Created:** [20 June 2018 19:15 UTC](https://discourse.nodered.org/t/greenhouse-irrigation/965 "2018-06-20T19:15:17Z")
**Posts on this page:** 20
**Page:** 6

<div class="post-metadata">

### Author: ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)
#### Post date: [16 April 2019 19:12 UTC](https://discourse.nodered.org/t/greenhouse-irrigation/965/101 "2019-04-16T19:12:00Z")

</div>

> [@nassima100](#):
>
> My question is: if I get a result of let's say 0.35 for example, how can I determine the time of watering based on that ?

Use a range node to scale it up.

![scale](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/d/da33dd5b29add0ad6bce26ee99e7ee32b664b80d.jpeg)

---

<div class="post-metadata">

### Author: ![nassima100](https://avatars.discourse-cdn.com/v4/letter/n/e5b9ba/32.png) [@nassima100](https://discourse.nodered.org/u/nassima100)
#### Post date: [16 April 2019 19:17 UTC](https://discourse.nodered.org/t/greenhouse-irrigation/965/102 "2019-04-16T19:17:41Z")

</div>

150 seconds ? I'm sorry 🥺 I just don't understand what the output of the PID node refers to

---

<div class="post-metadata">

### Author: ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)
#### Post date: [16 April 2019 19:23 UTC](https://discourse.nodered.org/t/greenhouse-irrigation/965/103 "2019-04-16T19:23:37Z")

</div>

> [@nassima100](#):
>
> I just don't understand what the output of the PID node refers to

It's the number of seconds that the pump would be activated for.  
...or should I say the number of seconds that should elapse before switching the pump off.

More seconds = more water!

So if your PID outputted 1, that would be scaled up to 150, which in turn would activate the water pump for 150 seconds.

---

<div class="post-metadata">

### Author: ![nassima100](https://avatars.discourse-cdn.com/v4/letter/n/e5b9ba/32.png) [@nassima100](https://discourse.nodered.org/u/nassima100)
#### Post date: [16 April 2019 19:27 UTC](https://discourse.nodered.org/t/greenhouse-irrigation/965/104 "2019-04-16T19:27:07Z")

</div>

Is the scaling based on you personal choice, based on your experience or on a reference ? Thanks in a advance

---

<div class="post-metadata">

### Author: ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)
#### Post date: [16 April 2019 19:32 UTC](https://discourse.nodered.org/t/greenhouse-irrigation/965/105 "2019-04-16T19:32:56Z")

</div>

> [@nassima100](#):
>
> Is the scaling based on you personal choice, based on your experience or on a reference ?

Trial & error!! it depends upon what rate you are delivering water, the type of soil etc.  
I started with minimal water delivery and gradually increased until I was happy that the PID could gain control, and maintain the moisture level that I wanted.

---

<div class="post-metadata">

### Author: ![nassima100](https://avatars.discourse-cdn.com/v4/letter/n/e5b9ba/32.png) [@nassima100](https://discourse.nodered.org/u/nassima100)
#### Post date: [16 April 2019 19:33 UTC](https://discourse.nodered.org/t/greenhouse-irrigation/965/106 "2019-04-16T19:33:44Z")

</div>

All right, Thank you very much!!

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [16 April 2019 21:01 UTC](https://discourse.nodered.org/t/greenhouse-irrigation/965/107 "2019-04-16T21:01:06Z")

</div>

In fact my suggestion is to use node-red-contrib-pid as you originally suggested. If you feed the output of the PID into that then it will generate an on/off time proportioned signal (effectively a very slow PWM) which you can use to control the water valve. So if for example the pid asks for 25% (actually 0.25) then it will switch the relay on for 25% of the time and off for 75% of the time, with the cycle time as set in the timeprop node. So if the max flow rate is set to that which is required in the worst case then it should do the job. Alternatively if you think you will never want the valve on for more than, say, 10% of the time you can use a Range node to convert the pid 0:1 to the range 0:0.1 and feed that into the timeprop node.

---

<div class="post-metadata">

### Author: ![nassima100](https://avatars.discourse-cdn.com/v4/letter/n/e5b9ba/32.png) [@nassima100](https://discourse.nodered.org/u/nassima100)
#### Post date: [17 April 2019 21:05 UTC](https://discourse.nodered.org/t/greenhouse-irrigation/965/108 "2019-04-17T21:05:37Z")

</div>

That makes a lot of sense, thank you !

---

<div class="post-metadata">

### Author: ![SuperNinja](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/superninja/32/5761_2.png) [@SuperNinja](https://discourse.nodered.org/u/SuperNinja)
#### Post date: [20 April 2019 21:06 UTC](https://discourse.nodered.org/t/greenhouse-irrigation/965/109 "2019-04-20T21:06:27Z")

</div>

more expensive but perhaps better acurate : [sht sensor for soil humidity](https://www.aliexpress.com/item/cable-length-OEM-SHT10-SHT11-SHT15-SHT20-SHT21-SHT25-IIC-interface-Soil-temperature-and-humidity-sensor/32828229124.html?spm=a2g0s.8937460.0.0.2e7c2e0eqpur0J)

What do you think about it ?

---

<div class="post-metadata">

### Author: ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)
#### Post date: [20 April 2019 21:35 UTC](https://discourse.nodered.org/t/greenhouse-irrigation/965/110 "2019-04-20T21:35:37Z")

</div>

I'm not that familiar with those devices, but a quick google search suggests that they aren't intended for long term exposure to submersion/high humidity conditions.  
It appears to be a SHTx sensor mounted in a fine metal mesh, intended to allow air to blow through, but fine enough to prevent short term water ingress.

Paul

---

<div class="post-metadata">

### Author: ![nassima100](https://avatars.discourse-cdn.com/v4/letter/n/e5b9ba/32.png) [@nassima100](https://discourse.nodered.org/u/nassima100)
#### Post date: [19 May 2019 23:09 UTC](https://discourse.nodered.org/t/greenhouse-irrigation/965/111 "2019-05-19T23:09:58Z")

</div>

Hi Paul, did you use`node-red-node-smooth` or the RC filter function in @Colin's flow or something else ?

---

<div class="post-metadata">

### Author: ![sakura](https://avatars.discourse-cdn.com/v4/letter/s/898d66/32.png) [@sakura](https://discourse.nodered.org/u/sakura)
#### Post date: [20 May 2019 00:00 UTC](https://discourse.nodered.org/t/greenhouse-irrigation/965/112 "2019-05-20T00:00:36Z")

</div>

Hello guys, I recently bought a capacitive soil moisture sensor , but I just can't calibrate it, I tried to take analog values when it is dry (0) and when it is dipped in water (100) but it didn't turn out accurate, also I have another question, as in @Colin's blog in order to obtain the time at which the first peak occurs you have to start out from 0, does that mean that I have to put the sensor in a very dry soil as a start ?

---

<div class="post-metadata">

### Author: ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)
#### Post date: [20 May 2019 00:51 UTC](https://discourse.nodered.org/t/greenhouse-irrigation/965/113 "2019-05-20T00:51:12Z")

</div>

@nassima100 I've used Colin's RC filter, as I want the most recent readings to have a greater impact on the readings (because the soil will be progressively getting moister).

---

<div class="post-metadata">

### Author: ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)
#### Post date: [20 May 2019 00:58 UTC](https://discourse.nodered.org/t/greenhouse-irrigation/965/114 "2019-05-20T00:58:11Z")

</div>

@sakura instead, try measuring soil samples of the extremes of the expected soil humidity.  
For example, the soil humidity when a plant would be wilting through dryness, and another when the soil has been saturated and allowed to drain a while.  
Once you get those two readings, use a range node to scale it 0 to 100 ( or 100 to 0 depending upon your process).

---

<div class="post-metadata">

### Author: ![sakura](https://avatars.discourse-cdn.com/v4/letter/s/898d66/32.png) [@sakura](https://discourse.nodered.org/u/sakura)
#### Post date: [20 May 2019 21:51 UTC](https://discourse.nodered.org/t/greenhouse-irrigation/965/115 "2019-05-20T21:51:01Z")

</div>

I willl, thank you.

---

<div class="post-metadata">

### Author: ![ima](https://avatars.discourse-cdn.com/v4/letter/i/67e7ee/32.png) [@ima](https://discourse.nodered.org/u/ima)
#### Post date: [20 May 2019 22:05 UTC](https://discourse.nodered.org/t/greenhouse-irrigation/965/116 "2019-05-20T22:05:49Z")

</div>

hello @Paul-Reed i'm working on somthing similar to yours and using the same hardware,would you please share your flow with us ...thanke you

---

<div class="post-metadata">

### Author: ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)
#### Post date: [21 May 2019 01:33 UTC](https://discourse.nodered.org/t/greenhouse-irrigation/965/117 "2019-05-21T01:33:51Z")

</div>

@ima The flow would not really help you as it's closely tied into the ESP firmware.  
For example; the ESP via MQTT tells node-RED what the soil humidity is, and node-RED calculates and tells the ESP how much water to administer.

So one won't work without the other, and you would need the ESP hardware & firmware for the flow to run.

---

<div class="post-metadata">

### Author: ![nassima100](https://avatars.discourse-cdn.com/v4/letter/n/e5b9ba/32.png) [@nassima100](https://discourse.nodered.org/u/nassima100)
#### Post date: [21 May 2019 01:39 UTC](https://discourse.nodered.org/t/greenhouse-irrigation/965/118 "2019-05-21T01:39:19Z")

</div>

I honestly didn't understand how his RC filter works, I tried to debug it and it only gives me bigger and bigger values each time, I think it is for simulation sake but how to make it filter real sensor's values and return logical values according to that?

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [22 May 2019 19:18 UTC](https://discourse.nodered.org/t/greenhouse-irrigation/965/119 "2019-05-22T19:18:09Z")

</div>

> [@nassima100](#):
>
> I honestly didn't understand how his RC filter works

Which one do you mean? Post a small flow showing the problem.

---

<div class="post-metadata">

### Author: ![nassima100](https://avatars.discourse-cdn.com/v4/letter/n/e5b9ba/32.png) [@nassima100](https://discourse.nodered.org/u/nassima100)
#### Post date: [24 May 2019 10:36 UTC](https://discourse.nodered.org/t/greenhouse-irrigation/965/120 "2019-05-24T10:36:32Z")

</div>

I'm talking about these two nodes:

```auto
[{"id":"582764f9.714ecc","type":"function","z":"2aaf6568.86263a","name":"10 sec RC","func":"// Applies a simple RC low pass filter to incoming payload values\nvar tc = 10*1000; // time constant in milliseconds\n\nvar lastValue = context.get('lastValue');\nif (typeof lastValue == \"undefined\") lastValue = msg.payload;\nvar lastTime = context.get('lastTime') || null;\nvar now = new Date();\nvar currentValue = msg.payload;\nif (lastTime === null) {\n // first time through\n newValue = currentValue;\n} else {\n var dt = now - lastTime;\n var newValue;\n \n if (dt > 0) {\n var dtotc = dt / tc;\n newValue = lastValue * (1 - dtotc) + currentValue * dtotc;\n } else {\n // no time has elapsed leave output the same as last time\n newValue = lastValue;\n }\n}\ncontext.set('lastValue', newValue);\ncontext.set('lastTime', now);\n\nmsg.payload = newValue;\nreturn msg;","outputs":1,"noerr":0,"x":501.5,"y":2815,"wires":[["43a52c92.e81ba4","3ca8f1a3.f9029e"]]}]

```

```auto
[{"id":"43a52c92.e81ba4","type":"function","z":"2aaf6568.86263a","name":"30 sec RC + 20","func":"// Applies a simple RC low pass filter to incoming payload values\nvar tc = 30*1000; // time constant in milliseconds\n\nvar lastValue = context.get('lastValue');\nif (typeof lastValue == \"undefined\") lastValue = msg.payload;\nvar lastTime = context.get('lastTime') || null;\nvar now = new Date();\nvar currentValue = msg.payload;\nif (lastTime === null) {\n // first time through\n newValue = currentValue;\n} else {\n var dt = now - lastTime;\n var newValue;\n \n if (dt > 0) {\n var dtotc = dt / tc;\n newValue = lastValue * (1 - dtotc) + currentValue * dtotc;\n } else {\n // no time has elapsed leave output the same as last time\n newValue = lastValue;\n }\n}\ncontext.set('lastValue', newValue);\ncontext.set('lastTime', now);\n\nmsg.payload = newValue + 20;\nreturn msg;","outputs":1,"noerr":0,"x":677,"y":2815,"wires":[["2ab907f7.bc74c8","8439448e.1a4318"]]}]

```

[Previous page](https://discourse.nodered.org/t/greenhouse-irrigation/965.md?page=5)

[Next page](https://discourse.nodered.org/t/greenhouse-irrigation/965.md?page=7)
