Using momentary switch to trigger scenes with PLEG State Variable function

Over the last year or so I have installed about 70 physical Z-wave devices and many Apps and Plug-ins.
I have used PLEG as my main automation platform having many things done automatically quite successfully.

Nevertheless my wife hates that the house opens and closes automatically (lights and shades closes not per her expectations…) and suggested to make a MASTER Switch to execute various scenes. My intention is to have 3 basic scenes triggered by this “Smart MasterHouse Switch” as per the house status, time of day, occupancy etc. :

  1. A short press to (in less then a second) execute open or close of our living floor (depending on day / night + house open/ close status)
  2. Double short press (in less then 2 seconds) opens (in the morning) shades in the bedrooms floor (with a “wake up” procedure for my kids…)
  3. Long press (over 2 seconds) to open or close entire house with A/C control Etc.

I thought about using the commands of State Variable with the counting @ function to set the triggers.
Its clear a timer is requested to hold execution until presses are done.

I have spent sometime here in the forum to search for State Variable samples but did not come across clear enough examples of implementation -
it seems not a very popular way of handling issues… I will thank any elaboration on how the presses should set the state using the @ function
for the desired “state” - and also elaborate on the syntax.

Thanks

(I have set a momentary wall switch on Aeontec device with “instant status” as being the MasterSwitch)

Just of the top of my head, I would do something like this:

Schedules
KeyTimer OnType: SelfTrigger, OffType: Interval, 00:00:02

Triggers
Button

Conditions
KeySV$0 !KeyTimer and !Button and (KeySV > 1)
KeySV$1 Button and !KeyTimer and (!KeyTimer; Button)
KeySV$2 !Button and !KeyTimer and (KeySV$1; !KeyTimer) and (KeySV == 1)
KeySV$3 Button and KeyTimer and (KeySV$1; Button) and (KeySV == 1)
KeySV$4 !KeyTimer and Button and (Button; !KeyTimer) and (KeySV == 1)

Actions
KeySV$1 PLEG StartTimer timerName=KeyTimer
KeySV$2 <action for single click)
KeySV$3 <action for double click)
KeySV$4 <action for long click)

Repeat off for all Conditions.

Thanks a lot for your attention!

Unfortunately I have not fully understood the sequence of the state variable and the logic behind it.
Nevertheless I have put it to work and it did. The instant update is not that great and I have changed the timer to 3 sec.
The pressing needs to be somewhat longer. What I saw was that the short single press is more or less OK. The long press is also OK - the operation starts even if the press is continued (no requirement for button == 0 there). This could be fine for me because I have a
signal led in the switch and educate my family to press and wait until its on as a confirmation (for the short press they will see a short blink after the press and two blinks for the double).
I’m more concern about the short double pressing not being confused with the short press - could you please explain the sequence and logic and how this
eliminates the mix-up between the single and double pressing. :-[
Also in this regard attached is a status of these conditions in my system - its not clear how condition c20MasterSt2 (equivalent to your KeySV$2) is true if it requires c20MasterSt == 1 (your KeySV == 1 ) while it appears to be false.

Many thanks!

KeySV$0 - This resets the state machine when the timer expires
KeySV$1 - This is true while the Timer is active … (i.e. KeyTimer is true and !KeyTimer is false) and is started on the DOWN press of the button.

KeySV$2 - Single click … this waits until the timer expires, If the Button is not set and KeySV == 1 then there was only 1 button click during the interval.

KeySV$2 - Double click If a Button is detected while the timer is still Active … then this is a double-click.
KeySV$2 - Long click If the Button is still down at the end of the timer … then it’s a long click.

[hr]

NOTE: My experience with timing related triggers like this is that they are OK most of the time … but do not work when there is other activity on Vera or it’s doing a heal (Early Morning) … In that case “Instant Status” is not quite instant.

It’s really brilliant! thanks.