The purpose is to control irrigation in the kitchen garden automatically in Home Assistant based on expected rainfall and measured soil moisture. Irrigation is only started when the total rainfall from the previous and the current day is below a defined threshold and the soil is at the same time drier than a defined threshold. This avoids unnecessary and costly watering while ensuring that the plants receive sufficient water.
The solution is based on rain forecasts supplemented by a soil moisture sensor. The rain forecast makes it possible to control irrigation proactively based on expected rainfall, while the soil moisture sensor ensures that watering only takes place when the soil is actually dry. The entire setup is managed within Home Assistant.
The irrigation is based on a Sonoff Zigbee Water Valve, which is integrated via ZHA. The device is easy to use and can be controlled directly as a standard switch in Home Assistant.
Soil moisture is measured with a ThirdReality Smart Soil Moisture Sensor Gen2, a capacitive Zigbee sensor that, like the valve, is integrated via ZHA. The sensor is placed in the root zone, and its reading is calibrated to the specific soil so that a moisture threshold is set, below which irrigation is triggered.
Failsafe during automatic irrigation
During automatic irrigation there is a risk that the valve could remain open if the Zigbee connection or Home Assistant is interrupted while watering is in progress.
To handle this, a built-in Zigbee function (cluster 6) is used, where the valve opens and at the same time receives a predefined closing time. The valve then closes itself again without further communication.
Timed off is activated via a ZHA cluster command with a duration of 2100 seconds (35 minutes).
Automatic irrigation and duration
Automatic irrigation in the kitchen garden is controlled via a daily automation that starts watering when the conditions are met. Both a normal stop after 30 minutes and a timed off of 35 minutes are used as a failsafe, so that the failsafe only intervenes if the normal stop fails.
The irrigation duration is set to 30 minutes based on a simple measurement of water output. The system delivers approximately 10 liters per minute, resulting in around 300 liters over 30 minutes. Distributed over an area of 150 m², this corresponds to approximately 2 mm of rainfall. This amount has been chosen to provide sufficient water without overconsumption.
By defining irrigation as a known quantity in millimeters, it can be directly compared with the rain forecast, which is also expressed in millimeters. This allows the same unit to be used as the basis for irrigation decisions in the kitchen garden.
Control based on rain forecasts and soil moisture
The forecast component is based on OpenWeatherMap One Call 3.0, where an hourly precipitation forecast is retrieved in Home Assistant. From this, a total rainfall amount for the next 24 hours is calculated. OpenWeatherMap One Call 3.0 can be used free of charge if the daily number of API calls remains below 1000.
Every evening at 23:55, OpenWeatherMap’s rainfall value for the previous day is stored and used as “previous rain”. After midnight, a new 24-hour forecast is retrieved and used as “today’s rain”. Both are forecast-based values from OpenWeatherMap.
The total rainfall amount is calculated as the sum of these two values. Irrigation is started only if the total amount is below the defined threshold and the soil moisture is at the same time below its threshold. If the weather is dry but the soil is still moist, irrigation is skipped.
The setup provides a unified control system where irrigation in the kitchen garden is continuously adjusted based on expected rainfall and measured soil moisture, and executed with a built-in failsafe. The solution is implemented directly in Home Assistant.
Frost
The irrigation of the kitchen garden takes place during the growing season when there is no frost. In case of risk of frost, the Sonoff irrigation unit must be removed, and the garden water system must be drained. The draining is carried out using a 3/4″ bicycle pump valve with a cap, installed in the water system by the house.
About coding
This case describes the architecture and control principles, but not the specific Home Assistant automations. The code will depend on the individual installation. Automations can be generated using AI, provided the AI is given the necessary technical context as described above.

