灌水,来自chatGPT,仅供参考。
esphome:
name: 插座名称
platform: ESP8266
board: esp01_1m
wifi:
ssid: "您的WiFi名称"
password: "您的WiFi密码"
# 配置按键和LED
binary_sensor:
- platform: gpio
pin:
number: GPIO0 # 按键引脚
mode: INPUT_PULLUP
inverted: True
name: "插座按键"
on_press:
- switch.toggle: relay
on_double_click:
then:
- switch.turn_on: relay
- light.turn_on: led
- delay: 2h
- switch.turn_off: relay
- light.turn_off: led
on_triple_click:
then:
- switch.turn_on: relay
- light.turn_on: led
- delay: 8h
- switch.turn_off: relay
- light.turn_off: led
output:
- platform: gpio
pin: GPIO12 # 继电器引脚
id: relay
light:
- platform: binary
name: "LED灯"
output: led_output
output:
- platform: gpio
pin: GPIO14 # LED灯引脚
id: led_output
# 配置Web界面的下拉选择关闭时间
select:
- platform: template
name: "关闭时间"
id: close_time
options:
- "1小时"
- "2小时"
- "4小时"
- "8小时"
# 自动关闭继电器的触发器
time:
- platform: homeassistant
id: close_timer
on_time:
- seconds: 0
minutes: 0
hours: !lambda 'return {"1小时": 1, "2小时": 2, "4小时": 4, "8小时": 8}[id(close_time)];'
- platform: template
id: close_trigger
lambda: |-
if (id(close_timer).is_running()) {
return false;
} else {
return true;
}
switch:
- platform: template
name: "自动关闭继电器"
id: auto_close
turn_on_action:
- homeassistant.service:
service: timer.start
data:
entity_id: timer.close_timer
turn_off_action:
- homeassistant.service:
service: timer.cancel
data:
entity_id: timer.close_timer
# 配置Web界面的下拉选择关闭时间与自动关闭继电器的关联
web_server:
port: 80
api:
services:
- service: select.select_option
variables:
option: int
then:
- if:
condition:
switch.is_on: auto_close
then:
- homeassistant.service:
service: timer.start
data:
entity_id: timer.close_timer
- homeassistant.service:
service: timer.cancel
data:
entity_id: timer.close_timer
else:
- homeassistant.service:
service: timer.cancel
data:
entity_id: timer.close_timer
请注意,上述配置文件中的GPIO引脚号(如GPIO0、GPIO12、GPIO14)可能需要根据您的硬件连接进行调整。此外,如果您使用的是ESP32-C3,您需要将`board`字段更改为适合ESP32-C3的板型。
此配置文件包含一个按键和一个LED灯的配置。按键的单击操作用于打开或关闭继电器,并控制LED灯的亮灭。双击按键会立即打开继电器,LED灯闪烁2小时后自动关闭。三击按键会立即打开继电器,LED灯闪烁8小时后自动关闭。此外,还添加了一个Web界面的下拉选择框,用于选择关闭继电器的时间。选择关闭时间后,会自动触发相应的定时器来关闭继电器。
请根据您的具体需求和硬件配置进行适当的调整和测试。 |