Complete watering system based on openHAB

import org.openhab.core.library.types.*

import org.joda.time.*

Do not include these imports in OH 2.x

You are right but it helps when I develope code in SmartDesigne , without these import it displays errors.

You could use Design Pattern: Cascading Timers to make this part more generic which would make it >easier for other users to adopt.

I’ve almost rewrote whole code to use this pattern, after this change code is shorter about 100 lines but is definitly more complicated to understand and more complicated to debug. My watering installation has only 3 section in my situation what I’ve written is a trade off between flexibility and simplicity of code.
For sure I will put all timers to Map and I will use lambda expression and fix minor bugs. To be honest I’ve made all modification but I have to make final test :slight_smile:

Could use a Timer for this rather than a polling cron trigger.

I thought about Timers, but pooling has some adventages - it is simpler to test.

I would recommend using one of the Weather bindings for this rather than using HTTP directly. Or if it were acquired separately using HTTP, move this to a special weather set of rules so you don’t need to m

Good idea, but I have to check if this bindings offers exactly what I want - I need rainfall for next 24h

It shouldn’t since org.openhab.core.library.types no longer exist. Trying to include it should do nothing. Are you using Eclipse SmartHome Designer 0.8? Furthermore, using * in an import statement will generate a warning both in ESH Designer and in the OH logs.

There is often a trade-off between making code generic which requires the code to become a little more abstract. Abstract does not necessarily mean more complicated, but it is not always as straightforward. However, though it requires a little more work up front to understand, if done right, it becomes much easier to maintain and modify in the future.

You only have three zones but at least where I’ve lived, 5 or more is more typical (I have nine). For this reason, your example becomes much easier to adopt by other users if they can add new zones without needing to modify the rules. And this is primarily why I made the suggestion.

I don’t see Timers as any harder to test than polling.

I know for sure the Wunderground binding does. I beleive most if not all of the other bindings, except for maybe the Yahoo Weather Binding also offer this.

There is often a trade-off between making code generic which requires the code to become a little more >abstract

Yes you are right. For 15 years I was software developers and I know what do you mean.
But in my situation I wrote software for my garden not generic garden :slight_smile: Second, I think we have many users on forum with limited knowledge about programming and they probably do not understand more advanced patterns and they can have problems to adopt code to specific needs. Usually people looking for what is easy to understand and easy use.
Your cascade pattern is more difficult to understand but off course for several section you are right is definitely better.
From my experience I can say that in some situation simpler code is better when you think about maintenance.

I don’t see Timers as any harder to test than polling.

Maybe not harder but simpler for me. During pooling I execute so little code that is also does not generate performance issue and I can exacly change how often my action can be performed.

But still thank you for your help , your advice is very helpful.

Michal

1 Like

True, but you posted it in Tutorials & Examples Solutions which implies you intended this posting to be something that others could take, use, and adopt to their system. With that assumption, I was looking for ways to make a user’s adoption of the the code require less work and less overall understanding. If the user need only copy the rule and create a bunch of Items and Groups it takes even less coding knowledge for them than requiring them to create new global variables and understand all the rules so they know where to copy and paste the right sections of code to add more zones.

But this section of the forum is also for the “I made this” type postings which your posting and I do thank you for contributing.

Except when you violate DRY you end up with a lot more opportunities to mess up when you want to change some behavior, fix a problem, or add more zones because you have to make the same changes in multiple places.

I agree that simpler code is easier to maintain, but I disagree that more abstract code is necessarily more complex in this regard.

1 Like

Dear Mr. Rich Koshak, Good Morning. I request you to publish your method of coding for a similar or a comparable Watering System for me Adapt my needs. I will also learn lot of coding technique from your posting.
Please help us with your for a learner like me.
Thanking you in advance.
With Great Regards,
Ragothaman R

Thank you so much and with Best regards.
Ragothaman R.

BTW includes are not necessary in 2.1 but I have strange behaviour in rule:

It does not work

var tmp= new Date()

it produce such error

2017-11-03 21:26:00.448 [ERROR] [ntime.internal.engine.ExecuteRuleJob] - Error during the execution of rule Watering_algorithm: An error occurred during the script execution: null

It works

var tmp= new java.util.Date()

and it also works

import java.util.Date
var tmp= new Date()

What imports are needed and which are not needed?

Only those imports I highlighted are not needed. I.e. those from org.openhab.core and org.joda. All other imports are required, including those from java.util.

How is it going with this project?
I’m looking for watering system for my house. Valeves are in place. I have older control system but without external connection. Still have few months to next seeson but it would be nice to plan something.

It is not a big project but few rules and items. Simply it works :slight_smile:
Michal

Hi @Michal_Szymanski,

first of all, thank you for posting your project.
I was wondering if you have current version for OH 2.5 which you want to share with us?
Would like to use your code for my garden project.

Regards

Patrick

Hi bellow, most current version.
Sorry but comments are in Polish, without problem you can use google translate to translate to your native language. This version works without problem with 2.5. If you have question to code let me know.

Hi @Michal_Szymanski,

cool thanks for sharing. It drops niw far less errors;)
I have indeed a couple of questions:

  • MinimumReqRainfallCfg -> is this related to the rain sensor? It throws a lot of error messages.
  • sendPushOverMessage & pushoverBuilder -> is there a certain binding needed as it throws errors?
  • Hunter Rain sensor - did you connect it directly to the raspy?

