ESPHome 2026.5.1
Loading...
Searching...
No Matches
esphome::light::LightColorValues Class Reference

This class represents the color state for a light object. More...

#include <light_color_values.h>

Public Member Functions

 LightColorValues ()
 Construct the LightColorValues with all attributes enabled, but state set to off.
 
 LightColorValues (ColorMode color_mode, float state, float brightness, float color_brightness, float red, float green, float blue, float white, float color_temperature, float cold_white, float warm_white)
 
void normalize_color ()
 Normalize the color (RGB/W) component.
 
void as_binary (bool *binary) const
 Convert these light color values to a binary representation and write them to binary.
 
void as_brightness (float *brightness) const
 Convert these light color values to a brightness-only representation and write them to brightness.
 
void as_rgb (float *red, float *green, float *blue) const
 Convert these light color values to an RGB representation and write them to red, green, blue.
 
void as_rgbw (float *red, float *green, float *blue, float *white) const
 Convert these light color values to an RGBW representation and write them to red, green, blue, white.
 
void as_rgbww (float *red, float *green, float *blue, float *cold_white, float *warm_white, bool constant_brightness=false) const
 Convert these light color values to an RGBWW representation with the given parameters.
 
void as_rgbct (float color_temperature_cw, float color_temperature_ww, float *red, float *green, float *blue, float *color_temperature, float *white_brightness) const
 Convert these light color values to an RGB+CT+BR representation with the given parameters.
 
void as_cwww (float *cold_white, float *warm_white, bool constant_brightness=false) const
 Convert these light color values to an CWWW representation with the given parameters.
 
void as_ct (float color_temperature_cw, float color_temperature_ww, float *color_temperature, float *white_brightness) const
 Convert these light color values to a CT+BR representation with the given parameters.
 
bool operator== (const LightColorValues &rhs) const
 Compare this LightColorValues to rhs, return true if and only if all attributes match.
 
bool operator!= (const LightColorValues &rhs) const
 
ColorMode get_color_mode () const
 Get the color mode of these light color values.
 
void set_color_mode (ColorMode color_mode)
 Set the color mode of these light color values.
 
float get_state () const
 Get the state of these light color values. In range from 0.0 (off) to 1.0 (on)
 
bool is_on () const
 Get the binary true/false state of these light color values.
 
void set_state (float state)
 Set the state of these light color values. In range from 0.0 (off) to 1.0 (on)
 
void set_state (bool state)
 Set the state of these light color values as a binary true/false.
 
float get_brightness () const
 Get the brightness property of these light color values. In range 0.0 to 1.0.
 
void set_brightness (float brightness)
 Set the brightness property of these light color values. In range 0.0 to 1.0.
 
float get_color_brightness () const
 Get the color brightness property of these light color values. In range 0.0 to 1.0.
 
void set_color_brightness (float brightness)
 Set the color brightness property of these light color values. In range 0.0 to 1.0.
 
float get_red () const
 Get the red property of these light color values. In range 0.0 to 1.0.
 
void set_red (float red)
 Set the red property of these light color values. In range 0.0 to 1.0.
 
float get_green () const
 Get the green property of these light color values. In range 0.0 to 1.0.
 
void set_green (float green)
 Set the green property of these light color values. In range 0.0 to 1.0.
 
float get_blue () const
 Get the blue property of these light color values. In range 0.0 to 1.0.
 
void set_blue (float blue)
 Set the blue property of these light color values. In range 0.0 to 1.0.
 
float get_white () const
 Get the white property of these light color values. In range 0.0 to 1.0.
 
void set_white (float white)
 Set the white property of these light color values. In range 0.0 to 1.0.
 
float get_color_temperature () const
 Get the color temperature property of these light color values in mired.
 
void set_color_temperature (float color_temperature)
 Set the color temperature property of these light color values in mired.
 
float get_color_temperature_kelvin () const
 Get the color temperature property of these light color values in kelvin.
 
void set_color_temperature_kelvin (float color_temperature)
 Set the color temperature property of these light color values in kelvin.
 
float get_cold_white () const
 Get the cold white property of these light color values. In range 0.0 to 1.0.
 
void set_cold_white (float cold_white)
 Set the cold white property of these light color values. In range 0.0 to 1.0.
 
