In ESPHhome I have config to start pumping water into a barrel when empty.
When vlotter1 on, it starts pumping 3 minutes, waits 3, etc.
with this code:
Why don’t you just buy a 10$ float switch? Your making it more complicated than it needs to be with qll these delays and in/off triggers. A simple float switch will turn on a relay and pump when the float drops to a certain level and when it rises back up with the water level, it will shut off the relay switch.
There are multiple issues with your code that you have to solve:
You call a switch.turn_on from within the on_press handler of that same switch, effectively creating a loop that may trigger itself over and over again.
You have implemented 3 minute on/off schedules in two places, acting on the same switch. These schedules can be triggered at the same time and their on and off commands will overlap and interfere in a completely unpredictable way.
I strongly recommend that you move your 3 minute cycle logic to a script component that you can call from wherever it is needed.
The beauty of scripts is that the script.mode parameter allows you to control what will happen if the script is called again while it is still running.
You also have a script.stop method that you can call to break off the execution of the script if needed.