I have no rain sensor at the moment, can i use it without it as well?

Regards

Patrick

Hi @Michal_Szymanski,

cool thanks for sharing. It drops niw far less errors;)

No problem, BTW in source code you will find key to weather forecast service, please do not use it , because it is for my account :slight_smile:

I have indeed a couple of questions:

  • MinimumReqRainfallCfg -> is this related to the rain sensor? It throws a lot of error messages.

I use weather forecast service, simply everyday I make REST call to external service and get rainfall forecast for next 24h. If forecast rainfall is greater than MinimumReqRainfollCfg simply I will not start watering. Value of MinimumReqRainfallCfg is set in GUI, below watering configuration:

  • sendPushOverMessage & pushoverBuilder -> is there a certain binding needed as it throws errors?

exactly it is Action for sending info to smartphone:

  • Hunter Rain sensor - did you connect it directly to the raspy?

no I do not, I’m using MCP2307 input / output extender. You can connect to Rpi directly buy for Rpi safety it is good idea to use something between Rpi and sensor.

I have no rain sensor at the moment, can i use it without it as well?

Of course, rain sensor is only used in two ways, if it is wet it does not start watering if will wet during watering it stops current watering. Simply you can remove lines where I use WtrRainSensor

BTW where are you from ?

Hi @Michal_Szymanski,

thank you for your reply. I’m getting there slowly but steady…
I disabled all relevant rain sensor linesand it looks good for the moment. However the
MinimumReqRainfallCfg is confusing me. It still throws errors.
Please see screenshot

Could you please also share your sitemap file?
I created the rain amount inpout based on your screenshot, but it doesnt look right.

And where is the pushover function sending the messages to? To the OH app on your mobile or
do you need to configure a device accordingly?

Don’t worry, i have deleted the API KEY;)

I’m from Germany.

Regards

Patrick

This problem is solved, i deleted for some reason the MinimumReqRainfallCfg item in the itmes file.

But it is a message from your IDE, have you seen such message in openHab?

I use pushover to send message to my smartphone (you need to install pushover software on your mobilephoine).

Configuration

	/* Konfiguracja systemu  */
	Text label="Konfiguracja" icon="settings" {
		
		Text label="Systemu podlewania" icon="water" {
		
 			Frame label="Czas podlewania" {
	 			Setpoint item=WtrDurationFront  label="Przed domnem" minValue=1 maxValue=40 step=1
	 			Setpoint item=WtrDurationBack   label="Za domem" minValue=1 maxValue=40 step=1
	 			Setpoint item=WtrDurationLine   label="Linia kroplujaca" minValue=1 maxValue=40 step=5
	 			Setpoint item=WtrScaleFactor    label="Korekta" minValue=1 maxValue=100 step=1
	 			
 			}
			
		
 			Frame label="Pozostale parametry" {
	 			Setpoint item=MinimumReqRainfallCfg     label="Min.wymagana ilość opadow"	minValue=1 maxValue=20 step=1
			 	Selection item=WtrStartTime mappings=["00:00"="00:00", "01:00"="01:00", "02:00"="02:00",
 				                                  "03:00"="03:00", "04:00"="04:00", "05:00"="05:00", 
 				                                  "06:00"="06:00", "07:00"="07:00", "08:00"="08:00",
 				                                  "09:00"="09:00", "10:00"="10:00", "11:00"="11:00", 
 				                                  "12:00"="12:00", "13:00"="13:00", "14:00"="14:00",
 				                                  "15:00"="15:00", "16:00"="16:00", "17:00"="17:00",
 				                                  "18:00"="18:00", "19:00"="19:00", "20:00"="20:00", 
 				                                  "21:00"="21:00", "22:00"="22:00", "23:00"="23:00"
 			]
 			}
			
		}

and

   Text label="Podlewanie" icon="water" {
		Frame label="Podlewanie sekcji" {
			Switch item=WtrValveFront label="Przod"   mappings=[OFF="Wł", ON="Wył"] 
			Switch item=WtrValveBack  label="Tyl"     mappings=[OFF="Wł", ON="Wył"] 
			Switch item=WtrValveLine  label="Linia"   mappings=[OFF="Wł", ON="Wył"] 
		}
		
		Frame label="Status" {
			Text item=WtrRainSensor 
			
			// czy wlaczona automatyka
			Text item=WtrAuto 
			
			// prognoza ilosci opadow
			Text item=WtrRainfallForecast
			
			// data kiedy byla pozyskana prognoza
			Text item=WtrRainfallForecastDate
			
			// data podlania / sprawdzania czy bylo 'mokro'
			Text item=WtrLastDate
	
		}	
	}

Hi Michal,

thanks for your reply, i have managed to tweak the rules with “virtual switches” as i have no IO input. For the time being it looks like it 's working somehow.

I have three questions:

  • why are you using var OnOffType ON_R & var OnOffType OFF_R. I think this avoids my system to manually stop the irrigation system.

  • Is t normal that the irrigation rule is starting the watering every hour? I thought it is supposed to do it only once a day?

  • The item “WtrStartBtn”, is it in connect to a physical switch or a button. I mean here how the signal is created. Is the state either closed or open, or do you just close the circuit when hitting it?

BTW: i have changed the code for Telegram as push service, as i use the app on a daily basis.

Regards

Patrick

Hi Michał,
Bellow? You mean where? I can find only new sitemap.
Pozdrawiam
Marcin