Smart garden irrigation with openHAB

In this article I would like to share my experience on how to realize a smart garden irrigation with openHAB (http://openhab.org).

After a few years living in our smart home, I decided to shut down my home-brew automation server and setup openHAB on my NAS server at home. One of the reasons for this decision was openHAB’s flexible rule engine which makes it very easy to implement even more complex scenarios such as a multi zone and weather dependent garden irrigation.

The EIB (European Installation Bus) installation in our house provides the required functionality to switch the water pump and three independent water circuits. These three circuits supplies the irrigation for our herb garden, our lawn and our bushes. An additional circuit provides water to some “water sockets” well distributed all over the garden for individual irrigation when required. Also an eQ-3 HomeMatic CCU2 is connected to openHAB providing some additional sensors and – important for this scenario – a remote control to switch garden pump and valves manually.

The rules described in the following takes into account, that the different zones have also different requirements on the irrigation time. For the visualization I realized a panel in LiVo offering functionalities to switch the pumps and valves as well as a set of timers to set the individual irrigation time for the different zones.

Irrigation rule items in openHAB

Let’s start with the items first. Below you see the items I defined for my “smart garden irrigation”:

The item Bewaesserung_Pumpe switches the garden pump, while Bewaesserung_Rasen, Bewaesserung_Zaun and Bewaesserung_Gemuese controls the valves for the three different zones. All these items are bound to their corresponding EIB device as the knx-binding shows.

The three “Bewaesserung_*_Restzeit” items are not bound to any device. They are used as global variables to set and track the remaining irrigation time in seconds for the corresponding zones.

Bewaesserung_Sperre is required to stop the irrigation for a day after it occurred on the planned time as described in the rules. Bewaesserung_Manuelle_Sperre is to block the irrigation manually for example if you have a BBQ party (even though this may be a lot of fun, depending on your guests 🙂 ).

Some additional items are required to track the environment state, such as wind speed, rain amount and outdoor temperatures. The item “Regen” is on when the corresponding sensor detects rain. The item “Regen_Tageszaehler” counts the minutes of rain during the day and is reset by a rule every night to zero. The items Min/MaxTemperaturAussen tracks the corresponding daily temperature minimum and maximum, while the item “Wind” stays for the current wind speed. The “Daemmerung” item tracks the current latest light (the higher the value, the darker).

The “Handsender*” items finally represents the status of the HomeMatic remote keys. The first key will be used to switch the garden pump for manual irrigation. A short press of this key turns the pump on while a long press turns it off again.

Features

Lines 1 to 19 of the following rules definition basically initializes all required variables. BEW_Regenschwelle defines the threshold (in minutes) of daily rain after that irrigation is not started for the current day. The variable BEW_Entwaessern marks the point when the valves should be opened to allow water in the pipes to dissipate through the drain valves mounted on different places on the pipes. The “Automatik” variables tracks the current state of the individual zones whether irrigation is started automatically by the rule or manually.

The “BEW_Zeit_*” variables defines how long  (in minutes) the irrigation should take place in the corresponding zone. Some timers are required to drive the draining time and other functions.

The rule starts with a setup of all items and variables when openHAB has been started (lines 21-35). This may not be the best choice and you may prefer to load stored values from openHAB persistence. As persistence is a topic of its own, I wouldn’t stress that too much here.

The rule “Minutenzähler” is called every minute as the cron item describes and increments the “minutes of rain” counter if the rain sensor is active (lines 42-44). Below, depending on the remaining irrigation time, the remaining time is decreased by 60 seconds on every zone (lines 45-93) and the corresponding valve is switched on when irrigation has started and off when the remaining time has decreased to 0. Also note that the “Automatik” variables are set to true in this case as the rule is taking control of the whole irrigation process.

The rule “Temperaturen” (lines 95-105) is taking care of setting the daily max and min temperatures.

All values are reset at the end of the day on lines 107-119.

Remember that I wanted to start irrigation not earlier than 6:00pm. The rule starting on line 121 takes care of unblocking the corresponding item.

I wanted to setup rules that defines the irrigation time for each individual zone depending on the current environment state and the amount of rain already fallen. Depending on the daily temperature maximum the irrigation will take a little longer to compensate for the additional evaporation. The times (in minutes) that you see in the rules below are individual and depends a lot on the water output of the individual irrigation systems, your soil conditions and of course the plants in your garden. This is something that you will have to judge depending on your individual conditions. The corresponding rule starting on line 128 sets these values depending on the daily maximum temperature.

The next rule starting on line 146 is the core of the whole irrigation concept. Irrigation should start at the latest light, it shouldn’t start when a party is ongoing (I omitted this item in the items list above). Of course irrigation shouldn’t start again when it already took place, this is why the “Bewaesserung_Sperre” item is for. Also a minimum daily temperature should have been reached (I set this to 12 degrees celsius). The lawn sprinkler should not be irrigating when the wind speed is so high, that it would basically irrigate the terrace or even the house facade and in general it wouldn’t make sense to irrigate the garden when it is raining or enough rain has fallen during the day. You could imagine way more conditions to drive this rule but believe me, it is already very hard to test as you have to reach or simulate all these conditions and it took me about a week or so to find the right parameters and initialization settings.

The pump is started automatically when one of the valves is opened. The rule on lines 171-186 also tracks if a draining state is reached. In this case the pump is not turned on to allow draining of the whole system.

One hour after the pump has been switched off, the system draining is started (lines 188-225). All valves are opened for a minute to allow the remaining water to drain out of the pipes. The BEW_Entwaessern flag is set to avoid the “pump starting” rule to switch on the pump.

Finally (lines 227-242) the garden pump is automatically switched off after two hours to save energy (it may be someone just forgot to switch it off).

The rules starting on line 244 handle the HomeMatic remote control. This is a particularly nice feature as we normally do not have any switches or an iPhone or iPad to turn on the pump when we are working in the garden. The HomeMatic remote MODELTYPE is very similar to a car key remote, therefore ruggedized for outdoor usage even though you should not forget it outdoors as it is not water resistant.

The visualization

The visualization on an iPhone or iPad is realized with my own app LiVo, which you can get on the Apple app store. Besides the Apple HomeKit, LiVo supports openHAB very well an edit has been improved a lot in the past. The switches are connected to the corresponding items in openHAB as well as the remaining time counters. Irrigation can so be started manually and set to an individual time for each zone. The timer controller widgets used in LiVo shows the remaining time as well as all corresponding conditions.

The openHAB items are visualized and controlled in the LiVo iOS smart home app.

Conclusion

Even though the rule code seems to be very complex it is quite easy to realize even more complex functions with openHAB. Some of the complexity may come through the repetitive rules, depending on the irrigation zone handled.

The openHAB items definition is very powerful also to share information and states among different rules and an external visualization. An item doesn’t have to be bound to a physical sensor or actor which makes it basically a global variable shareable  all across the system. I could have handled the repetitive tasks differently by providing some reusable functions as described in the corresponding article in this blog.

I hope you enjoyed reading, you’re welcome to leave a comment here!

Arno

Rules code

 

One Comment

  1. Super Artikel. Sehr schön beschrieben.