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 / configuration-flow-and-options

Configuration flow and options

Adaptive Lighting uses a Home Assistant config entry to name each instance and store its settings. The flow separates entry identity from changeable options, accepts settings from either the UI or YAML, and presents the same option model through localized Home Assistant forms. See also Adaptive Lighting user configuration and switches and service controls.

Configuration entry lifecycle

User entry creation

The user flow first asks for the name of an Adaptive Lighting instance. The name becomes the entry title and its unique identity, so Home Assistant stops a second entry from using the same name. A new entry starts with no saved options; the option form supplies defaults when the user configures it later.

The flow changes when entries already exist. Home Assistant offers a choice between creating a new instance and duplicating an existing one. Duplication copies the source entry's saved options but still requires a new name.

This diagram shows how a UI request becomes a named config entry and how an existing entry can provide option values for a duplicate.

flowchart TD
    A[Start user flow] --> B{Existing entries?}
    B -->|No| C[Enter instance name]
    B -->|Yes| D[Create new or duplicate]
    D -->|Create new| C
    D -->|Duplicate| E[Copy saved options]
    E --> C
    C --> F{Name already used?}
    F -->|Yes| G[Abort as already configured]
    F -->|No| H[Create config entry]

References: custom_components/…/config_flow.py• L31-84 tests/test_config_flow.py• L20-37 tests/test_config_flow.py• L150-249

YAML entry import

YAML configuration enters Home Assistant through the import step. The integration first validates the YAML shape, including unique names across entries, then creates or updates the matching config entry. YAML-managed entries keep their settings in configuration.yaml rather than in the UI options form.

If an entry with the same unique name already exists, an import updates that entry's data instead of creating a competing instance. The import also marks the entry as YAML-managed so later setup can keep the two configuration sources distinct.

References: custom_components/…/__init__.py• L25-36 custom_components/…/__init__.py• L48-59 custom_components/…/config_flow.py• L86-101 tests/test_config_flow.py• L39-53

Option model

Option groups

The option model controls the light set and the way Adaptive Lighting changes it over time. The UI uses the same names as YAML, which makes a setting easy to move between the two configuration paths.

GroupPurposeExamples
Light selection and timingChoose controlled lights and set the adaptation cadencelights, interval, transition, initial_transition, adapt_delay
Brightness and colorSet output limits and color preferencemin_brightness, max_brightness, min_color_temp, max_color_temp, prefer_rgb_color
Sleep and sun timesDefine sleep output and virtual sunrise or sunset boundssleep_brightness, sleep_color_temp, sleep_rgb_color, sunrise_time, sunset_time
Brightness curveSelect the brightness calculation style and its time rangesbrightness_mode, brightness_mode_time_dark, brightness_mode_time_light
Manual controlDecide how external light changes pause adaptationtake_over_control, take_over_control_mode, autoreset_control_seconds
Turn-on and command handlingControl first-on behavior and command interceptiononly_once, adapt_only_on_bare_turn_on, separate_turn_on_commands, intercept, multi_light_intercept
State and display behaviorControl state checks, group handling, and option visibilitydetect_non_ha_changes, skip_redundant_commands, expand_light_groups, include_config_in_attributes

Some options depend on another option. For example, sleep_color_temp applies when sleep mode uses color_temp, while sleep_rgb_color applies when it uses rgb_color. The non-default brightness curve uses its two time options, and multi-light interception requires interception to be enabled. detect_non_ha_changes, manual_control_on_external_turn_on, and adapt_only_on_bare_turn_on also depend on takeover control. expand_light_groups selects whether configured groups are treated as their members or as group targets.

References: custom_components/…/strings.json• L23-105 custom_components/…/en.json• L24-107

Defaults and precedence

The system has one documented default for each option. When an options form opens, it uses the saved option value when one exists and otherwise shows that default. A missing light list defaults to an empty list, so an instance can be created before lights are assigned.

At runtime, Adaptive Lighting builds the effective configuration in this order:

  1. Start with the factory defaults.
  2. Apply values saved by the options flow.
  3. Apply values in config-entry data, which includes YAML settings.
  4. Convert special placeholder and time values to the types used by the running component.

This order means YAML data takes precedence over an options value for the same key. The main defaults include a 90-second adaptation interval, a 45-second transition, brightness limits of 1 to 100 percent, color temperature limits of 2000 to 5500 Kelvin, and enabled external-control takeover and command interception. The complete option table and current default values are maintained in docs/configuration.md.

References: custom_components/…/const.py• L323-407 custom_components/…/switch.py• L554-583 custom_components/…/config_flow.py• L142-160

Option validation

The options form validates values before it saves them. Numeric settings use bounds or Home Assistant validators, boolean settings require boolean values, entity selection is limited to light entities, and dropdowns restrict values such as brightness mode and takeover mode.

Time-related settings have an additional check. Home Assistant validators for time periods and clock times cannot be stored directly in a JSON config entry, so the options flow checks them again and reports Invalid option when they do not pass. A missing configured light produces a separate One or more selected light entities are missing from Home Assistant error.