float get_warm_white () const
 Get the warm white property of these light color values. In range 0.0 to 1.0.
 
void set_warm_white (float warm_white)
 Set the warm white property of these light color values. In range 0.0 to 1.0.
 

Static Public Member Functions

static LightColorValues lerp (const LightColorValues &start, const LightColorValues &end, float completion)
 Linearly interpolate between the values in start to the values in end.
 

Protected Member Functions

 ESPHOME_LIGHT_UNIT_FIELDS_UNION ()
 

Protected Attributes

float state_
 ON / OFF, float for transition.
 
float color_temperature_
 Color Temperature in Mired.
 
ColorMode color_mode_
 

Detailed Description

This class represents the color state for a light object.

The representation of the color state is dependent on the active color mode. A color mode consists of multiple color capabilities, and each color capability has its own representation in this class. The fields available are as follows:

Always:

  • color_mode: The currently active color mode.

For ON_OFF capability:

  • state: Whether the light should be on/off. Represented as a float for transitions.

For BRIGHTNESS capability:

  • brightness: The master brightness of the light, should be applied to all channels.

For RGB capability:

  • color_brightness: The brightness of the color channels of the light.
  • red, green, blue: The RGB values of the current color. They are normalized, so at least one of them is always 1.0.

For WHITE capability:

  • white: The brightness of the white channel of the light.

For COLOR_TEMPERATURE capability:

  • color_temperature: The color temperature of the white channel in mireds. Note that it is not clamped to the valid range as set in the traits, so the output needs to do this.

For COLD_WARM_WHITE capability:

  • cold_white, warm_white: The brightness of the light's cold and warm white channels.

All values (except color temperature) are represented using floats in the range 0.0 (off) to 1.0 (on), and are automatically clamped to this range. Properties not used in the current color mode can still have (invalid) values and must not be accessed by the light output.

Definition at line 95 of file light_color_values.h.

Constructor & Destructor Documentation

◆ LightColorValues() [1/2]

esphome::light::LightColorValues::LightColorValues ( )
inline

Construct the LightColorValues with all attributes enabled, but state set to off.

Definition at line 98 of file light_color_values.h.

◆ LightColorValues() [2/2]

esphome::light::LightColorValues::LightColorValues ( ColorMode color_mode,
float state,
float brightness,
float color_brightness,
float red,
float green,
float blue,
float white,
float color_temperature,
float cold_white,
float warm_white )
inline

Definition at line 111 of file light_color_values.h.

Member Function Documentation

◆ as_binary()

void esphome::light::LightColorValues::as_binary ( bool * binary) const
inline

Convert these light color values to a binary representation and write them to binary.

Definition at line 167 of file light_color_values.h.

◆ as_brightness()

void esphome::light::LightColorValues::as_brightness ( float * brightness) const
inline

Convert these light color values to a brightness-only representation and write them to brightness.

Definition at line 170 of file light_color_values.h.

◆ as_ct()

void esphome::light::LightColorValues::as_ct ( float color_temperature_cw,
float color_temperature_ww,
float * color_temperature,
float * white_brightness ) const
inline

Convert these light color values to a CT+BR representation with the given parameters.

Definition at line 243 of file light_color_values.h.

◆ as_cwww()

void esphome::light::LightColorValues::as_cwww ( float * cold_white,
float * warm_white,
bool constant_brightness = false ) const
inline

Convert these light color values to an CWWW representation with the given parameters.

Note on gamma and constant_brightness: This method operates on the raw/internal channel values stored in this object. For cold_white_ and warm_white_ specifically, these may already be gamma-uncorrected when derived from a color_temperature value. For constant_brightness=false, additional gamma for the output can be applied after this method since gamma commutes with simple multiplication. For constant_brightness=true, the caller (LightState::current_values_as_cwww) must apply gamma to the individual channel values BEFORE the balancing formula, because the nonlinear max/sum ratio does not commute with gamma. See LightState::current_values_as_cwww() for the correct implementation.

Definition at line 219 of file light_color_values.h.

◆ as_rgb()

void esphome::light::LightColorValues::as_rgb ( float * red,
float * green,
float * blue ) const
inline

Convert these light color values to an RGB representation and write them to red, green, blue.

