Complete watering system based on openHAB

As you see you have different now and userTime, question why. In code I check:
if ( ( ( userStartTime.getHourOfDay == now.getHourOfDay() && userStartTime.getMinuteOfHour() == now.getMinuteOfHour() ) || checkUserStartTime == false )
&& WtrAuto.state == CLOSED && (isWatering == false)

Can you show me this line in your code?

Thank you first of all!

Please see below:
if ( (( userStartTime.getHourOfDay == now.getHourOfDay() && userStartTime.getMinuteOfHour() == now.getMinuteOfHour() ) || checkUserStartTime == false )
&& WtrAuto.state == CLOSED && (isWatering == false))

Its the same trigger.

For the tests change to

if ( userStartTime.getHourOfDay == now.getHourOfDay() && userStartTime.getMinuteOfHour() == now.getMinuteOfHour() )

rest of the comparison is not so important for you (it is e.g physical button to switch on automatic watering)

@Michal_Szymanski could you please verify if openweathermap is providing information about rain?
I can see in your log “Wtr_algorithm: Cannot find rain section - rainfallMm is 0mm”
Same in my log for WrocƂaw, however on webpage i can see “light rain” information for tomorrow.

Wtr_algorithm: forecastJson[{"cod":"200","message":0,"cnt":8,"list":[{"dt":1594242000,"main":{"temp":12.71,"feels_like":11.71,"temp_min":11.34,"temp_max":12.71,"pressure":1017,"sea_level":1017,"grnd_level":1003,"humidity":93,"temp_kf":1.37},"weather":[{"id":803,"main":"Clouds","description":"broken clouds","icon":"04n"}],"clouds":{"all":84},"wind":{"speed":2.15,"deg":248},"sys":{"pod":"n"},"dt_txt":"2020-07-08 21:00:00"},{"dt":1594252800,"main":{"temp":11.41,"feels_like":9.98,"temp_min":10.69,"temp_max":11.41,"pressure":1018,"sea_level":1018,"grnd_level":1004,"humidity":94,"temp_kf":0.72},"weather":[{"id":803,"main":"Clouds","description":"broken clouds","icon":"04n"}],"clouds":{"all":73},"wind":{"speed":2.3,"deg":247},"sys":{"pod":"n"},"dt_txt":"2020-07-09 00:00:00"},{"dt":1594263600,"main":{"temp":10.38,"feels_like":8.75,"temp_min":10.13,"temp_max":10.38,"pressure":1018,"sea_level":1018,"grnd_level":1004,"humidity":94,"temp_kf":0.25},"weather":[{"id":804,"main":"Clouds","description":"overcast clouds","icon":"04d"}],"clouds":{"all":90},"wind":{"speed":2.18,"deg":251},"sys":{"pod":"d"},"dt_txt":"2020-07-09 03:00:00"},{"dt":1594274400,"main":{"temp":14.48,"feels_like":13.97,"temp_min":14.48,"temp_max":14.48,"pressure":1018,"sea_level":1018,"grnd_level":1004,"humidity":82,"temp_kf":0},"weather":[{"id":803,"main":"Clouds","description":"broken clouds","icon":"04d"}],"clouds":{"all":70},"wind":{"speed":1.38,"deg":239},"sys":{"pod":"d"},"dt_txt":"2020-07-09 06:00:00"},{"dt":1594285200,"main":{"temp":18.73,"feels_like":17.5,"temp_min":18.73,"temp_max":18.73,"pressure":1018,"sea_level":1018,"grnd_level":1004,"humidity":66,"temp_kf":0},"weather":[{"id":802,"main":"Clouds","description":"scattered clouds","icon":"03d"}],"clouds":{"all":48},"wind":{"speed":2.75,"deg":182},"sys":{"pod":"d"},"dt_txt":"2020-07-09 09:00:00"},{"dt":1594296000,"main":{"temp":18.02,"feels_like":17.29,"temp_min":18.02,"temp_max":18.02,"pressure":1017,"sea_level":1017,"grnd_level":1003,"humidity":74,"temp_kf":0},"weather":[{"id":803,"main":"Clouds","description":"broken clouds","icon":"04d"}],"clouds":{"all":73},"wind":{"speed":2.52,"deg":201},"sys":{"pod":"d"},"dt_txt":"2020-07-09 12:00:00"},{"dt":1594306800,"main":{"temp":21.07,"feels_like":18.55,"temp_min":21.07,"temp_max":21.07,"pressure":1015,"sea_level":1015,"grnd_level":1001,"humidity":67,"temp_kf":0},"weather":[{"id":804,"main":"Clouds","description":"overcast clouds","icon":"04d"}],"clouds":{"all":87},"wind":{"speed":5.75,"deg":228},"sys":{"pod":"d"},"dt_txt":"2020-07-09 15:00:00"},{"dt":1594317600,"main":{"temp":19.12,"feels_like":19.13,"temp_min":19.12,"temp_max":19.12,"pressure":1013,"sea_level":1013,"grnd_level":999,"humidity":81,"temp_kf":0},"weather":[{"id":804,"main":"Clouds","description":"overcast clouds","icon":"04d"}],"clouds":{"all":89},"wind":{"speed":2.7,"deg":221},"sys":{"pod":"d"},"dt_txt":"2020-07-09 18:00:00"}],"city":{"id":3081368,"name":"WrocƂaw","coord":{"lat":51.1,"lon":17.0333},"country":"PL","timezone":7200,"sunrise":1594176421,"sunset":1594235193}}]

Could you please also share with us “rainvalues.js” file?

Well I do not remember what is meaning of rainvalues but as I remember it is name file that is used to transform forecastJson variable.
Openwheathermap provide info about rainfall - it is why I use it :slight_smile:
“Wtr_algorithm: Cannot find rain section - rainfallMm is 0mm” is displayed when there is a problem to connect to openwheather - sometimes it happen, in such situation I assume that rainfall=0.

Thank you, I’m almost there :slight_smile:
I can steer valves connected to sonoff 4ch pro (tasmota onboard) over MQTT.
@Michal_Szymanski could you please share your transformation file “rainvalues.js”?

Bellow rainfall transformation script, I’ve forget that script exists :slight_smile:

(function(datastring) {
    var data = JSON.parse(datastring);
    var listValues = data.list;
    var text = "";
    var i;
    for (i = 0; i < listValues.length; i++) {
        if (listValues[i].hasOwnProperty('rain')) {
            if (listValues[i].rain['3h'] !== undefined) {
                text = text + listValues[i].rain['3h'].toString() + ",";
            }
        }
    }
    text = text.substring(0, text.length-1);
    return text;
})(input)

Is this file to be placed in the “transform” folder?

EDIT: yes it is to be placed there. Now the algorithm can properly extract the rain data.

Hi All,

the system is working quite well for the last couple of days. However if saw that last night, the irrigation part reset itself. Now the default value for the starting time and the duration of the individual watering lines have been set to the defaults in the code.
Anyone seing the same?

Probably it is not a problem of openhab but Rpi, check in the openhab log what did happen .
By the way problem of keeping a state after reset is a typical problem, you can try use MapDB for persistence. You will find info about it in openhab documentation.
When you use it you define special file what look like this

Strategies {
        default = everyChange
}
Items { 
        MainWaterValve          : strategy = everyChange, restoreOnStartup
        FlAlarmLED              : strategy = everyChange, restoreOnStartup
        FlAlarmUpperBathroom_L  : strategy = everyChange, restoreOnStartup
        FlAlarmLowerBathroom_L  : strategy = everyChange, restoreOnStartup
        FlAlarmCupboard_L       : strategy = everyChange, restoreOnStartup
        FlAlarmKitchen_L        : strategy = everyChange, restoreOnStartup
       -----

Oh cool. Thank you!

Has anyone worked on any duration algorithms to adjust the Scale Factor based on past and future conditions.

For instance say its forecasted to be 30C+ you could set watering scale factor to 150% but if its going to be cloudy and 20C maybe only run water for 70%

Just looking to see if anyone has anything built as a baseline i can work off of :slight_smile:

I am not sure if the temperature-dependent watering time approach is correct from a natural point of view
The purpose of (grass) watering is to reach the roots and it should continue until the soil near the grass roots (15-20 cm) is irrigated. Time depends mainly on the type of soil and the efficiency of the nozzle, and we regulate the frequency of irrigation

Of course, I assume that you do not water during the sun / heat because then the poured water evaporates quickly

Judge, a much better approach is the Soil Moisture Sensor served by OpenHab rules :slight_smile:

I think it is good idea to measure soil moisture. Some time ago I developed such sensor and I’ve made integration with openHab but still is uder testing.

I am currenlty testing capactive soil moisture sensor with OH2 . I have a cheap sensor (~ 2 EUR) so not sure about its durability when I buried it in the lawn. I may need to buy something better


Second challange is to determine percentage (or voltage) at which soil is wet/dray. Such such a threshold triggers my irrigation rule.

I did this years ago calculating envirotranspiration rates and am quite happy with it. Best accuracy would be using readings from an on site weather station of course.
Link to the post:
https://groups.google.com/g/openhab/c/kS-gfOkBqfI/m/_ZJ22uY2g80J

Did used soil moisture sensors in the past but I live in an area with frequent lightning from thunderstorms and found any sensor stuck in the ground got fried pretty quick. And you only get accurate results if you calibrate them properly (oven dry method is one way) and you have set an accurate threshold.
If you want to try this route, I went through many different inexpensive ones, really liked the vegitronix (https://www.vegetronix.com/Products/VH400/). Be careful of the capacitive ones, unless they are operating on AC current, DC ones tend to corrode quickly.
Tried various lightning suppression techniques too, but ran out of time and money, when really the envirotranspiration rate gave me good results.

Does this calculation still work for you in OH2.X?
It appears to lock up for a few mins during the calculation and then errors out

EDIT:
It appears the “var irl” calculation is causing issues. I simplified the calculation and it looks like the Math::cos is broken?

Rule:
var irl_1 = Math::cos(((2 * 3.14159265) / 365)*235)
logInfo(filename+“.ETo”, “–> irl_1: " + irl_1 +”.")

Output:
2020-08-22 01:28:01.666 [INFO ] [me.model.script.Hargreaves.rules.ETo] - → irl_1: -0.6186714068941486.

But if i do the same calculation on a scientific calculator i get:

image
image

@g_g_rich that looks interesting, thank you. Can you please advise what device you used to connect the sensors into OpenHAB? Did you custom build something, or did you use an “out of box” solution?

No, it’s running on an old system running 1.8.
I’ll try it on my 2.5 version.
edit. Tried it, yes, seems to hang up quite a lot! I’ll play around with it see what I can come up with.

I used a custom 1-wire board based on a ds2438 chip. Buried it and it gave me soil temp too.