feature-requests icon indicating copy to clipboard operation
feature-requests copied to clipboard

Support arbitrary light for status_led

Open maruel opened this issue 3 years ago • 14 comments

Describe the problem you have/What new integration you would like

The M5Stack Pico mate has a SK6812 LED onboard but no other LED. So it is impossible to use the status_led light component.

M5Stack Pico

Please describe your use case for this integration and alternatives you've tried:

It'd be nice if we could use the onboard RGB led as a status LED.

I think it'd be better to simply make status_led more generic than do a one-off to support a SK6812 specifically.

Additional context

I took a quick look at the code and there's no way at the moment hook events when STATUS_LED_ERROR or STATUS_LED_WARNING are set. I suspect this feature request would require some deep internal refactoring inside https://github.com/esphome/esphome/blob/dev/esphome/core/component.cpp.

maruel avatar Jan 18 '22 21:01 maruel

Addressable light?

nagyrobi avatar Jan 20 '22 21:01 nagyrobi

For this specific board, it's indeed an addressable light of one LED. :)

maruel avatar Jan 20 '22 21:01 maruel

In theory you should be able to set it up using addressable_light platform...

nagyrobi avatar Jan 20 '22 21:01 nagyrobi

I don't understand; https://esphome.io/components/light/status_led.html implies a binary light. I want a RGB one.

The alternative would be global events something like on_error but looking at the code it doesn't exist in the way that would enable the same experience.

maruel avatar Jan 20 '22 21:01 maruel

You could make an addressable lambda that uses App.get_app_state() which returns the uint32_t you can then use to change the light

jesserockz avatar Jan 20 '22 23:01 jesserockz

Thank you so much @jesserockz! I totally missed this. Will try tomorrow.

maruel avatar Jan 21 '22 02:01 maruel

It's a bit verbose and does complexify my config files but I think this is enough of a good workaround to not need an actual change in esphome, at least unless there's a larger variety of boards with RGB LEDs. I'm fine if you want to close as wontfix.

Note: I have not yet tested the error modes in the following;

esphome:
  (...)
  on_loop:
    then:
      lambda: |-
        static uint32_t last_state = 0;
        auto state = App.get_app_state();
        if (state != last_state) {
          if (state & STATUS_LED_ERROR) {
            auto call = id(led).turn_on();
            call.set_effect("ERROR");
            call.perform();
          } else if (state & STATUS_LED_WARNING) {
            auto call = id(led).turn_on();
            call.set_effect("BOOT");
            call.perform();
          } else {
            auto call = id(led).turn_off();
            call.perform();
          }
          last_state = state;
        }

ota:
  password: !secret ota_password
  on_begin:
    # Doesn't work as expected, https://github.com/esphome/issues/issues/2967
    then:
      - light.control:
          id: led
          state: on
          brightness: 100%
          red: 100%
          green: 0%
          blue: 100%
  on_error:
    then:
      - light.control:
          id: led
          state: on
          effect: ERROR

light:
  - platform: fastled_clockless
    id: led
    name: "LED"
    pin: 27
    chipset: WS2812
    num_leds: 1
    rgb_order: GRB
    restore_mode: ALWAYS_OFF
    effects:
      - lambda:
          name: "ERROR"
          update_interval: 0.5s
          lambda: |-
            static bool state = false;
            auto call = id(led).turn_on();
            call.set_transition_length(500);
            call.set_rgb(1, 0, 0);
            if (!state) {
              call.set_brightness(1);
            } else {
              // If using 0, it freaks Home Assistant UI.
              call.set_brightness(0.01);
            }
            call.perform();
            state = !state;
      - lambda:
          name: "BOOT"
          update_interval: 0.5s
          lambda: |-
            static bool state = false;
            auto call = id(led).turn_on();
            call.set_transition_length(500);
            call.set_rgb(0, 1, 0);
            if (!state) {
              call.set_brightness(1);
            } else {
              // If using 0, it freaks Home Assistant UI.
              call.set_brightness(0.01);
            }
            call.perform();
            state = !state;

