Garage door with one entity to open/stop/close/open/stop/close

Hi there! Hello to all and Happy New Year :slight_smile:
I am beginner in HA but my HA is almost completely set up. However, I have a little problem. I have two gates. One of gate has two separate inputs: open/close and that’s ok.
The other gate (it is garage) has one input running in the sequence “open/stop/close/open/stop/close etc.” I have control of both the gates and the reading of their status on Satel Integra (it’s doesn’t matter what it is, I’ve got it). To control the garage door, I need help with writing the code in YAML according to the block diagram I enclose. Of course, I have to duplicate it for three states: open, close, stop, but if someone helps me with this one algorithm, the rest will no problem for me :slight_smile:
Thank you in advance!