Automation button for my gate

Hello,

I have got a switch to open my garage gate and a sensor to my dog’s gate to show whether it is closed or open so my dog will not escape from my yard when I open the garage gate.
What I want to do is when I tap the button to open the garage gate, before it opens I want it to check if the sensor of my dog’s gate is in closed position, if it is an open position, my garage gate should not open.
In smart life app I could do an automation Launch Tap-to-RUN if dog’s gate is close then open garage gate but in HA I am not sure how to do it in automations because it looks that it will not allow me to say like this… When button/automation is pressed and if dog’s gate is closed then do open the garage gate. Or am I missing something like a noob?

In the UI, these are under “And If”:

yes but I do not understand what should I put for “When”. I was expecting to see a funtion like tap or run.

Thank you for being helpful! I managed to make it work using your tehniques