ESP8266 sprinkler controller

A WiFi lawn irrigation controller using an ESP-12F WiFi module to drive up to 4 sprinkler stations.

The sprinkler stations can be controlled and programmed remotely using Home Assistant.

The ESP8266 board communicates with Home Assistant using an MQTT broker on the local WiFi network. The ESP8266 listens to events in order to turn on/off and to program the schedule for each sprinkler station.

The controller is powered by a 9V battery as this is also the voltage required to activate the solenoids for each sprinkler. Being a battery powered device, the efficiency of the circuit is very important. The ESP8266 needs to be in deep sleep as much as possible and only wake up for activating/deactivating sprinkler stations.

There is also an interface mode that can be activated explicitly using Home Assistant. In interface mode, the ESP8266 will not go into deep sleep and is always ready to receive commands to activate/deactivate stations and configure the system. This mode is useful if we need to test a specific sprinkler station or if we need to trigger the stations manually.

The controller is also equipped with a reset button which will force the system to wake up from deep sleep, and go into interface mode (if enabled).

How to configure Home Assistant

The esp8266 sprinkler controller is configured from Home Assistant using MQTT switches and input fields.

As an example, here is my lawn irrigation card within the Home Assistant dashboard. I have three sprinkler stations configured:

Each station is controlled by a different MQTT switch. The switches automatically display the station state and are also used to trigger the stations manually (provided that the controller is in interface mode).

Besides the station controller switches and CRON inputs, there are two additional switches to toggle:

  • the interface mode
  • the irrigation itself.

When the irrigation controller is in interface mode, the ESP8266 will not go into deep sleep and the user can toggle the stations directly.

The irrigation toggle switch can be used to skip the programmed schedule. As an example, it is possible to disable the irrigation if rain is forecast for the next 12 hours or is has rained in the last 12h.

Apart from the switches, Input Text Fields are used to configure the CRON expression and duration for each station. An automation is also required so that an MQTT event is published whenever the text field changes.

If a station is activated due to the configured cron expression schedule, the respective switch will be updated automatically with the current status as an MQTT event is sent from the controller whenever there is a station event.

You can find an example on how to configure these MQTT switches and text fields on the HA examples included in this repository:

Circuit

Power

Because the solenoids that activate the sprinklers require 9V to activate, this circuit is powered by a 9V battery (two 9V batteries in parallel to be precise). A voltage regulator is used to step down from 9v to 5v so that we can power some 5v ICs in the circuit. The ESP-12F requires 3.3V. Therefore, another voltage regulator was added to step down from 5v to 3.3v. This is not ideal, as there are two voltage regulators but in this case we require 3 different voltages and it would not be practical to have multiple batteries for the same circuit.

Latching solenoids and the L293D ICs

There are two L293D ICs in this circuit. These are Quadruple Half-H Drivers that are designed to provide bidirectional drive currents. The L293D is also designed to drive inductive loads such as solenoids and motors. These ICs allow us to drive the 9v power lines to the solenoid with a 3.3v logic signal provided by the ESP8266.
 
A latching solenoid uses an electrical current pulse or internal permanent magnet material to maintain a set position without the constant application of power. Latching solenoids (also known as bistable solenoids)...

Read more »