Definition at line 173 of file light_color_values.h.

◆ as_rgbct()

void esphome::light::LightColorValues::as_rgbct ( float color_temperature_cw,
float color_temperature_ww,
float * red,
float * green,
float * blue,
float * color_temperature,
float * white_brightness ) const
inline

Convert these light color values to an RGB+CT+BR representation with the given parameters.

Definition at line 202 of file light_color_values.h.

◆ as_rgbw()

void esphome::light::LightColorValues::as_rgbw ( float * red,
float * green,
float * blue,
float * white ) const
inline

Convert these light color values to an RGBW representation and write them to red, green, blue, white.

Definition at line 185 of file light_color_values.h.

◆ as_rgbww()

void esphome::light::LightColorValues::as_rgbww ( float * red,
float * green,
float * blue,
float * cold_white,
float * warm_white,
bool constant_brightness = false ) const
inline

Convert these light color values to an RGBWW representation with the given parameters.

Definition at line 195 of file light_color_values.h.

◆ ESPHOME_LIGHT_UNIT_FIELDS_UNION()

esphome::light::LightColorValues::ESPHOME_LIGHT_UNIT_FIELDS_UNION ( )
protected

◆ get_blue()

float esphome::light::LightColorValues::get_blue ( ) const
inline

Get the blue property of these light color values. In range 0.0 to 1.0.

Definition at line 299 of file light_color_values.h.

◆ get_brightness()

float esphome::light::LightColorValues::get_brightness ( ) const
inline

Get the brightness property of these light color values. In range 0.0 to 1.0.

Definition at line 279 of file light_color_values.h.

◆ get_cold_white()

float esphome::light::LightColorValues::get_cold_white ( ) const
inline

Get the cold white property of these light color values. In range 0.0 to 1.0.

Definition at line 329 of file light_color_values.h.

◆ get_color_brightness()

float esphome::light::LightColorValues::get_color_brightness ( ) const
inline

Get the color brightness property of these light color values. In range 0.0 to 1.0.

Definition at line 284 of file light_color_values.h.

◆ get_color_mode()

ColorMode esphome::light::LightColorValues::get_color_mode ( ) const
inline

Get the color mode of these light color values.

Definition at line 265 of file light_color_values.h.

◆ get_color_temperature()

float esphome::light::LightColorValues::get_color_temperature ( ) const
inline

Get the color temperature property of these light color values in mired.

Definition at line 309 of file light_color_values.h.

◆ get_color_temperature_kelvin()

float esphome::light::LightColorValues::get_color_temperature_kelvin ( ) const
inline

Get the color temperature property of these light color values in kelvin.

Definition at line 314 of file light_color_values.h.

◆ get_green()

float esphome::light::LightColorValues::get_green ( ) const
inline

Get the green property of these light color values. In range 0.0 to 1.0.

Definition at line 294 of file light_color_values.h.

◆ get_red()

float esphome::light::LightColorValues::get_red ( ) const
inline

Get the red property of these light color values. In range 0.0 to 1.0.

Definition at line 289 of file light_color_values.h.

◆ get_state()

float esphome::light::LightColorValues::get_state ( ) const
inline

Get the state of these light color values. In range from 0.0 (off) to 1.0 (on)

Definition at line 270 of file light_color_values.h.

◆ get_warm_white()

float esphome::light::LightColorValues::get_warm_white ( ) const
inline

Get the warm white property of these light color values. In range 0.0 to 1.0.

Definition at line 334 of file light_color_values.h.

◆ get_white()

float esphome::light::LightColorValues::get_white ( ) const
inline

Get the white property of these light color values. In range 0.0 to 1.0.

Definition at line 304 of file light_color_values.h.

◆ is_on()

bool esphome::light::LightColorValues::is_on ( ) const
inline

Get the binary true/false state of these light color values.

Definition at line 272 of file light_color_values.h.

◆ lerp()

LightColorValues esphome::light::LightColorValues::lerp ( const LightColorValues & start,
const LightColorValues & end,
float completion )
static

Linearly interpolate between the values in start to the values in end.

This function linearly interpolates the color value by just interpolating every attribute independently.

Parameters
startThe interpolation start values.
endThe interpolation end values.
completionThe completion value. 0 -> start, 1 -> end.
Returns
The linearly interpolated LightColorValues.

Definition at line 10 of file light_color_values.cpp.

◆ normalize_color()

void esphome::light::LightColorValues::normalize_color ( )
inline

Normalize the color (RGB/W) component.

Divides all color attributes by the maximum attribute, so effectively set at least one attribute to 1. For example: r=0.3, g=0.5, b=0.4 => r=0.6, g=1.0, b=0.8.

Note that this does NOT retain the brightness information from the color attributes.

Parameters
traitsUsed for determining which attributes to consider.

Definition at line 147 of file light_color_values.h.

◆ operator!=()

bool esphome::light::LightColorValues::operator!= ( const LightColorValues & rhs) const
inline

Definition at line 262 of file light_color_values.h.

◆ operator==()

bool esphome::light::LightColorValues::operator== ( const LightColorValues & rhs) const
inline

Compare this LightColorValues to rhs, return true if and only if all attributes match.

Definition at line 256 of file light_color_values.h.

◆ set_blue()

void esphome::light::LightColorValues::set_blue ( float blue)
inline

Set the blue property of these light color values. In range 0.0 to 1.0.

Definition at line 301 of file light_color_values.h.

◆ set_brightness()

void esphome::light::LightColorValues::set_brightness ( float brightness)
inline

Set the brightness property of these light color values. In range 0.0 to 1.0.

Definition at line 281 of file light_color_values.h.

◆ set_cold_white()

void esphome::light::LightColorValues::set_cold_white ( float cold_white)
inline

Set the cold white property of these light color values. In range 0.0 to 1.0.

Definition at line 331 of file light_color_values.h.

◆ set_color_brightness()

void esphome::light::LightColorValues::set_color_brightness ( float brightness)
inline

Set the color brightness property of these light color values. In range 0.0 to 1.0.

Definition at line 286 of file light_color_values.h.

◆ set_color_mode()

void esphome::light::LightColorValues::set_color_mode ( ColorMode color_mode)
inline

Set the color mode of these light color values.

Definition at line 267 of file light_color_values.h.

◆ set_color_temperature()

void esphome::light::LightColorValues::set_color_temperature ( float color_temperature)
inline

Set the color temperature property of these light color values in mired.

Definition at line 311 of file light_color_values.h.

◆ set_color_temperature_kelvin()

void esphome::light::LightColorValues::set_color_temperature_kelvin ( float color_temperature)
inline

Set the color temperature property of these light color values in kelvin.

Definition at line 321 of file light_color_values.h.

◆ set_green()

void esphome::light::LightColorValues::set_green ( float green)
inline

Set the green property of these light color values. In range 0.0 to 1.0.

Definition at line 296 of file light_color_values.h.

◆ set_red()

void esphome::light::LightColorValues::set_red ( float red)
inline

Set the red property of these light color values. In range 0.0 to 1.0.

Definition at line 291 of file light_color_values.h.

◆ set_state() [1/2]

void esphome::light::LightColorValues::set_state ( bool state)
inline

Set the state of these light color values as a binary true/false.

Definition at line 276 of file light_color_values.h.

◆ set_state() [2/2]

void esphome::light::LightColorValues::set_state ( float state)
inline

Set the state of these light color values. In range from 0.0 (off) to 1.0 (on)

Definition at line 274 of file light_color_values.h.

◆ set_warm_white()

void esphome::light::LightColorValues::set_warm_white ( float warm_white)
inline

Set the warm white property of these light color values. In range 0.0 to 1.0.

Definition at line 336 of file light_color_values.h.

◆ set_white()

void esphome::light::LightColorValues::set_white ( float white)
inline

Set the white property of these light color values. In range 0.0 to 1.0.

Definition at line 306 of file light_color_values.h.

Field Documentation

◆ color_mode_

ColorMode esphome::light::LightColorValues::color_mode_
protected

Definition at line 344 of file light_color_values.h.

◆ color_temperature_

float esphome::light::LightColorValues::color_temperature_
protected

Color Temperature in Mired.

Definition at line 343 of file light_color_values.h.

◆ state_

float esphome::light::LightColorValues::state_
protected

ON / OFF, float for transition.

Definition at line 341 of file light_color_values.h.


The documentation for this class was generated from the following files: