Git Product home page Git Product logo

esphome-light-gradient's Introduction

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

esphome-light-gradient's People

Contributors

a0s avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.