Rewriting ColorHug ALS Script

Five years ago I bought an ambient light sensor (ALS) such that I could automatically adjust the brightness of my computer screen, just like smartphones do. For this I have written a Python script. It is all written up in the blog post from 2016.

By now I have tweaked the script here and there, but somehow it just doesn't quite work right. I have also moved the sensor to a different position, but still I struggle to find the right model to map from sensor readings. I want to take new measurements, gather more data, find a better model. Also I want to have some clean architecture with that script.

So I start to clean this up. It turns out that I have multiple copies of that script, bin/brightness, bin/brightness-ng-runner, brightness, brightness-bin, brightness-ng.py and ddc-save-brightness, as well as a Python module externalbrightness. This is a mess. And I want to clean it up.

There isn't that much to do with the architecture. We need to have a sensor, a model that maps sensor readings to display brightness. There are then concrete implementations for that.

I have created a command line which just takes a sensor reading, converts it to a brightness using the model and then sets the screens appropriately.

But making the model is hard. For that one needs data, and a decent way to get the data. So I made a web UI using Streamlit where one can just set the screen brightness with a slider. Once that is good, one can just click “Save” and it will be stored on disk. This is what the interface looks like:

At the moment there are just two data points. Over the course of a few days I can gather the data that I need to make a model.

The code is now published as a Python package on PyPI, such that I can just use that on my computers. And the source code is on GitHub, as autobright.