I needed a way to see when a gate was left open in my yard. This setup is through a M2 hub connected to Apple HomeKit.
I used an Aqara window sensor that is in a waterproof plastic box mounted next to the gate latch. I then glued a magnet to the gate latch so the window sensor only shows closed if the latch is in the lock position.
The window sensor triggers an existing Aqara smart bulb to flash on and off Red, if the gate is left open for more than 30 minutes.