Help me design a rule that triggers with double click on a physical switch

What i'm trying to do is trigger an automation by double clicking a physical switch fast. Either on-off or off-on.

Other option would be to trigger it on 1 push and build the 'wait for second push' into the action but I can't wrap my head around this either.

I assume this would work IF by timeout rule machine exited the rule, not continued executing it. But can't figure out how to achieve that.

Thanks and sorry for being not very bright.

The Tuya scene switch has single press, double press, and hold. The spacing between the double presses is critical.

This is what I use

4 for $28.98 at Amazon

Or one for $16.36

I get all my Tuya goodies from AliExpress. Here is the same scene switch for $3.99.

https://a.aliexpress.com/_mKgSBWL

Free shipping if you spend over $10.00 so get 4 for about $16.00 and wait a week or so.

The driver ‘Tuya Scene Switch TS004F’ from @kkossev works great.

In the living room, for example, the scene switch opens the shades and turns on the lights with a single tap.
At night, a double tap closes all the shades, turns off the lights and locks the front door.

The hold function is not used.

Here is a portion of the rule for double tap

1 Like

Thanks, this works. This is much appreciated.

Setting the currtime and lasttime variables and comparing them is understandable to me,
but I wish I understand what those private booleans mean / do.

1 Like

Why is the ELSE clause even needed? If the IF clause doesn't fire, the Set PB = True line fires and the rule exits.

PB's are convenient local variables that exist in all rules.

In this context, the rule can't fire a second time if the PB=false, since the Required Expression (RE) prevents the rule from running until the PB=true again.

So initially, PB=true, the RE is true, and the rule can be triggered by the Trigger Events. When the rule is triggered, the PB is set to false immediately, and hence the rule will run but cannot be re-triggered. At the end of the rule, the PB is set to true, and thus the RE is reset, allowing the rule to be triggered once more.

1 Like

So basically i could have 1 automation triggered if there are < 2 seconds between presses and another one then 2-4 seconds for example?

Also come to think about it I could also implement a check on the door sensor. If the door sensor had been triggered some time (30 seconds) before the double click, that means I came home, and the double click should turn ON the lights. If door contact hadn't been triggered that means i'm on my way out and the double tap should trigger turning OFF the lights :slight_smile:

1 Like

The new wisdom appears to be to use a conditional trigger instead

1 Like