Hello, I am using Esphome to control a CCT led strip that I have installed in a desk lamp. I can control it in Home Assistant and in the integration with Homekit, but I would like to control it with a button connected directly to the same Esp8266 since the lamp before connecting it to an ESP8266 could turn it on directly from the button.
I manage to control the on/off of the led strip from a button as long as I use the “monochromatic” platform, but then I lose the option to control the color temperature. As soon as I switch to the “cwww” platform it no longer works. I would like to continue using the “cwww” platform. Is there someone who can help me? I’m not very good with code, and I’m lost. This is the code I’ve been trying but I can’t get it to work.
esphome:
name: led-cct
esp8266:
board: nodemcuv2
# Enable logging
logger:
# Enable Home Assistant API
api:
ota:
password: "##################################"
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Led-Cct Fallback Hotspot"
password: "secret wifi_password"
captive_portal:
binary_sensor:
- platform: gpio
pin:
number: D7
mode: INPUT_PULLUP
inverted: yes
name: "Button"
on_click:
then:
- switch.toggle:
id: led_relay
switch:
- platform: gpio
pin:
number: D4
inverted: yes
id: led_relay_pin
restore_mode: ALWAYS_OFF
- platform: template
name: "led Relay"
icon: "mdi:fire"
id: led_relay
optimistic: true
lambda: 'return id(led_relay).state;'
turn_on_action:
- light.turn_on:
id: output_component1
- light.turn_off:
id: output_component2
- switch.turn_on:
id: led_relay_pin
turn_off_action:
- light.turn_off:
id: output_component1
- light.turn_on:
id: output_component2
- switch.turn_off:
id: led_relay_pin
light:
- platform: cwww
name: "Led Temperature Color"
cold_white: output_component1
warm_white: output_component2
cold_white_color_temperature: 6536 K
warm_white_color_temperature: 2000 K
constant_brightness: true
output:
- platform: esp8266_pwm
id: output_component1 #CW
pin: D2
- platform: esp8266_pwm
id: output_component2 #WW
pin: D1
inverted: false