Hello sl01fr.
Thank you for using the Apple Support Communities. It seems you are encountering some issues with your iMac's brightness when the "Automatically Adjust Brightness" option is selected. I'm happy to provide you with some direction to resolve this.
Let's start by reviewing the following Apple knowledge base articles to ensure everything is setup correctly.
OS X El Capitan: Adjust your display’s brightness
OS X El Capitan: ambient light sensor
Let's also make sure that there is nothing in the way on the ambient light sensor, located next to the FaceTime HD camera on your iMac.
If the issue persists, then let's access Safe Mode and a Test User to check what could be causing it. Here are the articles to complete both steps:
Try safe mode if your Mac doesn't finish starting up
How to test an issue in another user account on your Mac
If the issue persist in both modes, we would then want to reinstall OS X. This should not delete any data, but I recommend backing up your iMac's contents with Time Machine before performing this step. Here are the articles for that:
Use Time Machine to back up or restore your Mac
How to reinstall OS X on your Mac
Make sure to follow the "Reinstall OS X from Recovery" section:
1. Turn on your Mac.
2. Immediately after you hear the startup sound, hold the Command and R keys on your keyboard.
3. Release the keys after the Apple logo appears.
4. If prompted, select a Wi-Fi network, or connect your Mac to the Internet using an Ethernet cable.
5. After the Recovery menu appears, select the option to Install OS X.
6. Follow the onscreen prompts to select your destination disk and install OS X.
And lastly, if that fails to resolve the issue, I recommend following the "Erase your drive and install OS X" section of the same article as above. Be sure to check if the issue occurs before you restore your Time Machine backup in order to verify if this is a possible hardware issue with your iMac.
Have a great day.