Skip to content

An example how to create gradient with regular FastLED and Home Assistant

License

Notifications You must be signed in to change notification settings

a0s/esphome-light-gradient

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ESPHome Light Gradient 🌈

An example how to create color (or brightness) gradient with regular FastLED and Home Assistant (HASS)

Devices

In both devices, I was forced to replace their native controllers (Tuya and Magic Home) with regular esp8266. No additional power tricks were needed. Both devices use ws2812b, or their clones. The pinout was determined with the help of an oscilloscope.

How it works

In the current solution, each device in the HASS interface is represented by three entities. Two RGB Lights are used to determine the color at the beginning and end of the gradient. The Template Select is employed to switch between different operating modes of the LED strip, as well as to turn it off.

HASS entity list

Screenshot 2023-05-24 at 00 26 45Screenshot 2023-05-24 at 00 26 30

The RGB Light isn't real, we're just using this entity as an interface for color selection on the HASS side. To use it, we need a fake output:

esphome:
  includes:
    - esphome/NullOutputComponent.h
output:
  - platform: custom
    type: float
    lambda: |-
      auto my_output = new NullOutputComponent();
      App.register_component(my_output);
      return {my_output};
    outputs:
      id: null_output_float

⚠️ To be able to set a specific color for each LED, we use Addressable Light over FastLED Light. Addressable Light supports so-called pages, on which different content can be presented. It's these pages that we switch using Template Select. All the magic of rendering happens in the description of the pages. The RGB Lights are used as a color source for the start and end of the gradient.

The LED strip is defined using fastled_clockless. The restore_mode: ALWAYS_ON mode is used so as not to interfere with the operation of addressable_light.

Don't forget to update the mosaic_leds_count variable with the actual number of LEDs. Also, update the GPIO pin to the one you are using.

Disadvantages

  • To control one light source, you need to visit three popup dialogs in HASS. Here, scenes help a little.
  • To control two different light sources, you need to have a full copy of the source codes with differing IDs. This is quite error-prone when copy-pasting.
  • It's impossible to adequately control the colors from the ESPHome web interface. The necessary controls are simply not available: Screenshot 2023-05-24 at 10 59 43

About

An example how to create gradient with regular FastLED and Home Assistant

Topics

Resources

License

Stars

Watchers

Forks

Languages