First, let me say; You've done a good job utilizing loop() and timers correctly. It's like fresh air not to be typing "learn BlinkWi....".
But in this case I think you've overdone it with the control variables. It needs to be simpler.
if( millis() - prag_tm1 > 3000) // this keeps being true
flag_tm1 = 1;
if( millis() - prag_tm2 > 10000) // even when this is true
flag_tm2 = 1;
var = 0;
You have 1 variable for gate to go up and another for gate to go down.
And then here you have the gate-up variable being set every time after 3 seconds.
I suggest that you have twice the control variables and timers that you need.
Just use one gate movement variable with 0=no move, 1=up, 2=down.
Just use one timer. Where do they ever get set different?
Increase the number of states that var can have to 2 and break up case 1 into 2 cases.
Possibly use 1 control variable with more than 3 states to combine var and the gate control.
Possibly in a block of comments, outline the action in steps and use pseudocode as needed to make the needed steps clear. You can check your code against that.