Gate inactivity alert

I don't think OP is concerned about whether the gate is open or closed, but about how long it has been since a cow went through the gate.

You could get the cows to wear RFID tags, and train them to walk closer to the RFID reader.

Or, you could use a PIR sensor to see if there are any cows moving around. I suspect that the cows are close enough to the IR spectrum that the PIR sensor monitors.