I developed an irrigation controller that suits my needs perfectly. But I don’t want to rely on external scheduling from HA or anywhere else. The controller needs to be completely independent of any other system ( well, except for electricity )
ESPHome has a built-in scheduler that includes cron functionality, however it is baked into the firmware and cannot be modified at runtime. So I created a dynamic cron scheduler class in C++ that can be dropped into any ESPHome project. The scheduler does two things: 1. Determines the next-run-time of your Sprinkler instance, 2. Triggers the run, when that point in time is crossed.
The Croncpp Scheduler for ESPHome includes basic setup instructions and will be kept updated as fixes and improvements are made.
EDIT: See the latest version, an External Component, here: esphome-dynamic-cron
I wrote this class specifically for the Sprinkler component, however it is easily modifiable to work with any ESPHome component. The functionality is unobtrusive and will not alter your ESPHome code.
Some of the features are:
- Automate start times entirely within ESPhome, no home-assistant required.
- Editable cron expressions, no re-flash (or re-boot) required.
- Multiple cron expressions for each Schedule instance.
- Multiple independent Schedule instances handle multiple Sprinkler instances (or whatever you want to schedule on your ESPHome device).
- Remembers missed start times after power failure or reboot.
Here’s my irrigation UI (native ESPHome web UI) showing the essential controls for the scheduler. Notice the lines for “Cron Schedule”, “Next Run”, and “Disable Schedules”. Those are the main controls, and they are simple to integrate with your ESPHome project using switch
, text
, and text_sensor
components.
I know there are other scheduling tools for ESPHome, but I wanted to roll my own to better familiarize myself with the inner-workings of ESPHome. I also wanted to create something that was simple, modular, and usable outside the context of my specific project. I have gained a lot of knowledge from members on this site, so I hope this project can be of use to others as well.
Credit to mariusbancila for the excellent Croncpp library for parsing cron expressions. That’s really where the heavy lifting happens.
EDIT: I have developed an External Component that is based on this class. It gives a simple ESPHome interface for creating dynamic cron schedules that can be edited/updated at run time, without needing to reflash or reboot. Check it out on github: esphome-dynamic-cron