Solution (exclusion method):
When only the 1 black hat is turned off for the first time, you will find that.
There are only two black hats. When the lights were turned off for the first time, both of them thought there was only one black hat, waiting for someone else.
Turn off the lights for the second time and you will know.
Only three black hats turned off the lights for the first time. . .