maruel avatar Jan 22 '22 00:01 maruel

I still think its a good idea to allow status_light to utilize rgb etc natively so wont close this FR. I have C3 board which do also have an rgb onboard so I might get to it at some point. Just wanted to give you a path forward for now =)

jesserockz avatar Jan 22 '22 00:01 jesserockz

Thanks! I didn't want to put undue burden on the team for what could have been interpreted as a one-off. Sounds good.

maruel avatar Jan 22 '22 01:01 maruel

This would also be great for the m5stack Atom Lite 👍

Tuckie avatar Jan 22 '22 04:01 Tuckie

You can do this now using a template output with the status_led as described in #2230.

ssieb avatar Jul 24 '23 20:07 ssieb

unless there's a larger variety of boards with RGB LEDs

Its basically all boards from M5Stack.

iBobik avatar Jan 26 '24 13:01 iBobik

Have a look at this component: https://github.com/esphome/esphome/pull/5814 this allows you to config how want to see most important statuses and you can add your own statuses as well and fire them as well,

nielsnl68 avatar Jan 26 '24 20:01 nielsnl68

Hey, I was also working on the status LED and created a package. Maybe it helps you too guys:
ESPHome_RGB-Status-LED_Package

💡 LED Colors and States

System States

The LED system status follows a strict top-down priority. The highest matching state always wins. If a condition is no longer fulfilled, the LED falls back to the previous applicable state.

Priority Color + Effect System State Notes
1 Red
fast pulsing
Booting / initialization Shown before WiFi stack is ready
2 Yellow
static
Boot completed Waiting for WiFi / network issue?
3 White
static
WiFi connected network OK, Home Assistant not connected
4 Green
static
Home Assistant connected FULLY STARTED - Normal operating mode

Custom States

Additionally there are LED working states provided, which can be triggered from your main device configuration. They are meant to signals states separate from the main priority logic. They temporarily override the LED as long as the script is active, similar to the beacon state.

Script ID Color + Effect Notes (Examples)
led_working_status_1 Blue
slow pulsing
Example: device performing a background task; BT-beacon detected; etc.
led_working_status_2 Purple
slow pulsing
Example: special output is turned on; long-running I²C read; etc.
led_working_status_* add more if you like

To set and reset the working light you can call the following scripts:

  • - script.execute: led_working_status_1 (or any other number)
  • - script.execute: led_system_status (to reset the LED to the system-status)

🛠️ Set Up

Add the package to your device configuration:

packages:
  rgb_status_led: 
    url: https://github.com/Flo-R1der/ESPHome_RGB-Status-LED_Package
    file: status_led_package.yaml

Make sure your project defines the required GTB LED light with the ID system_status_led. The following light configuration has proven to work on a LOLIN C3 Mini (board: lolin_c3_mini):

light:
  - platform: esp32_rmt_led_strip
    id: system_status_led             # DO NOT CHANGE
    pin: GPIO7                        # check your board
    rgb_order: GRB                    # check your board
    num_leds: 1
    chipset: ws2812                   # check your board
    name: "onboard LED"
    disabled_by_default: true
    default_transition_length: 200ms
    icon: mdi:led-outline
    restore_mode: ALWAYS_OFF
    effects:
      - pulse:
          name: "Slow Pulse"          # REQUIRED
          update_interval: 2s         # can be adjusted
      - pulse:
          name: "Fast Pulse"          # REQUIRED
          update_interval: 500ms      # can be adjusted

[!NOTE]
The package does not depend on any specific LED chipset or ESP32 variant.
If you prefer another LED type (NeopixelBus, FastLED, CWWW RGB LED), simply keep the ID identical.

Flo-R1der avatar Nov 16 '25 22:11 Flo-R1der