Page 1 of 1
How to use longpress event and doubleclick event with a pushbutton ?
Posted: 07 Aug 2024, 13:12
by rw11lkx82
Good afternoon !
I'm continuing my discovery of the ESPEASY with the sensors I usually use.
I'm having a problem with the push button.
Configuration :
Board : ESP32
Pushbutton : electrical classic like this
https://www.legrand.fr/pro/catalogue/po ... ules-blanc
Linked on GPIO 13 (between Ground and GPIO 13 - voltage from the expansion board in 5V)
Internal pullup enabled.
Config like this

- Capture d’écran du 2024-08-07 13-00-38.png (64.64 KiB) Viewed 8147 times
With 1 shortpress event, I got the state value 1. An other shortpress : state value 0. Everything is fine !
But : when I am trying a longpress event, I am expecting to get state value 10 or 11. But the state value stays on 0.
Same with doubleclick event, I am expecting value 3 : the state value goes from 0 to 1 or 1 to 0 (not each time)
I don't understand what I am doing bad... I would like to use the longpress event to manage an event in Domoticz and adjust a dimmer.
About the doubleclick event, it is useless because not user friendly, but I find funny to get an "hidden" function
So, if anyone has an idea... Many thanks in advance !
Re: How to use longpress event and doubleclick event with a pushbutton ?
Posted: 07 Aug 2024, 13:29
by TD-er
When actually using a mechanical button (thus not a clear digital signal like from a sensor), you really should set some debounce time.
When you press a button, there is no immediate contact, but rather it will bounce a few times before making a full contact.
Also when using long wires (over a few decimeter), you may also need to take extra measures to prevent picking up noise.
For example adding some small capacitor (e.g. 100 nF) over the GPIO pin and GND, as close as possible to the GPIO pin.
You mentioned you're using 5V.
Maybe better to use some resistors to make this more close to 3V3.
I know there are lots of sources claiming the ESP's are 5V tolerant, but still this may cause issues as the GPIO pins internally are pulled to the Vcc net using diodes and thus you may change the effective voltage applied to the ESP.
So maybe you could use something like this:
5V --- R1 --- GPIO --- R2/C1 --- GND
With R2 and C1 placed parallel.
Suggestion for values:
R1: 4k7
R2: 10k
C1: 100 nF
As can be calculated
here, when using a 10k resistor and 100 nF capacitor, you discharge the capacitor in 1 msec, which may help a bit in keeping out noise and maybe also act a bit as a debounce circuit.
A typical value for the debounce in the switch task is 100 msec.
Re: How to use longpress event and doubleclick event with a pushbutton ?
Posted: 10 Aug 2024, 16:45
by rw11lkx82
Hello TD-er,
Thanks for your reply but it does not work.
According to your post :
- I modify the debounce value to 100ms (instead of 0) like this

- Capture d’écran du 2024-08-10 16-34-10.png (48.11 KiB) Viewed 8008 times
- I modify the circuit like this :
5V --- R1 --- GPIO --- R2/C1 --- GND
where
R1: 4k7
R2: 10k
C1: 100 nF

