Create a doubletap in driver

want to see if I can create a double tap within a driver, so within the event case I found some code which does similar. Would this work, or is there a better way to do it.

LastPress = now()
               if (lastPress != null && now() - lastPress < 5000) {
                sendButtonEvent( "doubleTapped" ,ep,"physical")
             } else{
                sendButtonEvent( "pushed" ,ep,"physical")

The approach looks solid to me, but without the rest of the code for contact, it would be hard to say.

It's just a case statement with a trigger from a device above this and a break below. So if the event of a press happens this runs.

I can't seem to get it working, essentially in sudo I think I want the below or though I'm not sure if it's the best way to do it or if it would even work. That's why I found that example above.

Button pressed

Add to NumberPressed
Wait 0.5 seconds
If 1 then
send pushed
Send double tap
End if
Set NumberPressed to 0

The thing that will get you is the wait for .5 seconds. You'll need to have the event register the button press and do the variable count, but schedule a method to run after the delay period to check the count, send the appropriate event, then reset the variable to 0.

Something along these lines:

def buttonPress(evt) {
    state.buttonCount += 1

void buttonCheck() {
    if{state.buttonCount == 1} {
        sendEvent "button tapped"
    } else {
        sendEvent "doubleTapped"
   state.buttonCount = 0

:+1: Pause Execution and waits are usually to be avoided when possible in code. I have found a few cases where it causes issues with Hubitat apps before.


That was my thinking, it didn't sound like a good thing to do and when you trying to capture a very quick press aswell.

I'll try your code though thanks.

wont save because of the def location

looked more into the code

There is a void parse (string X) {
then it maps that parse X
    Then tests that in a IF (test) {
      switch (eventFromMap) { 
      Case "1":

Then the push event which I want to work out if it can be a double tap,
so pasted you code and sorted the send events.

other cases etc
      } end of case
} end of void