letscontrolit / ESPEasy

Easy MultiSensor device based on ESP8266/ESP32
http://www.espeasy.com
Other
3.28k stars 2.21k forks source link

DoubleClick- and Longpress-Issue (tested with Sonoff Touch T1) #2696

Closed toxic-tonic closed 1 year ago

toxic-tonic commented 4 years ago

Hi everybody,

I face an issue with Sonoff Touch T1 ESPEasy (tried mega-20191028 and mega-20191003) with the doubleclick-/longpress-function of the switch-plugin. When trying to use that function, it always triggers both funtions shortpress and doubleclick AND longpress (?) on doubleclick or only shortpress and longpress on longpress! The log looks like this:

doubleclick: ...... 207621: SW : GPIO=0 State=1 Output value=1 207624: EVENT: Touch#State=1.00 207662: ACT : gpio,12,0 207666: SW : GPIO 12 Set to 0 207709: SW : GPIO=12 State=0 Output value=0 207717: EVENT: Relay#State=0.00 207744: ACT : gpio,13,0 207749: SW : GPIO 13 Set to 0 207823: SW : GPIO=0 State=1 Doubleclick=3 207825: EVENT: Touch#State=3.00 208920: SW : LongPress: GPIO= 0 State=1 Output value=11 208922: EVENT: Touch#State=11.00 ......

longpress: ...... 115896: SW : GPIO=0 State=1 Output value=0 115898: EVENT: Touch#State=0.00 115942: ACT : gpio,12,1 115947: SW : GPIO 12 Set to 1 115983: SW : GPIO=12 State=1 Output value=1 115991: EVENT: Relay#State=1.00 116013: ACT : gpio,13,1 116017: SW : GPIO 13 Set to 1 116898: SW : LongPress: GPIO= 0 State=1 Output value=11 116909: EVENT: Touch#State=11.00 ......

The related article in the forum is here: https://www.letscontrolit.com/forum/viewtopic.php?f=5&t=7162

I tested different configurations like active high and active on low, several debounce-times and timeouts, with no effect.

I'm not shure waht additional informations you need, just let me know if you need something...

Thanks in advance

Tobias

TD-er commented 4 years ago

I added the needsinfo tag, since I don't know if this behavior you're seeing is intended. So it's not about you not supplying enough info, but I hope the author of the double-/long-press will shed some light on this.

toxic-tonic commented 4 years ago

Found the same Problem discribed here: https://www.letscontrolit.com/forum/viewtopic.php?t=6152

giig1967g commented 4 years ago

Hi, I developed the long-press (LP) and double-click (DC). And I can confirm that the behaviour described is the correct behaviour of the plugin. The reason for this logic is because I couldn't find another way of developing it. (keep in mind that the current switch plugin handles both switches and push buttons, where a push button is a momentary button that changes state after it has been pressed and released)

Nevertheless, I thought many times that it might be implemented in a better way with more flexibility.

A little of background: during the development of these features I also faced the issue if sending single-click together with doubleclick or longpress and the reason why I ended sending also the single click is because when you press the button the first time you are actually changing the state of the switch.

This is the current logic: Let me make an example assuming initial state =1: single click button: the user presses shortly a button, on PRESS an event is created (state=0). On RELEASE an event is created (state=1) switch button with double click: the user presses shortly a button, on PRESS an event is created (state=0). On RELEASE an event is created (state=1). On another quick PRESS a double-click event is created (state=3). On RELEASE an event is created (state=1) button with longpress: the user presses shortly a button, on PRESS an event is created (state=0). The user keep pressing the button and after a time defined in the plugin it send the LP event (state=10 if I am not wrong). On RELEASE an event is created (state=1).

As you can see, it's impossible to avoid sending the single-click without applying a delay in the response time or missing some state changes.

The solution (working only for LP) could be to implement different logics for switch and push buttons:

In case of PUSH buttons the logic could be: a) the event change is sent on button RELEASE instead of button PRESS b) the user presses a button, on PRESS no events crated. On RELEASE according to the time elapsed from the 1st PRESS and the 2nd PRESS it generates either a state toggle or a state=10.

For double-click I really don't have ideas in how to avoid sending the single-click. I also checked and I can confirm that when you doubleclick the standard mouse button, the mouse is sending first the single click and then the double click.

To resume: if you have an idea on how to improve LP and DC, please write it here and I, together with Gijs, will analyze and try to implement. Any contribution will be really appreciated.

toxic-tonic commented 4 years ago

Hi,

Sorry for the late reply, was busy the last days! And Thank you for your explanation. I understand your point and it is more complicate than expected. In my opinion the easiest way would be to separate the classical switch and the push button. So we leave the double-click / longpress just in the touch button and the activation of either would result in a delay, what would be logic for everyone! So the workflow would look like this:

Config: Button Active Low Doubleclick within 1000ms active on low Logpress longer then 1000ms active on low

You press the button (gpio low), and it starts a timer for 1000ms

Do I miss something? If someone don’t want the delay he could either disable (or not enable) the double-click or decrease the delay for it.

Best regards

Tobias

toxic-tonic commented 4 years ago

Am I any near a possible solution? ;-)

Thanks

Tobias

TD-er commented 4 years ago

@giig1967g is working on the GPIO handling for switch plugins. Maybe he is also the best one to answer this question?

giig1967g commented 4 years ago

sorry, but I am working in the PLUGIN_WRITE section of the plugin (commands) The PLUGIN_TEN_PER_SECOND (longpress, etc.) will be my next work...

deggle commented 4 years ago

Hi All,

I've had the same issue - I'd like three separate MQTT events for single, double and long - however the standard behaviour will, as described above, will always immediately send the =1 event on initial stage change, with the double=3/long=11 (in my case) events.

I have a solution that has worked for me - using a rule and timer. Essentially, I've disabled the switch directly being sent to the controller and handled this with the rule. The 'single' event isn't sent until 1 second has passed to be sure it's not actually a double or long event (in which case the time is stopped).

It may not work for all your use cases, but I've seen at least someone wanting it for controlling 3 hue lights etc, which this will probably work fine for (though you'll need to manage the toggling of state elsewhere - this solution just splits the three events).

Rules:


on Switch1#switch1=1 do
 timerSet,1,1
EndOn

On Rules#Timer=1 do
 Publish sometopic/switch1,single
 timerSet,1,0
endon

on Switch1#switch1=3 do
 Publish sometopic/switch1,double
 timerSet,1,0
EndOn

on Switch1#switch1=11 do
 Publish sometopic/switch1,long
 timerSet,1,0
endon

Obviously you'll need to amend based on your switch names/values, MQTT topics and if you're using other timers. If you don't want MQTT I'm sure other actions/rules could be worked into this.

Hope this is helpful for someone!

giig1967g commented 4 years ago

I am aware of the problem, and I think that the best practice (that I will develop as soon as the GPIO commands in the CORE will be merged) is to operate the SINGLE and LONG press events based on the RELEASE action of the button.

Maikel-K commented 4 years ago

Has this been worked out? I want to use single press to turn on the light and long press for dim up

tonhuisman commented 1 year ago

No replies here for a long time, most likely can be closed

iz8mbw commented 12 months ago

@TD-er @tonhuisman It seems this issue is still present, I have the same issue, see:

https://www.letscontrolit.com/forum/viewtopic.php?t=9881

https://www.letscontrolit.com/forum/viewtopic.php?t=6152