- 20240810_163629.jpg (2.75 MiB) Viewed 8008 times
You can see that on the picture.
Green wire linked to GPIO D13
Blue wire linked to 5V
Purple wire linked to GND
And nothing more than before : pushbutton works on single event (state changes from 0 to 1 and 1 to 0). But no state 3 or 10 or 11 as expected for double click or longpress.
I also tried in 3.3V with the same circuit (and without) : no change.
About longpress : the state change from 0 to 1 (or 1 to 0) before I release the button. Like if the board does not care I still press the button...
Re: How to use longpress event and doubleclick event with a pushbutton ?
Posted: 10 Aug 2024, 17:02
by Ath
Hmm, the Doubleclick max. interval and the Longpress min. interval might be too close to each other, causing both to be ignored.
You could try with the Doubleclick max. interval set to 800 msec, to see if that un-confuses the plugin?
Re: How to use longpress event and doubleclick event with a pushbutton ?
Posted: 10 Aug 2024, 17:35
by rw11lkx82
Hello ATh,
You can not put a value lower than 1000ms.
But I put 1000ms to double and 1200 to longpress.
Unfortunately, no change.
No state 3 or 10 or 11.
Re: How to use longpress event and doubleclick event with a pushbutton ?
Posted: 10 Aug 2024, 19:41
by TD-er
On the picture, it doesn't really look like the capacitor is as close as possible to the GPIO pin.
The reason this needs to be put close(r) to the GPIO pin is that it can easily pick up noise as the wires act as an antenna.
Re: How to use longpress event and doubleclick event with a pushbutton ?
Posted: 10 Aug 2024, 19:50
by rw11lkx82
10 cm wires are too far ???
Are you kidding ?
Re: How to use longpress event and doubleclick event with a pushbutton ?
Posted: 10 Aug 2024, 20:24
by Ath
You have the switch configured for "Push Button Active Low", but that should be set to "Normal Switch", even when using push-buttons.
The Push Button types can not be used with Longpress and Doubleclick, as these types have to be pressed again to revert the state, so they would always be long-pressed, and that doesn't make sense.
Naming that switch type "Push Button" might seem weird, but it's been this way for a long time, and there is no better way of naming these types. So, 1st push switches from Off to On, 2nd push switches from On to Off.
Re: How to use longpress event and doubleclick event with a pushbutton ?
Posted: 10 Aug 2024, 20:35
by ThomasB
I agree, use Normal switch.
But : when I am trying a longpress event, I am expecting to get state value 10 or 11. But the state value stays on 0.
Same with doubleclick event, I am expecting value 3 : the state value goes from 0 to 1 or 1 to 0 (not each time)
You did not say, but perhaps you are viewing ESPEasy's Devices Tab page for the state values. Be aware that only states 0 and 1 are reported in the ESPEasy Browser. You will not see the other state values there.
Also, double press may be unreliable if serial log is enabled. And in some cases a brief single press event can be missed too. So disable serial log during your testing to avoid this problem.
And it is not clear to me if your switch is a common push switch (only active while depressed), which is what your application should use. The translated datasheet description appears to be a push on, push off switch (mechanical toggle), which in this case is not the correct type. Your continuity tester will confirm what you have; It should only beep when the switch is being pressed.
- Thomas
Re: How to use longpress event and doubleclick event with a pushbutton ?
Posted: 10 Aug 2024, 20:44
by rw11lkx82
Ath,
I changed Push Button Active Low to Normal switch but I don't see the states I am looking for (3 or 10 or 11).
And now the behaviour is state still on 1 except when I press the button.
So maybe I could work with this in a Domoticz script.
I just see the ThomasB post :
Indeed, I am watching the states in ESPEasy browser. Thanks for your information !
Noted for serial log.
I don't test my push button yet but maybe the behaviour I just described (about the state still on 1 except when I press the button) answers your question ?
I will continue my experiments tomorrow. Thanks for your help guys !!!
Have a good evening !
Re: How to use longpress event and doubleclick event with a pushbutton ?
Posted: 10 Aug 2024, 20:45
by Ath
And I also enabled "Inversed logic", so my button can connect the GPIO to GND to activate, that usually makes things more clear.
Re: How to use longpress event and doubleclick event with a pushbutton ?
Posted: 10 Aug 2024, 20:48
by ThomasB
I don't test my push button yet but maybe the behaviour I just described (about the state still on 1 except when I press the button) answers your question ?
You need to test the push button with a continuity tester. Remove from circuit before testing.
- Thomas
Re: How to use longpress event and doubleclick event with a pushbutton ?
Posted: 10 Aug 2024, 23:04
by Ath
NB: When using the Longpress (10/11) and Doublclick (3) events, you will also get the standard State event of 1.