AutoBrightness
On your display
Automatically adjusts panel brightness to the sun's elevation. Runs entirely on the clock.
- Topic
- Miscellaneous
- Includes
- Script
Runs on
- Runs on 32×8 (TC001 & DIY)
- Runs on 52×16 (TC002)
- Does not run on 32×8 with AWTRIX 3 (TC001 & DIY) Made for AWTRIX NG.
Choose your display in the next step.
Script description
AutoBrightness
Automatically dims and brightens your AWTRIX NG panel based on the sun's elevation at your location. It is dark at night, bright during the day, with a smooth, adjustable transition at dawn and dusk.
It runs as a headless background script directly on the clock. It does not need Home Assistant, MQTT or any other external service.
How it works
Every 10 minutes the script calculates the sun's elevation from your coordinates and the clock's time, then maps it to a brightness value:
-
Sun elevation ≤ dark threshold → minimum brightness
-
Sun elevation ≥ bright threshold → maximum brightness
-
In between, the position inside that range is turned into a value from 0 to 1 and shaped by the curve exponent:
brightness = min + (position ^ exponent) × (max − min)where
position = (elevation − dark threshold) / (bright threshold − dark threshold).
Auto brightness (LDR) is switched off by the script, otherwise the clock would ignore the brightness value.
Setup
- Open the web UI of your clock and go to the Scripts tab.
- Create a new script named
AutoBrightnessand paste the code (or install it from the Hub). - Save. The script starts right away and does not appear in the app rotation.
- Go to the Apps tab, click the ⚙ button next to AutoBrightness and enter your latitude and longitude. The defaults are for a location in the Alps and will be wrong for most people.
- Optional: check the log in the Scripts tab. You should see a line like
Sun 12.3 deg -> brightness 47every 10 minutes.
Settings
| Setting | Default | Description |
|---|---|---|
| Latitude | 47.4127 | Your latitude in decimal degrees |
| Longitude | 10.9785 | Your longitude in decimal degrees (east is positive) |
| Min brightness | 10 | Brightness at night (0–255) |
| Max brightness | 140 | Brightness in full daylight (0–255) |
| Sun elevation for min | -6 | At or below this elevation the panel is at minimum brightness (-6° is the end of civil twilight) |
| Sun elevation for max | 20 | At or above this elevation the panel is at maximum brightness |
| Curve exponent | 1.8 | Shape of the transition between min and max (0.5–4). 1.0 = linear. See below. |
Curve exponent
The exponent controls how the brightness is distributed between the two sun elevation thresholds.
1.0: linear. Brightness rises at a constant rate with the sun.- above
1.0(e.g. 1.8): slow at first, faster towards the end. The panel stays dim for longer in twilight and reaches full brightness late. Good for bedrooms and anyone who finds the panel too bright at dusk. - below
1.0(e.g. 0.7): fast at first, slower towards the end. The panel gets bright early in the morning and stays bright into the evening.
Why not simply linear? Our eyes perceive brightness roughly logarithmically: going from 10 to 20 looks like a doubling, while going from 120 to 130 is barely noticeable. With a linear curve, most of the visible change happens in the first part of the transition. An exponent above 1 spreads it out more evenly.
Example with the default values (min 10, max 140, thresholds -6° and 20°):
| Sun elevation | Position in range | 1.0 (linear) |
1.8 (default) |
2.5 |
|---|---|---|---|---|
| -6° or lower | 0 % | 10 | 10 | 10 |
| 0.5° | 25 % | 43 | 21 | 14 |
| 7° | 50 % | 75 | 47 | 33 |
| 13.5° | 75 % | 108 | 87 | 73 |
| 20° or higher | 100 % | 140 | 140 | 140 |
Tips:
- Start with the default and check how the panel looks around dusk. Each change of the exponent only needs a save of the settings.
- If the panel reaches full brightness too late with a high exponent, lower the sun elevation for max (for example to 10–15°) instead of lowering the exponent.
- AWTRIX NG applies its own gamma correction to the panel (Display settings, default 1.9). That already compensates part of the perception effect, so values between 1.0 and 2.0 are usually enough.
Notes
- Only the sun's position is used. Clouds and room lighting are not taken into account.
- Manual changes to the brightness slider are overwritten at the next update (every 10 minutes).
- The script needs the clock to have a valid time (NTP). Until then it simply waits.
- Accuracy of the sun position is about half a degree, which is more than enough for a brightness curve.
Sign in to view and copy the code of this script.
Discussion 0
Ask a question, suggest a change or share how you use it.
No comments yet. Start the conversation.
More scripts in Miscellaneous
Something wrong with this script? Report it.
Have an idea?
Sign in to ask questions and join the conversation.