Objective

My significant other comes from a family of expert gardeners, so expectations are quite high when it comes to the appearance of the lawn :) Luckily, I also helped out in the family business before my current job, so I know that it’s the drought that weakens the grass enough to make it easier for weeds to take hold.

Our garden is equipped with an irrigation system and an 8 cubic metre rainwater tank. As this is quite small, the irrigation schedule has to be smart enough to save as much water as possible. A static schedule is not an option as it does not take into account past and future rainfall. Why water if it rained the day before?

The first and, for me at least, ideal approach would be to measure the soil moisture. I did this with a DIY device using an ESP8266 NodeMCU module and a generic moisture sensor “capacitive soil moisture sensor v1.2”, which can be obtained from Aliexpress for a few euros. It turns out that electronic devices do not tolerate the constant presence of moisture very well. Who would have thought. I have given up on this approach, but I still think it is the best approach, because I would only really water when the soil moisture level drops below a certain level. Maybe it is feasible anyway with a more expensive device.

In the end, I decided to develop an automated system that determines the need for watering based on the amount of rainfall, the weather forecast and the air temperature.

Hardware

The valves of the irrigation system are controlled by OpenSprinkler. It allows the connection of 8 branches and quite a lot of other functionality that I have never really used. Although the whole irrigation system is from Rain Bird, I did not opt for their controller because of the poor support for external systems such as Home Assistant. In this case, integration would have been done via their cloud service. I am trying to avoid dependency on external services, so I have opted for OpenSprinkler, which allows local control via Home Assistant.

Home Assistant Integration

The integration is done via a built-in integration in Home Assistant and communicates with OpenSprinkler via a local API.

However, since the watering logic needs historical weather and forecast data, I used the integration with OpenWeatherMap, which provides current weather and forecast data. In the future I will probably purchase a weather station and implement automation logic below using my own data.

Automation Logic

Conditions that suggest the need for watering are:

  • the average temperature over the last 4 days is above 20°C. This limits watering to the hottest days.
  • less than 3 mm of rain has fallen in the last 4 days. 1 mm of rain is equivalent to 1 litre per square metre.
  • The irrigation system has irrigated for less than 15 minutes in the last 4 days. This condition prevents watering more frequently than every 4 days.

The conditions are checked every day at 6:00. If all the above conditions are true and rain is not forecasted for that day, then watering of the lawn for 25 minutes will be initiated.

The most challenging part of implementing the above was formatting the data into the appropriate format.

For example, OpenWeatherMap records rainfall in units of mm per hour, representing the intensity of the rain, but I needed the total amount of rain that fell.

The amount of rain fall is represented by the area of the graph above. I used the Riemann sum available in Home Assistant’s Helpers to calculate this. The result is the total amount of rain that has fallen, and it increases towards infinity each time it rains.

Since the total rainfall doesn’t tell us much, we need to extract the statistics for 4 days from this metric. All we need is the difference between the value 4 days ago and now. Home Assistant allows you to calculate this statistic, that’s what it looks like for me:

1
2
3
4
5
6
7
sensor:
- platform: statistics
  name: "Rainfall 4d"
  entity_id: sensor.total_rainfall
  state_characteristic: change
  max_age:
    hours: 96

The above setting takes the total value “total_rainfall” and makes a new sensor that measures the rainfall only in the last 4 days:

During development, I also made the dashboard below, which I use to monitor if all the input data makes sense: