Hi,
I’m new here and also new in esphome. I found it very useful for making dumb devices smart very easy.
I integrated ESP-12 inside very big and high intensity bathroom lamp with 5 channel LEDs RGB-CW-WW. My goal is to make smart lamp which would be used as ambient lamp at night (from 21:00 to 4:00) and if I press button it will turn on on 100% 4500K from 6:00 to 20:00 and 50% 2700K from 20:00 to 6:00. If the light is turned on another short press turns it off (or ambient during night). Double click turns the lamp on full power. Third function (long press) changes or better said cycles colors (RGB) all on full power.
I already tried but I don’t have experiences with this type of programming. First problem is that I can’t use nested IF conditions. I tried with lambda but I always get some errors. I don’t even know how to check the state of “wc_light”. I would appreciate some help with this project.
time:
- platform: homeassistant
id: esptime
binary_sensor:
- platform: gpio
pin:
number: GPIO02
#mode: INPUT_PULLUP
inverted: true
name: button
on_multi_click:
- timing:
- ON for at most 1s
- OFF for at most 1s
- ON for at most 1s
- OFF for at least 0.2s
then:
- logger.log: "Double Clicked"
- light.turn_on:
id: wc_light
brightness: 100%
color_temperature: 4500K
- timing:
- ON for at least 1.5s
then:
- logger.log: "Long Press"
- light.turn_off: wc_light
- timing:
- ON for at most 1s
- OFF for at least 0.3s
then:
- logger.log: "Single Short Clicked"
- if:
condition:
- light.is_on: wc_light
#lambda: 'return id(esptime).now().second >= 30;'
then:
- light.turn_off: wc_light
else:
- light.turn_off: wc_light
- if:
condition:
- lambda: 'return id(esptime).now().hour >= 20 || id(esptime).now().hour <= 6;'
then:
lambda: |-
if(return id(wc_light).current_values.get_state()){
auto call = id(wc_light).make_call();
call.set_state(false);
call.perform();
} else {
static int color_temp = 370;
static int transition = 3000;
auto call = id(wc_light).make_call();
call.set_state(true);
call.set_color_temperature(color_temp);
call.set_transition_length(transition);
call.set_brightness(0.5);
call.perform();
}
else:
lambda: |-
static int color_temp = 255;
static int transition = 1000;
auto call = id(wc_light).make_call();
call.set_state(true);
call.set_color_temperature(color_temp);
call.set_transition_length(transition);
call.set_brightness(1.0);
call.perform();
light:
- platform: rgbww
name: "bathroom"
id: wc_light
red: pwm_red
green: pwm_green
blue: pwm_blue
cold_white: pwm_cw
warm_white: pwm_ww
cold_white_color_temperature: 6000 K
warm_white_color_temperature: 2700 K
constant_brightness: false
color_interlock: true
output:
- platform: esp8266_pwm
pin: GPIO12
frequency: 800 Hz
id: pwm_green
- platform: esp8266_pwm
pin: GPIO14
frequency: 800 Hz
id: pwm_red
- platform: esp8266_pwm
pin: GPIO04
frequency: 800 Hz
id: pwm_blue
- platform: esp8266_pwm
pin: GPIO13
frequency: 1000 Hz
id: pwm_ww
max_power: 100%
- platform: esp8266_pwm
pin: GPIO05
frequency: 1000 Hz
id: pwm_cw
max_power: 100%