GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing esphome.io — Light Component Light ComponentIn ESPHome, This component can restore its state on reboot/reset if configured to do so. Base Light ConfigurationSection titled “Base Light Configuration”All light configuration schemas inherit these options. Configuration variablesSection titled “Configuration variables”
NOTE If you have a friendly_name set for your device and you want the light
to use that name, you can set
Additional configuration variables for addressable lights:
Advanced options:
Light stateSection titled “Light state”Some actions/configuration refer to light state. A light state may consist of any of the following configuration variables:
All percentage options accept values in the range Light AutomationsSection titled “Light Automations”Section titled “light.toggle Action” |
| Chipset | Red (mA) | Green (mA) | Blue (mA) |
|---|---|---|---|
| WS2812B | 16 | 11 | 15 |
| SK6812 | 12 | 12 | 12 |
| APA106 | 16 | 14 | 12 |
NOTE
These are rough guideline values. For accurate power budgeting, measure your specific strip.
light.is_on / light.is_off ConditionThis Condition checks if the given light is ON or OFF. OFF means that the light is completely OFF, and ON means that the light is emitting at least a bit of light.
# In some trigger:on_...: if: condition: # Same syntax for is_off light.is_on: my_lightlight.on_turn_on / light.on_turn_off TriggerThis trigger is activated each time the light is turned on or off. It is consistent with the behavior of the
light.is_on and light.is_off condition above.
light: - platform: binary # or any other platform # ... on_turn_on: - logger.log: "Light Turned On!" on_turn_off: - logger.log: "Light Turned Off!"light.on_state TriggerThis trigger is activated each time the set light state is changed. It is not triggered based on current state, but
rather, it triggers on the set state which can differ from the current state due to transitions. For example, the
light.on_state trigger can be used for immediate action when the light is set to off; while light.on_turn_off
does not trigger until the light actually achieves the off state.
light: - platform: binary # or any other platform # ... on_state: - logger.log: "Light State Changed!"ESPHome has several built-in/pre-defined light effects you can use for your lights. The defaults for the effect parameters are made to work well on their own, but ESPHome also allows you to manually change these parameters.
Each effect you define in ESPHome will appear as an entry in the effects dropdown for the light in Home Assistant. If you wish to have several variants of the same effect, you can create multiple entries, each having a unique name:
light: - platform: ... # ... effects: # Use default parameters: - random: # Customize parameters - random: name: "My Slow Random Effect" transition_length: 30s update_interval: 30s - random: name: "My Fast Random Effect" transition_length: 4s update_interval: 5sNOTE
After setting a light effect, it is possible to reset the in-use effect back to a static light by setting the
effect to none when it is being called through Home Assistant or directly on the device.
These effects work on any light platform.
| Preview | Effect | Description | Parameters |
|---|---|---|---|
| Pulse | Smooth brightness pulse | name, transition_length, update_interval, min_brightness, max_brightness | |
| Random | Random colors at fixed intervals | name, transition_length, update_interval | |
| Strobe | Cycle through a list of colors with set durations | name, colors | |
| Flicker | Candle-like brightness variation | name, alpha, intensity | |
| Lambda | Run custom C++ on each update | name, update_interval, lambda |
These effects require an addressable light (LED strip).
| Preview | Effect | Description | Parameters |
|---|---|---|---|
| Addressable Rainbow | Hue sweeps the length of the strip | name, speed, width | |
| Addressable Color Wipe | New colors shift in at the start of the strip | name, colors, add_led_interval, reverse | |
| Addressable Scan | Single dot slides back and forth across the strip | name, move_interval, scan_width | |
| Addressable Twinkle | Random pixels brighten and fade | name, twinkle_probability, progress_interval | |
| Addressable Random Twinkle | Twinkle, but each pixel gets a random color | name, twinkle_probability, progress_interval | |
| Addressable Fireworks | Sparks burst from random pixels | name, update_interval, spark_probability, use_random_color, fade_out_rate | |
| Addressable Flicker | Per-pixel candle flicker | name, update_interval, intensity | |
| Addressable Lambda | Run custom C++ per LED | name, update_interval, lambda |
These effects receive frames from an external source instead of generating animation locally.
| Effect | Description | Parameters |
|---|---|---|
| Automation | Run ESPHome automation actions on a loop | name, sequence |
| E1.31 | Receive sACN / E1.31 frames over the network | universe, channels |
| Adalight | Receive Adalight protocol over UART | uart_id |
| WLED | Receive WLED UDP sync protocol | port, blank_on_start, sync_group_mask |
This effect makes a pulsating light. The period can be defined by update_interval, the transition length with
transition_length. transition_length should be set to less than update_interval, setting
transition_length to 1s and update_interval to 2s will result in a transition from 0% to 100% lasting
1 second, 1 second full light, a transition from 100% to 0% for 1 second and off for 1 second.
light: - platform: ... # ... effects: - pulse: - pulse: name: "Fast Pulse" transition_length: 0.5s update_interval: 0.5s min_brightness: 0% max_brightness: 100% - pulse: name: "Slow Pulse" transition_length: 500ms update_interval: 2s - pulse: name: "Asymmetrical Pulse" transition_length: on_length: 1s off_length: 500ms update_interval: 1.5sConfiguration variables:
name (Optional, string): The name of the effect. Defaults to Pulse.
transition_length (Optional, Time): The duration of each transition. Defaults to 1s. Can be a
single time or split for on and off using these nested options.
update_interval (Optional, Time): The interval when the new transition is started. Defaults to
1s.
min_brightness (Optional, percentage): The minimum brightness value. Defaults to 0%
max_brightness (Optional, percentage): The maximum brightness value. Defaults to 100%
This effect makes a transition (of length transition_length ) to a randomly-chosen color and/or brightness (for
monochromatic) every update_interval.
light: - platform: ... # ... effects: - random: - random: name: Random Effect With Custom Values transition_length: 5s update_interval: 7sConfiguration variables:
Random.5s.This effect cycles through a list of colors with specific durations.
light: - platform: ... # ... effects: - strobe: - strobe: name: Strobe Effect With Custom Values colors: - state: ON brightness: 100% red: 100% green: 90% blue: 0% duration: 500ms - state: OFF duration: 250ms - state: ON brightness: 100% red: 0% green: 100% blue: 0% duration: 500ms - state: ON color: darkred duration: 500msConfiguration variables:
name (Optional, string): The name of the effect. Defaults to Strobe.
colors (Optional, list): A list of colors to cycle through. Defaults to a quick cycle between ON and OFF.
state (Optional, boolean): The ON/OFF state to show. Defaults to ON.
color_mode (Optional, string): The color mode of the light. Defaults to the current color mode.
brightness (Optional, percentage): The brightness of the light. Defaults to 100%.
color_brightness (Optional, percentage): The brightness of the RGB lights, if applicable. Defaults to 100%.
red (Optional, percentage): The red channel of the light, if applicable. Defaults to 100%.
green (Optional, percentage): The green channel of the light, if applicable. Defaults to 100%.
blue (Optional, percentage): The blue channel of the light, if applicable. Defaults to 100%.
color (Optional, string or hex value): A
standard CSS color name or a hex value in the
form 0xRRGGBB to use instead of red, green and blue. Also sets color_brightness, as described
in light state.
white (Optional, percentage): The white channel of the light, if applicable. Defaults to 100%.
color_temperature (Optional, float): The color temperature (in mireds or Kelvin) of the light, if applicable.
cold_white (Optional, percentage): The cold white channel of the light, if applicable. Defaults to 100%.
warm_white (Optional, percentage): The warm white channel of the light, if applicable. Defaults to 100%.
duration (Required, Time): The duration this color should be active.
transition_length (Optional, Time): The duration of each transition. Defaults to 0s.
See light state for more information on the various color fields.
This effect applies random variations to the brightness and all color channels which “hover” around the active color of the light. The default values simulate a gentle candle flicker, but with different settings it can produce subtle color shifts or chaotic sparkly noise.
light: - platform: ... # ... effects: - flicker: - flicker: name: Flicker Effect With Custom Values alpha: 95% intensity: 1.5%Configuration variables:
name (Optional, string): The name of the effect. Defaults to Flicker.
alpha (Optional, percentage): A smoothing factor that controls how much “memory” the flicker has. A high value makes the flicker’s next step very similar to its last, which smooths out changes. A low value mixes more of the new value, resulting in rapid changes. Defaults to 95%.
intensity (Optional, percentage): The magnitude of the random change applied at each step. As the changes are applied across color channels, higher values produce more visible shifts. Defaults to 1.5%.
This effect allows you to write completely custom light effects yourself using lambdas.
Available variables in the lambda:
it: API Reference: LightState instance for the light running this effect, allowing
you to reference the light directly without needing its id (see API reference for more info).initial_run: A bool which is true on the first execution of the lambda. Useful to reset static variables when
restarting an effect.light: - platform: ... # ... effects: - lambda: name: My Custom Effect update_interval: 1s lambda: |- static int state = 0; auto call = it.turn_on(); // Transition of 1000ms = 1s call.set_transition_length(1000); if (state == 0) { call.set_rgb(1.0, 1.0, 1.0); } else if (state == 1) { call.set_rgb(1.0, 0.0, 1.0); } else if (state == 2) { call.set_rgb(0.0, 0.0, 1.0); } else { call.set_rgb(1.0, 0.0, 0.0); } call.perform(); state += 1; if (state == 4) state = 0;Configuration variables:
name (Optional, string): The name of the custom effect. Defaults to Lambda.
update_interval (Optional, Time): The interval with which the lambda code is executed. A value of
0ms means that the lambda is always executed, without a cool-down. Defaults to 0ms.
lambda (Required, lambda): The code to execute. static variables are especially
useful.
You can access the name of a light effect using the get_name() method, which returns a StringRef:
// Get all effects for a lightauto &effects = id(my_light).get_effects();for (auto *effect : effects) { StringRef name = effect->get_name(); // Compare with string literal if (name == "My Custom Effect") { ESP_LOGI("light", "Found my effect!"); } // Safe logging with explicit size ESP_LOGI("light", "Effect: %.*s", (int) name.size(), name.c_str());}You can also get the currently active effect name from a light state using get_effect_name():
// Get currently active effectStringRef current = id(my_light).get_effect_name();if (current == "None") { ESP_LOGI("light", "No effect active");} else { ESP_LOGI("light", "Active effect: %.*s", (int) current.size(), current.c_str());}A light effect for individually-addressable LEDs that creates a moving rainbow over the whole LED strip using the HSV color wheel.
light: - platform: ... # ... effects: - addressable_rainbow: - addressable_rainbow: name: Rainbow Effect With Custom Values speed: 10 width: 50Configuration variables:
Rainbow.10.50.A light effect for individually-addressable LEDs that continuously introduces new colors at the beginning of the strip
and shifts them forward every add_led_interval.
light: - platform: ... # ... effects: - addressable_color_wipe: - addressable_color_wipe: name: Color Wipe Effect With Custom Values colors: - red: 100% green: 100% blue: 100% num_leds: 5 gradient: true - red: 0% green: 0% blue: 0% num_leds: 1 - color: darkred num_leds: 1 add_led_interval: 100ms reverse: falseConfiguration variables:
name (Optional, string): The name of the effect. Defaults to Color Wipe.
colors (Optional, list): The colors to shift in at the beginning of the strip. Defaults to shifting in random colors.
red (Optional, percentage): The percentage the red color channel should be on. Defaults to 100%.
green (Optional, percentage): The percentage the green color channel should be on. Defaults to 100%.
blue (Optional, percentage): The percentage the blue color channel should be on. Defaults to 100%.
color_brightness (Optional, percentage): A brightness to scale red, green and blue by.
Defaults to 100%.
color (Optional, string or hex value): A
standard CSS color name or a hex value in the
form 0xRRGGBB to use instead of red, green and blue. Also sets color_brightness, as described
in light state.
random (Optional, boolean): If set to true, will overwrite the RGB colors by a new, randomly-chosen
color each time. Defaults to false.
num_leds (Required, positive int): The number of LEDs of this type to have before transitioning to the next
color. If gradient is true, this will be the number of LEDs over which the color transition will occur.
gradient (Optional, boolean): If true the current color will transition with a gradient over num_leds
to the next color. Defaults to false.
add_led_interval (Optional, Time): The interval with which to shift in new LEDs at the beginning
of the strip. Defaults to 100ms.
reverse (Optional, boolean): Whether to reverse the direction of the color wipe. Defaults to false.
Creates a single, fast-moving dot “sliding” back and forth on the LED strip. The color is chosen by the currently active light color.
light: - platform: ... # ... effects: - addressable_scan: - addressable_scan: name: Scan Effect With Custom Values move_interval: 100ms scan_width: 1Configuration variables:
name (Optional, string): The name of the effect. Defaults to Scan.
move_interval (Optional, Time): The interval with which to move the dot/line one LED forward.
Defaults to 100ms.
scan_width (Optional, int): The number of LEDs to use. Defaults to 1.
Randomly chooses LEDs and brightens them for a moment, mimicking stars twinkling in the night sky. The color of the pixels is determined by the current light color.
light: - platform: ... # ... effects: - addressable_twinkle: - addressable_twinkle: name: Twinkle Effect With Custom Values twinkle_probability: 5% progress_interval: 4msConfiguration variables:
name (Optional, string): The name of the effect. Defaults to Twinkle.
twinkle_probability (Optional, percentage): The percentage with which, at any time step, a randomly-chosen LED should start its twinkle animation.
progress_interval (Optional, Time): The interval with which to progress the effect. This affects
the duration of a twinkle animation. Defaults to 4ms.
A light effect similar to addressable_twinkle, but using random colors for each twinkle animation.
light: - platform: ... # ... effects: - addressable_random_twinkle: - addressable_random_twinkle: name: Random Twinkle Effect With Custom Values twinkle_probability: 5% progress_interval: 32msConfiguration variables:
name (Optional, string): The name of the effect. Defaults to Random Twinkle.
twinkle_probability (Optional, percentage): The percentage with which, at any time step, a randomly-chosen LED should start its twinkle animation.
progress_interval (Optional, Time): The interval with which to progress the effect. This affects
the duration of a twinkle animation. Defaults to 4ms.
A light effect for individually-addressable LED strips that randomly sparks some fireworks at random positions and lets the sparkles cascade over the LED strip.
light: - platform: ... # ... effects: - addressable_fireworks: - addressable_fireworks: name: Fireworks Effect With Custom Values update_interval: 32ms spark_probability: 10% use_random_color: false fade_out_rate: 120Configuration variables:
name (Optional, string): The name of the effect. Defaults to Fireworks.
update_interval (Optional, Time): The interval with which to progress the effect. Defaults to
32ms.
spark_probability (Optional, percentage): The probability to start a new firework spark at a randomly-chosen
LED at any given time step. Defaults to 10%.
use_random_color (Optional, boolean): Whether to use random colors for new firework sparks. Defaults to using the currently active light color.
fade_out_rate (Optional, int): The rate with which to fade out the LED strip, unitless. Needs to be carefully
chosen so that the whole strip doesn’t light up forever if the fade out rate is too low or that the firework
sparks do not propagate for a long time. Defaults to 120.
An effect similar to the flicker effect, but for individually-addressable LED strips. This effect flickers each LED
by its own random amount around the currently active light color.
light: - platform: ... # ... effects: - addressable_flicker: - addressable_flicker: name: Flicker Effect With Custom Values update_interval: 16ms intensity: 5%Configuration variables:
name (Optional, string): The name of the effect. Defaults to Addressable Flicker.
update_interval (Optional, Time): The time interval for updating the random offsets. Defaults to
16ms.
intensity (Optional, percentage): The intensity of the effect, basically how much the random values can offset
the currently active light color. Defaults to 5%.
This effect allows you to access each LED individually in a custom light effect.
Available variables in the lambda:
it: API Reference: AddressableLight instance (see API reference for more info).current_color: API Reference: ESPColor instance (see API reference for more info).initial_run: A bool which is true on the first execution of the lambda. Useful to reset static variables when
restarting an effect.NOTE
ESPColor has been migrated to Color. See API Reference: Color for more information.
light:- platform: ... effects: - addressable_lambda: name: "My Custom Effect" update_interval: 16ms lambda: |- // it.size() - Number of LEDs // it[num] - Access the LED at index num. // Set the LED at num to the given r, g, b values // it[num] = Color(r, g, b); // Get the color at index num (Color instance) // it[num].get();
// Example: Simple color wipe for (int i = it.size() - 1; i > 0; i--) { it[i] = it[i - 1].get(); } it[0] = Color::random_color();
// Bonus: use .range() and .all() to set many LEDs without having to write a loop. it.range(0, 50) = Color::BLACK; it.all().fade_to_black(10);light:- platform: ... effects: - addressable_lambda: name: "My Custom Effect" update_interval: 16ms lambda: |- // Static variables keep their value even when // stopping and starting the effect again static uint16_t progress = 0;
// normal variables lose their value after each // execution - basically after each update_interval uint16_t changes = 0;
// To reset static when stopping and starting the effect // again you can use the initial_run variables if (initial_run) { progress = 0; it.all() = Color::BLACK; // optionally do a return so nothing happens until the next update_interval return; }Examples of this API can be found in the source code (the built-in addressable light effects).
In addition to the lambda and addressable_lambda light effects, effects can also be created with ESPHome’s
Automation system with the automation effect type.
The automation given in the sequence block will be repeatedly executed until the effect is stopped by the user.
light:- platform: ... id: my_light effects: - automation: name: Custom Automation Effect sequence: - light.addressable_set: id: my_light red: 100% green: 100% blue: 100% - delay: 100ms - light.addressable_set: id: my_light range_from: 0 range_to: 20 red: 100% green: 0% blue: 0%Configuration variables:
This effect enables controlling addressable lights by way of the UDP-based E1.31 protocol.
For example, when enabled, JINX or Hyperion.NG could be used to control the LEDs connected to the ESPHome device.
e131: method: multicast # default: register E1.31 to Multicast group
light: - platform: neopixelbus num_leds: 189 effects: - e131: universe: 1 channels: RGBConfiguration variables:
MONO, RGB or RGBW light
and in which order the colors are. Defaults to RGB.There are three modes of operation:
MONO : this supports 1 channel per LED (luminance), up-to 512 LEDs per universeRGB : this supports 3 channels per LED (RGB), up-to 170 LEDs (3*170 = 510 bytes) per universeRGBW : this supports 4 channels per LED (RGBW), up-to 128 LEDs (4*128 = 512 bytes) per universeIf there are more LEDs than allowed per universe, an additional universe will be used. In the above example of 189 LEDs, first 170 LEDs will be assigned to universe 1, while the remaining 19 LEDs will be assigned to universe 2.
It is possible to enable multiple light platforms to concurrently listen to the same universe, allowing the behavior to be replicated on multiple strips.
The E1.31 Effect requires a component hub for the e131 light effect.
Configuration variables:
multicast or unicast. Defaults to multicast.ESPHome will listen on UDP port 5568.
This effect enables controlling addressable lights using the serial Adalight protocol, allowing the creation of realtime ambient lighting effects.
Prismatik can be used to control addressable lights via Adalight protocol on ESPHome.
# Example configuration entry# Disable logging over USBlogger: baud_rate: 0
# Adalight requires higher RX buffer size# to operate without flickeringuart: rx_buffer_size: 1024
adalight:
light: - platform: neopixelbus ... effects: - adalight: # uart_id: additional_uartConfiguration variables:
This effect enables controlling addressable lights using the UDP Realtime Control protocol used by WLED, allowing
creation of realtime ambient lighting effects.
Prismatik and/or LedFx can be used to control addressable lights over the network on ESPHome. Use the connection type
udp on the default port and add the data prefix 0201.
wled:
light: - platform: neopixelbus ... effects: - wled: # port: 21324 # blank_on_start: True # sync_group_mask: 0Configuration variables:
21324.True.0 (All Sync Groups). Sync Groups 1, 2, 3, 4, 5, 6, 7, 8 use masks 1, 2, 4,
8, 16, 32, 64, 128. Combine mask values to listen to multiple Sync Groups.NOTE
You can also set the port to 19446 for compatibility with Hyperion Classic using a UDP device with protocol 0.
The following realtime protocols are supported: