Automation from actions within timeframe

Tags: #<Tag:0x00007fc4034496b0> #<Tag:0x00007fc403449570>

Hi all

I have in the back of my mind a system to be able to control a light switch (zigbee) from another switch (always zigbee).

Here is the idea.
Light switch A is on one side of a long passage that is very dark at night. Switch A controls the light of the passage.
On the other side of the passage I have light switch B that does NOT control the passage lighting but other lights.

My plan is: can I create some kind of automation that based on a combination of buttons pressed on B (eg. Toggle twice one of the buttons within a short timeframe) it turns on the light on A?

At the moment all the switches are connected via smartthings and unfortunately samsung does not offer this kind of feature.

This is what I thought could work.
I assign a variable named alpha=0.
If the button on B is pressed, alpha takes value 1 and starts a timer (5 secs). After the 5 seconds alpha reverts to zero. If within the 5 seconds (alpha=1) the button is pressed again then the light switch A is toggled.

I am seeking some more experienced advise on this one. Is there a smarter way to make it work that I am struggling to grasp?

Thanks in advance to all the contributors.

I do this with switches attached to shellies controlling lights.
A variable is not required unless you want more than two actions per switch.

Flicking a switch toggles a light.
Flicking a switch and back again within 1 second toggles another light, and in another case opens the garage door.

Your automation is triggered by the light switch changing state.
After a delay, you need a condition to check that the switch is back in its initial position.