Pump relay on an ESP32 clicks at boot and the board switch says On when it isn’t
Irrigation pump on a small farm, switched by an ESP32 through one of those blue 5 V relay modules (optocoupler, JD-VCC jumper). The ESP32 listens on v1/rpc/req/+ for pump.set with {"on": true|false} and answers on v1/rpc/res/{id}. On the board I put a Switch card that sends pump.set.
Two problems:
- Every time the ESP32 boots (power blip, or after a firmware update) the relay clicks on for about half a second. The pump contactor pulls in briefly. Not great.
- Yesterday the ESP32 was offline (Wi-Fi down at the shed), somebody flipped the switch on the board, and it showed “On” for a moment. The operator assumed the pump was running.
Relay input is on GPIO 2. Module powered from the ESP32’s 5 V pin (USB supply).
GPIO 2 is a boot strapping pin, it toggles during boot. That’s probably your click.
Ah. Any pin that stays quiet at boot?
I did the same pump setup for a uni project, both issues bit me.
Relay: move it to GPIO 26 or 27, they stay quiet through boot. Most of these blue modules are active LOW, so set the level before switching the pin to output, otherwise you get a short pulse anyway:
digitalWrite(26, HIGH); // relay off for an active-low module
pinMode(26, OUTPUT);
Also take the JD-VCC jumper off and feed the relay coil from its own 5 V, keep only VCC/IN/GND from the ESP. A coil on the ESP’s USB 5 V can brown it out when it pulls in.
Board: the switch shows what you bind as its current state. Have the firmware report {"pump_state": 1} after it actually switched, and bind the Switch card’s Current state slot to pump_state. The card then shows the device’s reported state once it arrives, not what was clicked. Leave “Disable the control when The reading is old” on (it’s the default), and also tick “The state is unknown”, so nobody can flip it while the ESP is offline. Keep “Ask before running” on for a pump, that’s the default too. Card settings: Control cards
Moved to GPIO 26 with the HIGH-before-OUTPUT trick, no more click across 20 reboots. Bound the switch to pump_state and the firmware reports after switching. I had the old-reading option but not the unknown-state one, so the card was still clickable right after a restart. Both ticked now.
- You must be logged in to reply to this topic.
Join the conversation
Sign in to ask and answer, like helpful posts and mark the reply that solved your problem. Every contribution earns points and levels.

