Skip to content

New Share your ideas with the AWTRIX community. Keep your creations together in your account.

Sign in

Which AWTRIX do you have? Choose it once and the Hub shows what runs on it.

ScriptAWTRIX NG

AutoBrightness

On an AWTRIX display
AutoBrightness shown on an AWTRIX display
AutoBrightness · by martinh87

On your display

Automatically adjusts panel brightness to the sun's elevation. Runs entirely on the clock.

Which AWTRIX do you have? See below where it runs, or choose your device.
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.

Send to AWTRIX

Choose your AWTRIX

AutoBrightnessAWTRIX NG script

Install this script on your AWTRIX NG. Its icons and sounds are installed with it.

Your AWTRIX’s local address, for example 192.168.178.39 or awtrix.local.

The name shown in your AWTRIX script list. Use letters, digits, hyphens or underscores.

Connection & device login

Connect your phone or computer to the same network as your AWTRIX. Allow local network access if your browser asks.

Use the device’s IP address, without a page path such as /#/apps.

If your AWTRIX requires a login, the username and password fields will appear when you connect.

Sign in to the Hub to install scripts. Attached files are installed separately.

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:

  1. Sun elevation ≤ dark threshold → minimum brightness

  2. Sun elevation ≥ bright threshold → maximum brightness

  3. 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

  1. Open the web UI of your clock and go to the Scripts tab.
  2. Create a new script named AutoBrightness and paste the code (or install it from the Hub).
  3. Save. The script starts right away and does not appear in the app rotation.
  4. 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.
  5. Optional: check the log in the Scripts tab. You should see a line like Sun 12.3 deg -> brightness 47 every 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.

More scripts in Miscellaneous

Something wrong with this script? Report it.