I changed the keybind for the ultimate to middle mouse after the first time I accidentally used it at a bank.
If you seriously want to make an addon that prevents it from firing out of combat, you can look into action layers. They should allow you to do what you want.