I can tell by tipping the keg just a few degrees, not enough to unsettle the sediment in the bottom but enough to tell me that there is still significant mass of beer left. When it feels light to the tipping, I lift it one handed slightly with the handy handle. When it lifts effortlessly I know I am down to the last few glasses. My next keg is already in the fridge beside the tapped one, I just scoot it over into position and hook it up. Then I put the next backup keg in the backup position and after a few days I pull a glass with a faucet mounted right on the beer post, to clear the bottom and the beer out tube, and check the beer and the carbonation. Then it's ready to go when I need it. Sometimes I have to bleed the keg pressure a few times to get it absolutely ready to serve. Perhaps a spunding valve should be on my wish list. At any rate, long before I am surprised by an empty keg, my backup is in all respects ready to hook up and serve, so the empty keg is no great tragedy or inconvenience.
I don't use a level sensor because no matter what, I am still going to have that last glass of beer. I don't call the keg empty until the first sputter of gas comes out the faucet. It takes all of two minutes to change the keg.