本帖最后由 土豪七 于 2025-1-14 11:12 编辑
下面是我用的配置,你参考下,按键少,但是灯不显示
esphome:
name: "gone2"
friendly_name: gone2
esp8266:
board: esp_wroom_02
restore_from_flash: yes ## 是否断电记忆继电器状态
# Enable logging
logger:
# Enable Home Assistant API
api:
encryption:
key: "iC09vSDBmHjO7lHYV5kguIKvXsf4qDPkGgpEjuXsJDk="
reboot_timeout: 0s #与客户端(如HA)失去连接多久后重启设备,秒s/分钟min/小时h,不需要此功能设置为0s
ota:
- platform: esphome
password: "123456789"
web_server: ## web控制,添加了这2行,就可以在网页端打开设备ip;
port: 80
wifi:
ssid: "L2701"
password: "123456789"
reboot_timeout: 0s #WiFi离线多久后重启设备,秒s/分钟min/小时h,不需要此功能设置为0s
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "gone2"
password: "123456789"
captive_portal:
switch:
- platform: gpio
pin: 14
id: "relay"
inverted: true
- platform: gpio
pin: 0
id: "yellow"
inverted: true
- platform: gpio
pin: 2
id: "blue"
inverted: true
- platform: gpio
pin: 15
id: "light"
- platform: gpio
pin: 12
id: "gpio12"
- platform: template
name: "guomei"
id: "guomei"
optimistic: true
turn_on_action:
then:
- switch.turn_on: relay
- switch.turn_on: gpio12
- switch.turn_off: gpio12
- switch.turn_on: yellow
turn_off_action:
then:
- switch.turn_off: relay
- switch.turn_on: gpio12
- switch.turn_off: gpio12
- switch.turn_off: yellow
binary_sensor:
- platform: gpio
id: "button"
pin: 13
filters:
- invert:
- delayed_on: 50ms
- delayed_off: 50ms
on_click:
- min_length: 50ms
max_length: 500ms
then:
- switch.toggle: guomei
sensor:
- platform: hlw8012
model: BL0937
sel_pin:
number: 16
inverted: true
cf_pin: 4
cf1_pin: 5
voltage_divider: 1314
current:
name: "Current"
voltage:
name: "Voltage"
power:
name: "Power"
energy:
name: "Energy"
#update_interval: 30s
interval:
- interval: 1s
then:
if:
condition:
wifi.connected:
then:
- if:
condition:
api.connected:
then:
if:
condition:
- switch.is_off: blue
then:
- switch.turn_on: blue
else:
- switch.turn_on: blue
- delay: 500ms
- switch.turn_off: blue
- delay: 500ms
else:
- switch.turn_on: blue
- delay: 200ms
- switch.turn_off: blue
- delay: 200ms
|