Introducing a new way to review your PRs.

Read the announcement

basnijholt / adaptive-lighting

Adaptive Lighting custom component for Home Assistant

View on GitHub

13 documents · Updated Oct 21, 2026

docs / color-and-brightness-preview-app

Color and brightness preview app

The color and brightness preview app is a standalone browser tool for exploring how Adaptive Lighting settings change light output across a day. It runs the integration’s time-based calculation model without a Home Assistant instance and shows the result as brightness and color plots. The app belongs to the supporting tools described in Adaptive Lighting development and delivery and complements the checks described in Validation and release automation.

System purpose

The app turns lighting settings into a visual daily simulation. It helps an engineer or user compare brightness behavior and see the related color change around sunrise, daytime, sunset, and sleep mode.

The app does not send commands to lights or read state from Home Assistant. It creates a calculation model in the web process and renders the model’s results in the browser.

User controls

Simulation settings

The sidebar exposes the main Adaptive Lighting settings that affect the simulation. The server maps these controls to one calculation input set before it creates each plot.

Setting groupPurpose
Brightness limitsSets the minimum and maximum daytime brightness.
Color-temperature limitsSets the warm and cool ends of the daytime color range.
Sleep behaviorEnables sleep mode and selects its brightness and either a fixed RGB color or a fixed color temperature.
Sleep transitionControls whether color continues toward the sleep setting after sunset.
Brightness modeSelects the default, linear, or tanh brightness response for the brightness comparison.
Sunrise and sunsetSets the simulated sunrise and sunset times.

The app also exposes the dark and light transition durations used by the linear and tanh brightness modes. Sunrise and sunset offsets and location limits are not user controls in this interface; the app supplies zero offsets, no time limits, a default Astral observer, and UTC for the simulation context.

References: webapp/app.py• L217-284 webapp/app.py• L299-327

Simulation flow

The app processes browser input through one shared settings model and then produces two views of the same daily calculation. This flow shows the relationship between the controls, the calculation model, and the rendered results.

flowchart LR
    A[Sidebar settings] --> B[Simulation inputs]
    B --> C[SunLightSettings]
    C --> D[Minute timeline for the day]
    D --> E[Brightness plot]
    D --> F[Color and sun-position plot]

Daily timeline

The simulation samples the current day at one-minute intervals. For each sample, the calculation model derives a sun position from sunrise, sunset, solar noon, and solar midnight, then uses that position to calculate the requested brightness and color values.

The app uses UTC as the model timezone and creates its sunrise and sunset values from the times entered in the sidebar. It therefore provides a controlled view of the calculation rather than a reading of a user’s Home Assistant location or local light state.

References: webapp/app.py• L16-29 webapp/app.py• L60-75 webapp/app.py• L325-327 webapp/color_and_brightness.py• L44-186

Result plots

The brightness plot compares the default, linear, and tanh brightness modes over the same day. It marks sunrise and sunset and displays the main limits and transition durations so that a change in a setting can be related to a visible curve.

The color plot shows the calculated RGB color across the day with the sun position overlaid. In sleep mode, it uses the selected sleep color when the model selects a fixed color temperature or RGB color, so the plot reflects the same output choice as the calculation model.

References: webapp/app.py• L60-134 webapp/app.py• L137-193 webapp/app.py• L330-344

Calculation model

Shared Adaptive Lighting model

The preview uses the same SunLightSettings calculation model as the integration. The model returns a single group of light settings for a time and sleep state: brightness percentage, color temperature in Kelvin and mireds, RGB, XY, HS, sun position, and whether RGB output is forced.

Brightness follows one of three supported responses. The default response uses the sun position, while the linear and tanh responses shape the change around the nearest sunrise or sunset. Color temperature follows the sun position during the day and can move toward the sleep color when the relevant setting is enabled.

References: custom_components/…/color_and_brightness.py• L204-230 custom_components/…/color_and_brightness.py• L249-339 custom_components/…/color_and_brightness.py• L341-401

Module synchronization

At app startup, the web app refreshes its local calculation module from the integration’s calculation module. It changes only the Home Assistant color utility import so the standalone process can use its local compatibility module. This keeps the preview tied to the integration model while avoiding a required Home Assistant runtime for that module.

The integration source remains the authoritative calculation source. A change to the integration model can affect the preview after the startup copy step, so changes to calculation behavior should be viewed in both the integration and the app.

References: webapp/app.py• L32-57 custom_components/…/color_and_brightness.py• L16-21 webapp/color_and_brightness.py• L16-21

Home Assistant color compatibility

Color utility boundary

The standalone app uses webapp/homeassistant_util_color.py as a small local substitute for the Home Assistant color utility functions required by the calculation model. The substitute removes the direct homeassistant.util.color dependency while keeping the color conversion boundary used by the integration.

The shared model uses this boundary to convert color temperature to RGB and to derive XY and HS values from RGB. The utility also contains the broader Home Assistant-compatible conversions, including RGB, HS, XY, mired, and RGB white-channel forms. The preview does not need a live Home Assistant service to perform these conversions.

References: webapp/homeassistant_util_color.py• L1-6 webapp/homeassistant_util_color.py• L214-267 webapp/homeassistant_util_color.py• L402-418 webapp/homeassistant_util_color.py• L538-662

Compatibility maintenance

The local utility is based on a specific Home Assistant color utility source and is marked as modified to remove the Home Assistant import path. It is therefore a compatibility layer rather than an independent color system. If the integration changes which Home Assistant color functions it calls, the local utility and the startup module-copy behavior must continue to provide the same boundary.

References: webapp/homeassistant_util_color.py• L1-6 custom_components/…/color_and_brightness.py• L16-21 webapp/app.py• L32-57

Dependencies and local launch

Application dependencies

The app is a Python Shiny application. Shiny provides the browser UI and server callbacks, Matplotlib and NumPy produce the plots, Astral supplies sun-event calculations, and Shinyswatch supplies the page theme.

The checked development requirements contain the packages needed to run the app locally. The separately compiled requirements file records Astral and its pytz dependency, while the app-specific plotting and UI packages are listed in the development requirements.

References: webapp/app.py• L3-14 webapp/requirements.txt• L1-6 webapp/requirements-dev.txt• L1-4

Local launch

Local use starts the Shiny server from the webapp directory. The documented path installs the development requirements, runs shiny run, and opens the server at http://127.0.0.1:8000.

References: webapp/README.md• L1-10

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep webapp/color_and_brightness.py compatible with the source module copy and with the import rewrite to homeassistant_util_color.
  • When the integration calculation output changes, check both preview plots because they consume different parts of the same result set.
  • When a Home Assistant color utility call changes, update the local compatibility boundary and confirm that RGB, XY, HS, and color-temperature outputs remain available.
  • When sidebar inputs change, keep the input mapping and the SunLightSettings fields aligned so the server does not silently use stale defaults.
  • When app imports change, review both the development requirements used by the launch instructions and the compiled requirements files.

Important failure modes

TriggerConsequenceGuard
The integration calculation module and the local web copy no longer have matching fields or behavior.The preview can show results that do not represent the integration.Treat the integration module as the source and review the startup copy step with calculation changes.
A required Home Assistant color conversion is absent from the local utility.The app cannot build the RGB, XY, or HS values needed for the color plot.Keep the local utility aligned with the color calls made by the shared calculation model.
Sunrise or sunset settings produce an invalid sun-event order.Sun-position calculation raises an error and the plots cannot render.Keep the event order valid when changing simulated times or the model inputs.
The app-specific development packages are not installed.shiny run cannot import the UI or plotting dependencies.Install webapp/requirements-dev.txt as shown in the web app README.

Key files

FileWhy to read it
webapp/app.pyShows the UI, input mapping, daily sampling, plot outputs, and standalone startup behavior.
custom_components/…/color_and_brightness.pyDefines the shared Adaptive Lighting calculation model used as the preview’s source.
webapp/color_and_brightness.pyShows the web-facing copy of the calculation model and its local color utility boundary.
webapp/homeassistant_util_color.pyDefines the Home Assistant-compatible color conversion boundary used without Home Assistant.
webapp/README.mdDocuments the supported local launch path and server address.
webapp/requirements-dev.txtLists the dependencies used to run the preview application locally.