Electrical stability and security with microgrids