Thanks Dave, I used the following instructions in my YAML file but I can’t get the sliders in HA to be correctly mapped, the pin assignment for the output_white is probably not right or something is missing. The “white value” slider seems inactive. What do you recommend reading to understand how to figure out the pins mapping?
I got my Kogan Lights working in esphome with the following config (after adapting your config and @kanga_who’s tasmota config from a few posts back):
I couldn’t get the colour temp slider to transition between the white LEDs and the RGB LEDs though. (Solved! see below)
light:
# merges the brightness slider and white level slider into one
- platform: custom
lambda: |-
auto light_out = new BetterRGBWLightOutput(id(red), id(green), id(blue), id(cold_white), id(warm_white));
App.register_component(light_out);
return {light_out};
lights:
- name: $display_name
default_transition_length: 500ms
sm16716:
data_pin: GPIO14
clock_pin: GPIO4
num_channels: 3
num_chips: 1
power_supply:
- id: rgb_power
pin: GPIO13
output:
- platform: sm16716
id: blue
channel: 0
power_supply: rgb_power
- platform: sm16716
id: green
channel: 1
power_supply: rgb_power
- platform: sm16716
id: red
channel: 2
power_supply: rgb_power
- platform: esp8266_pwm
id: warm_white
pin: GPIO5
- platform: esp8266_pwm
id: cold_white
pin: GPIO13
I also got the colour temperature to gradually switch between the RGB and main white LED light with the following modified BetterRGBWOutput code by user displaced:
/* A Better RGBW(W) Output
Based on/inspired by user *envy* at https://github.com/esphome/feature-requests/issues/212#issuecomment-498036079
And modified by *kabloomy* for Australian Kogan SmarterHome lights
Why?:
I have RGBWW (RGB + Cool-White + Warm-White) LED bulbs. After finding the correct PWM GPIOs to control each channel
and setting them up with esphome and HomeAssistant, I noticed the controls in HA were weird.
HA presented a brightness slider, colour temperature slider, 'white value' slider and an RGB picker.
The 'white value' and 'brightness' only worked to brighten/dim the CW/WW and RGB LEDs respectively. I wanted a single
'brightness' slider that worked no matter if the bulb was showing white or colour.
How?:
This output checks what the desired state is. If the RGB levels are equal, then the code turns off the RGB
LEDs and turns on the Cool and Warm LEDs. These levels set the white temperature, but not the brightness.
So, we also grab the brightness setting and multiply the CW/WW levels by it to get final levels for CW/WW.
If the desired RGB levels differ from eachother, then we know we want a coloured light. So, the code
turns off the CW/WW LEDs and sets the RGB levels as desired. We don't do a brightness multiplication here,
since that already seems to have been applied.
*/
#pragma once
#include "esphome.h"
class BetterRGBWLightOutput : public Component, public LightOutput {
public:
BetterRGBWLightOutput(FloatOutput *red, FloatOutput *green, FloatOutput *blue, FloatOutput *cold_white, FloatOutput *warm_white)
{
red_ = red;
green_ = green;
blue_ = blue;
cold_white_ = cold_white;
warm_white_ = warm_white;
}
LightTraits get_traits() override {
auto traits = LightTraits();
traits.set_supports_brightness(true);
traits.set_supports_rgb(true);
traits.set_supports_color_temperature(true);
traits.set_min_mireds(166);
traits.set_max_mireds(370);
return traits;
}
void write_state(LightState *state) override {
float red, green, blue, cold_white, warm_white, brightness;
state->current_values_as_rgbww(&red, &green, &blue, &cold_white, &warm_white);
state->current_values_as_brightness(&brightness);
if (red == green && red == blue && cold_white != 0)
{
// Cool white mode (RGB)
// the cold_white pin doesn't seem to exist in the Kogan lights...
// cold white is simulated with the RGB
this->red_->set_level(cold_white * brightness);
this->green_->set_level(cold_white * brightness);
this->blue_->set_level(cold_white * brightness);
this->cold_white_->set_level(0);
this->warm_white_->set_level(0.5 * warm_white * brightness);
}
else if (red == green && red == blue)
{
// Warm white mode
this->red_->set_level(0);
this->green_->set_level(0);
this->blue_->set_level(0);
this->cold_white_->set_level(0);
this->warm_white_->set_level(warm_white * brightness);
}
else
{
// RGB mode
this->red_->set_level(red);
this->green_->set_level(green);
this->blue_->set_level(blue);
this->cold_white_->set_level(0);
this->warm_white_->set_level(0);
}
}
protected:
FloatOutput *red_;
FloatOutput *green_;
FloatOutput *blue_;
FloatOutput *cold_white_;
FloatOutput *warm_white_;
};
The important bit there is the BASE: 48, using module 48 which has one channel for brightness and one for color temperature.
The product code is the same for old and new bulbs, I ran into it replacing older bulbs and couldn’t work out why the old template wasn’t working , gah!
Today I flashed a hihome smart switch (wpp 16s1) with tuyaconvert and esphome. Everything works but it shows the wrong voltages aprox 600 V… How do I calibrate this. I know I can do this with current_resistor and voltage_divider right? But what does these values say and how do I have to interpret them to calibrate the sensor.
My readings (I have an almost idle 2007 iMac running on Ubuntu plugged in, screen off, no GPU usage), the W seems to high for this computer (should be max 200W):