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 / switches-and-service-controls

Switches and service controls

Adaptive Lighting exposes four Home Assistant switch entities for each configuration. These entities let users and automations start or stop adaptation, select sleep or attribute modes, apply current values at once, and pause or resume adaptation for selected lights.

Control entities

Each configuration creates one main switch and three related switches. The entities use the configuration name in their IDs and appear as one Adaptive Lighting service device in Home Assistant. The configuration that creates these entities is described in Adaptive Lighting user configuration, while the path from a configuration flow to an active entry is described in Configuration flow and options.

Entity group

The main switch is the control point for a configuration. The three auxiliary switches choose which values the main switch applies to its lights.

EntityUser control
switch.adaptive_lighting_<name>Turns automatic adaptation for the configuration on or off.
switch.adaptive_lighting_sleep_mode_<name>Selects the configured sleep brightness and color values.
switch.adaptive_lighting_adapt_brightness_<name>Allows or blocks brightness adaptation.
switch.adaptive_lighting_adapt_color_<name>Allows or blocks color adaptation.

Sleep mode starts off. Brightness and color adaptation start on. Home Assistant restores the prior state of these switches when possible. A new main switch starts on by default, so its configured lights can begin adaptation without a separate turn-on action.

The four entities share one Home Assistant service device. A configuration can also use light groups as targets. Its group policy decides whether Adaptive Lighting expands a group into member lights or keeps the group as the command and manual-control target.

References: custom_components/…/switch.py• L487-555 custom_components/…/switch.py• L1036-1061 custom_components/…/switch.py• L1758-1811

Entity state model

The main switch controls whether the configuration keeps its light updates active. Turning it off removes the active update work and clears the tracked light state. Turning it on starts the update work and applies the current values to eligible lights.

Sleep mode changes the source of the values used for adaptation. When it turns on, the lights use the configured sleep brightness and either sleep color temperature or sleep RGB color. When it turns off, the lights return to values based on the current time of day. Both changes force an update when the main switch is on.

The brightness and color switches act as separate gates. If a gate is off, the related light property is not selected for automatic adaptation. Manual-control state can remove more properties from an update, so an enabled gate does not override a manual pause.

This diagram shows how the four entities select work for the lights assigned to one configuration.

flowchart TD
    M[Main adaptation switch] --> R[Active configuration]
    S[Sleep mode switch] --> R
    B[Adapt brightness switch] --> R
    C[Adapt color switch] --> R
    R --> Q{Eligible light properties}
    Q --> L[Configured lights]

References: custom_components/…/switch.py• L1254-1293 custom_components/…/switch.py• L1712-1733 custom_components/…/switch.py• L1560-1628

Automation services

The adaptive_lighting service domain exposes actions for immediate changes and temporary control. Service calls can target a switch directly, or in some cases use lights to find the configuration that supplies their settings.

Service target selection

adaptive_lighting.apply and adaptive_lighting.set_manual_control use the target switch as the settings and control source. If lights is omitted, the action covers all lights assigned to that switch. If lights is supplied, the action is limited to those lights.

When a service call supplies lights without a switch, Adaptive Lighting finds the switch that controls them. It can use a single matching switch, or the only matching switch that is on. If more than one active configuration matches, the call is ambiguous and must name the intended switch. A call that names a switch can target that switch's full light set or a selected subset. Multiple switches can be named when no light subset is supplied.

The same target rules apply to light groups. Explicit member targets remain individual targets. Configured groups follow the configuration's expand_light_groups policy, which affects both service actions and manual-control tracking.

References: custom_components/…/switch.py• L240-373 custom_components/…/switch.py• L415-484 custom_components/…/services.yaml• L5-17 custom_components/…/services.yaml• L45-63

On-demand adaptation

adaptive_lighting.apply applies the current time-based or sleep-mode values immediately. It is useful when an automation needs to refresh a light outside the normal update cycle, or when it needs to choose which properties to change for one action.

The service accepts a transition time and separate adapt_brightness and adapt_color choices. prefer_rgb_color selects RGB color over color temperature when the light supports both. turn_on_lights controls whether an off light is turned on before the action.

The action does not change the configuration stored for the switch. It only sends the selected current values to the requested lights.

References: custom_components/…/switch.py• L415-445 custom_components/…/services.yaml• L1-42

Manual control markers

adaptive_lighting.set_manual_control records that a light property is under manual control. The marker prevents normal adaptation from changing that property until the marker is cleared or reset.

The manual_control value selects the scope of the marker:

  • true marks brightness and color.
  • false clears brightness and color and allows adaptation to resume.
  • brightness marks only brightness.
  • color marks only color.

The marker is stored per light. The main switch reports lights with any marker in its manual_control state attribute. If autoreset_control_seconds is set, the marker expires after that period without a new manual change. An active switch then reapplies the current values to the light.

Adaptive Lighting also uses its take-over settings to mark changes that come from outside its own light commands. This lets a manual change pause only the changed property when the configuration uses the pause_changed mode, or pause both properties when it uses pause_all.

References: custom_components/…/switch.py• L447-484 custom_components/…/switch.py• L1630-1710 custom_components/…/switch.py• L1735-1755 custom_components/…/services.yaml• L43-63 custom_components/…/services.yaml• L226-269

Runtime setting changes

adaptive_lighting.change_switch_settings changes the active settings of one main switch for the current Home Assistant run. Its fields use the same setting names as the configuration flow, so an automation can change values such as sunrise time, sleep values, color limits, or light-group handling without creating another configuration.

The use_defaults value controls fields that the service call does not include:

ValueSource for omitted fields
currentThe switch's current active values. This is the default.
configurationThe values loaded when the switch configuration started.
factoryThe documented integration defaults.

The change is temporary. It is not written back to the configuration entry and resets when Home Assistant restarts. The service cannot change the switch name, entity ID, or configured light source. If the main switch is on, a setting change also refreshes the active values and reapplies them.

References: custom_components/…/switch.py• L376-413 custom_components/…/switch.py• L894-1002 custom_components/…/services.yaml• L65-270

State and event signals

The switch entities provide state for dashboards and automations. The main switch also exposes the values that explain what it is currently doing.

Main switch attributes

The main switch always exposes a configuration attribute group. It contains the active configuration only when include_config_in_attributes is enabled. While the main switch is on, its other attributes show the current calculated light values, the lights with manual-control markers, and any active manual-control reset timers.

When the main switch is off, calculated setting attributes are empty rather than current targets. This prevents an off switch from being read as if it were still applying those values.

References: custom_components/…/switch.py• L929-955 custom_components/…/switch.py• L1213-1242

Manual control events

When Adaptive Lighting marks a light as manually controlled, it fires the adaptive_lighting.manual_control event. Automations can use this event to react to a manual change without polling the switch attributes.

The event identifies the affected light, the Adaptive Lighting switch that owns the action, and the brightness or color properties that are now under manual control. The event can result from a direct set_manual_control call or from a detected external light change when the related take-over settings are enabled.

References: custom_components/…/switch.py• L447-484 custom_components/…/switch.py• L1630-1688 custom_components/…/switch.py• L1735-1755

Change checklist

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

  • Keep the four entity names and unique IDs aligned with the entity descriptions and with the service-device grouping used by Home Assistant.
  • Keep the default states of the three auxiliary switches aligned with restored-state behavior and with the adaptation gates used by the manager.
  • Keep service schemas, service descriptions, and target-resolution rules aligned. A service field that is shown in the UI but rejected by the schema can fail in an automation.
  • Keep light-group expansion rules aligned across configured targets, explicit service targets, adaptation, and manual-control tracking.
  • Keep manual_control values aligned across service validation, manager flags, event data, and the main switch attributes.
  • Keep the temporary-setting rule aligned with the three use_defaults sources. Runtime changes must not be mistaken for configuration-entry changes.
  • Keep every manual-control timer and event path paired with a state refresh when a marker is cleared or expires.

Important failure modes

TriggerConsequenceGuard
A service call supplies neither a switch nor lightsAdaptive Lighting cannot choose a settings source and rejects the callSupply an Adaptive Lighting switch or a light list.
Lights belong to more than one active switch and no switch is suppliedThe target configuration is ambiguous and the action is rejectedPass the intended main switch in entity_id.
Multiple switches and a light subset are supplied togetherAdaptive Lighting cannot map the subset to one settings sourceName one switch when using lights.
turn_on_lights is false for an off light in an apply callThe light remains off and receives no adaptationSet turn_on_lights: true when the action must also turn on the light.
Both adaptation switches are offThe main switch has no brightness or color property to applyTurn on the property switch that the light should follow.
A manual-control marker remains setNormal updates continue to skip the marked propertyClear it with adaptive_lighting.set_manual_control or configure an auto-reset period.
A runtime setting change is expected to survive a restartHome Assistant reloads the saved configuration insteadStore lasting changes through the configuration flow or YAML path.
A light group is expanded or kept contrary to the intended policyCommands or manual-control state apply to different entities than the automation expectsSet expand_light_groups to match the target contract.

Key files

FileWhy to read it
custom_components/…/switch.pyDefines the four entities, their state changes, service target resolution, runtime settings, attributes, and manual-control event flow.
custom_components/…/services.yamlDefines the Home Assistant service descriptions and user-facing fields for immediate actions, manual control, and runtime settings.
custom_components/…/const.pyDefines entity keys, service names, option defaults, and service validation used by the switch controls.
custom_components/…/adaptation_utils.pyDefines the brightness and color flags used by manual-control services and events.
docs/services.mdProvides the wider user-facing service contract and examples that correspond to the registered services.