[Custom Light Component, need c++ advice] Athom 15W 1400lm RGBCCT Bulb

Dear Community,
i got the Athom 15W preflashed with tasmota from Aliexpress.
After flashing esphome I relaized that the warm white and cold white channel are split into color temperatur and brightness.

I have not much experience seting up the code in c++ to achive the correct behaiviour.

Here is what collected till now:

Tasmota Template: https://templates.blakadder.com/athom_LB01-15W-E27.html

Athom 15W GPIO Layout:

RGB:	Red: 4, Green: 12, Blue: 14
WW:		CT: 13, Brightness: 5

Some one on github already wrote a coustem light componet but that one is currently missing the RGB part.

The ESPFile yaml file could probably look something like this:

output:
  - platform: esp8266_pwm
    pin: GPIO13
    id: out_cw
  - platform: esp8266_pwm
    pin: GPIO5
    id: out_b
  - platform: esp8266_pwm
    pin: GPIO4
    id: out_red
  - platform: esp8266_pwm
    pin: GPIO12
    id: out_green
  - platform: esp8266_pwm
    pin: GPIO14
    id: out_blue


light:
  - platform: custom 
    lambda: |- 
      auto light_out = new Athom15w(id(out_cw),id(out_b),id(out_red),id(out_green),id(out_blue)); 
      App.register_component(light_out); 
      return {light_out}; 
    lights: 
      - name: "${friendly_name}"
        gamma_correct: 0

Now comes the c++ part I don’t know how to setup correctly (athom_15w.h)

#pragma once

#include "esphome.h"

class Athom15w : public Component, public LightOutput {
 public:
  Athom15w(FloatOutput *cw_white_color, FloatOutput *brightness)
    {
        cw_white_color_ = cw_white_color;
        brightness_ = brightness;
        cold_white_temperature_ = 175;
        warm_white_temperature_ = 333;
        constant_brightness_ = true;
    }
  LightTraits get_traits() override {
    auto traits = light::LightTraits();
    traits.set_supports_brightness(true);
    traits.set_supports_rgb(false);
    traits.set_supports_rgb_white_value(false);
    traits.set_supports_color_temperature(true);
    traits.set_min_mireds(this->cold_white_temperature_);
    traits.set_max_mireds(this->warm_white_temperature_);
    return traits;
  }

  void write_state(LightState *state) override {
    float brightness, cwhite, wwhite;
    state->current_values_as_cwww(&cwhite, &wwhite, this->constant_brightness_);
//    ESP_LOGD("custom", "The value cwhite: %f", cwhite);
//    ESP_LOGD("custom", "The value wwhite: %f", wwhite);
    state->current_values_as_brightness(&brightness);
//    ESP_LOGD("custom", "The value brightness: %f", brightness);
    this->cw_white_color_->set_level(cwhite+(1-brightness));
    this->brightness_->set_level(brightness);
  }
  protected:
    FloatOutput *cw_white_color_;
    FloatOutput *brightness_;
    float cold_white_temperature_;
    float warm_white_temperature_;
    bool constant_brightness_;
};

Can someone help to correct the code?

Thank you.

We finally managed to get a working esphome configuration for this bulb here is the code. :wink:

If someone bricked their bulb here is the GPIO Layout of the “AJW03S” for serial flashing


That pinout just absolutely saved my bacon after I bricked my bulb trying to install the ESPHome config that Athom provide on Github and had to get the soldering iron out for a serial flash. Thank you!

My config is:

substitutions:
  name: "corner"
  friendly_name: "Corner"
  light_restore_mode: RESTORE_DEFAULT_ON
  color_interlock: 'true'
    
esphome:
  name: "${name}"

esp8266:
  board: esp8285
  restore_from_flash: true

preferences:
  flash_write_interval: 1min

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  domain: .internal

# Enable logging
logger:
  level: DEBUG

# Enable Home Assistant API
api:

ota:

mdns:
  disabled: false

output:
  - platform: esp8266_pwm
    id: red_output
    pin: GPIO4
  - platform: esp8266_pwm
    id: green_output
    pin: GPIO12
  - platform: esp8266_pwm
    id: blue_output
    pin: GPIO14
  - platform: esp8266_pwm
    id: white_output
    pin: GPIO5
  - platform: esp8266_pwm
    id: ct_output
    inverted: true
    pin: GPIO13

light:
  - platform: rgbct
    id: rgbct_light
    name: "${friendly_name}"
    restore_mode: ${light_restore_mode}
    red: red_output
    green: green_output
    blue: blue_output
    white_brightness: white_output
    color_temperature: ct_output
    cold_white_color_temperature: 6000K
    warm_white_color_temperature: 3000K
    color_interlock: ${color_interlock}

1 Like