Opening and closing gate

You can probably use a solid state relay to toggle the connection just like the switch does. However you'd need to confirm how much voltage is going through it and whether it is momentary (which I assume it is) or not before somebody can really help.