The form keeps basic settings visible and places advanced settings in a collapsed Advanced settings section. Home Assistant submits the section as nested data; the flow flattens it before validation and saving. When validation fails, the flow puts the submitted values back into the form and keeps the user on that form. It creates the options entry only after all extra checks pass, which then lets the integration reload the instance with the new settings.

References: custom_components/…/config_flow.py• L112-127 custom_components/…/config_flow.py• L129-202 custom_components/…/strings.json• L45-112 custom_components/…/en.json• L46-114

Home Assistant presentation

Configuration flow strings

The file custom_components/…/strings.json defines the source text for the config flow and options flow. The initial form names the instance and explains that one instance can control multiple lights. When entries already exist, the menu strings explain the create-or-duplicate choice. A duplicate name uses Home Assistant's standard already-configured error text.

The options description also provides links to the interactive parameter web app and the project documentation. The flow supplies those URLs as placeholders, so translated text can place the links without changing the flow logic.

References: custom_components/…/strings.json• L2-21 custom_components/…/config_flow.py• L24-27 custom_components/…/config_flow.py• L44-64

Option form strings

The options strings give Home Assistant a label for every option and a description for values that need context. The text explains units and dependencies such as seconds versus milliseconds, Kelvin, RGB color, sleep-mode selection, group expansion, and the relationship between takeover settings.

The strings also warn about options that can affect other Home Assistant behavior. For example, non-Home Assistant change detection may turn lights on when a device reports a false state, interception is not suitable for lights that do not support the required turn-on data, and group handling changes whether commands target a group or its members.

References: custom_components/…/strings.json• L29-105 custom_components/…/en.json• L30-107

Translation files

English source text is mirrored by locale files in custom_components/adaptive_lighting/translations/. Each locale can translate the config step, menu, options, field labels, field descriptions, and validation errors. The source keys must stay aligned with the flow data keys because Home Assistant uses those keys to place text on the matching form controls.

The translation layer changes what users read, not which values the flow accepts. Validation rules and defaults remain in the configuration model, while localized strings explain those rules in the selected language. The Estonian, Italian, Norwegian Bokmål, Brazilian Portuguese, Russian, Swedish, and Ukrainian locale files also carry translated option-form text. Their recent changes extend or refine descriptions for newer settings such as sleep transitions, brightness modes, takeover modes, command delays, and adaptation delays. They do not change the option contract or its defaults.

References: custom_components/…/strings.json• L2-112 custom_components/…/en.json• L2-114 custom_components/…/et.json• L17-57 custom_components/…/it.json• L17-88 custom_components/…/nb.json• L17-86 custom_components/…/pt-BR.json• L24-89 custom_components/…/ru.json• L17-97 custom_components/…/sv.json• L24-94 custom_components/…/uk.json• L24-94

Change checklist

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

  • Keep VALIDATION_TUPLES, YAML schema construction, and the options form aligned when adding or changing an option. These paths define the same key with different input sources.
  • Keep the advanced-section flattening aligned with the form schema. A field moved between basic and advanced settings must still reach validation and saved options under its original key.
  • Update the matching strings.json option label and data_description when an option's unit, dependency, or warning changes. Check locale files when the key set changes.
  • Preserve the distinction between config-entry data and options. YAML values in data override UI option values during effective configuration assembly.
  • Keep EXTRA_VALIDATION aligned with its JSON-safe coercion when changing a time or duration option. The options flow and runtime conversion must accept the same stored form.
  • Keep the YAML-import source behavior intact. YAML-managed entries must continue to direct users to YAML rather than expose a competing UI options form.

Important failure modes

TriggerConsequenceGuard
Reuse an existing instance nameHome Assistant aborts the new flow as already configuredSet a unique name before entry creation
Select a light entity that no longer existsThe options form reports a missing light and does not save the changeRemove or replace stale light entity IDs
Enter an invalid clock time or time periodThe options form reports Invalid optionUse the accepted time format and duration value
Submit advanced settings with a form key that is not flattenedThe value is not validated or saved under the expected option keyKeep advanced fields inside the named section and keep _flatten_section_input aligned with the schema
Set YAML and UI values for the same keyThe YAML value in config-entry data wins at runtimeKeep the active source of each setting clear
Try to edit a YAML-imported entry in the UIThe options flow shows no editable option schemaChange the YAML configuration and reload it

Key files

FileWhy to read it
custom_components/…/config_flow.pyShows user entry creation, duplication, YAML import, options validation, section handling, and form assembly.
custom_components/…/const.pyDefines option names, defaults, validators, allowed selections, and JSON-safe conversion rules.
custom_components/…/__init__.pyShows YAML schema validation and how YAML configuration enters the config-entry system.
custom_components/…/switch.pyShows how saved data, saved options, and defaults become the effective running configuration.
custom_components/…/strings.jsonDefines the source labels, descriptions, placeholders, and errors shown by Home Assistant.
custom_components/…/en.jsonShows the English presentation of the configuration flow and option form.
custom_components/…/et.json, it.json, nb.json, pt-BR.json, ru.json, sv.json, uk.jsonShow the recently updated localized presentations and the locale key shape for the same configuration forms.
docs/configuration.mdProvides the user-facing option table with descriptions, defaults, and types.