HA 2021.8.1 - No custom light attributes

Hello,

I have an ESPHome device with a custom light component. This works well in HA 2021.7.4, however in HA 2021.8.1 there are no attributes for this custom light.

Below is the code for the custom light:

#pragma once

#include "esphome.h"

class KessilLight : public Component, public LightOutput {
    public:

    KessilLight(FloatOutput *brightness_output, FloatOutput *color_output)
    {
        brightness_output_ = brightness_output;
        color_output_ = color_output;
    }

    LightTraits get_traits() override {
        auto traits = LightTraits();
        traits.set_supports_brightness(true);
        traits.set_supports_color_temperature(false);
        traits.set_supports_rgb(false);
        traits.set_supports_rgb_white_value(true);
        return traits;
    }

    void write_state(LightState *state) override {
        float brightness, red, green, blue, white;
        // use any of the provided current_values methods
        state->current_values_as_rgbw(&red, &green, &blue, &white, this->color_interlock_);
        state->current_values_as_brightness (&brightness);
        white = white / brightness;
        if (brightness == 0)
                {
            this->brightness_output_->set_level(0);
            this->color_output_->set_level(0);
        }
        else
        {
            this->brightness_output_->set_level(brightness);
            this->color_output_->set_level(white);
        }
        
    }
    
    protected:
    FloatOutput *brightness_output_;
    FloatOutput *color_output_;
    bool color_interlock_;
};

In the ESPHome config file the custom light is added as follow:

esphome:
  name: reef_tank
  comment: Reef Tank Contoller
  platform: ESP8266
  board: d1_mini
  includes:
    - kessil.h

...

light:
  - platform: custom
    lambda: |-
      auto kessil_light = new KessilLight(id(reef_tank_light_brightness_pwm), id(reef_tank_light_color_pwm));
      App.register_component(kessil_light);
      return {kessil_light};
    lights:
      - name: "Reef Tank - Light"
        id: reef_tank_light
        gamma_correct: 1

In HA 2021.7.4 under the Developer Tools panel the following attributes are shown for this light:

supported_color_modes: rgbw
color_mode: rgbw
brightness: 181
hs_color: 0, 0
rgb_color: 255, 255, 255
rgbw_color: 255, 255, 255, 25
xy_color: 0.323, 0.329
white_value: 25
friendly_name: Reef Tank - Light
supported_features: 169

After upgrading to HA 2021.8.1 the following attributes are shown under the Developer Tools panel. Brightness and white cannot be adjusted anymore from the dashboard.

supported_color_modes: 
color_mode: unknown
friendly_name: Reef Tank - Light
supported_features: 8

I restored a snapshot from HA 2021.7.4 and everything was working as expected. I tried to upgrade again to HA 2021.8.1 and end up with the same issue (no attributes for the custom light).

Could you please help understand if this is an issue with HA 2021.8.1 or if there is something I should change in the custom light to be able to adjust brightness and white from HA 2021.8.1?

1 Like

The combination of set_supports_rgb(false); with set_supports_rgb_white_value(true); has never been supported by ESPHome, and it only worked (somewhat) by accident.

In your case I’d suggest to just use two monochromatic lights.

Thank you Oxan! That was indeed the issue. I changed set_supports_rgb(false); to set_supports_rgb(true); and all the attributes show up now.

supported_color_modes: rgbw
color_mode: rgbw
brightness: 153
hs_color: 0, 0
rgb_color: 255, 255, 255
rgbw_color: 255, 255, 255, 0
xy_color: 0.323, 0.329
friendly_name: Reef Tank - Light
supported_features: 40

I just need to find now a way to put this in the Lovelance dashboard showing only the brightness and white sliders and not the RGB wheel…

Before I had in the attributes the white_value: 25 while this is now not showing up anymore. I believe this is what is preventing me from showing the White Slider in the dashboard. What trait should I add to obtain the white_value attribute?

white_value doesn’t exist anymore, this is a change due to ESPHome adapting HA’s color modes. You should use rgbw_color instead.

I managed to work around this by creating a new external component that uses the brightness and temperature attributes.

v1.21 (next week) will have a built-in color_temperature light that should do what you want, without need for an external component. :slight_smile: