Hi,
I have build a small irrigation system with two ESP32’s controlling eight valves. This works great: flower garden gets watered and my wife is happy - I don’t have to do it and I’m happy.
But, if f there is a network dropout during the watering cycle the valves keep open, which is no good. Im thinking that this is a common problem but searching for fail-safe and similar did not help.
Can anyone point me in the direction of some code that be modified to close the valves when network connection is lost?
What does your current code look like? Are you sending both the on and the off command from HA? If so, maybe change it so that HA sends the on command, and then a timer locally on the esp32 turns it back off?
Thanks for replying. Yes all control is done from HA.
That might be a solution, do you by any chance have any examples or a pointer?
Current code (very rudimentary):
Digging around i came across the api.connected which seem to work. Thanks for the idea!
I added the code below, which turns off the valve when the node looses api connection:
And to be on the safe side I added the following to make sure the relay is off if it instructed to reboot and event more safe by setting on_boot to turn the relay off.
I don’t use ESPHome, but maybe this can help you or someone else. On my irrigation system (consisting of Sonoff 4CH PRO R3) I use ESP Easy and they have the concept of a “pulse” instead of an “on”. So instead of sending an “on” command, I send for example a “30 minute pulse” command. I chose those 30 minutes to be the maximum safe irrigation time. If the network works fine, it will get the “off” command (which clears the pulse) after a few minutes, but if the network drops out it will run the full 30 minutes, which is a bit too long but will do no harm.
Thanks for sharing this! It’s exactly what I have been looking for to prevent my irrigation from running when it shouldn’t, the same problem you needed to fix.