esphome:
name: "clothes-hanger"
friendly_name: "clothes-hanger"
comment: 阳台晒衣杆、阳台灯
platformio_options:
board_build.flash_mode: dio
board_build.mcu: esp32c3
esp32:
board: esp32-c3-devkitm-1
framework:
type: esp-idf
version: recommended
# Custom sdkconfig options
sdkconfig_options:
CONFIG_COMPILER_OPTIMIZATION_SIZE: y
# Advanced tweaking options
advanced:
ignore_efuse_mac_crc: false
logger:
hardware_uart: USB_SERIAL_JTAG
# Enable logging
api:
ota:
password: "2fe5275a4f967590a20bb6179fb0ce14"
captive_portal:
wifi:
networks:
- ssid:
password:
- ssid:
password:
ap:
ssid: " - "
password: " "
sensor:
- platform: adc
pin: 0
id: alarm1
name: "超载报警"
update_interval: 2s
filters:
- multiply: 10
on_value_range:
- above: 1.5
then:
- cover.stop: hanger
- rtttl.play: 'long:d=1,o=5,b=100:e6'
- platform: wifi_signal
name: "clothes-hanger WiFi Signal"
update_interval: 60s
binary_sensor:
#上升限位
- platform: gpio
id: sxw
name: "Up Limit"
icon: mdi:arrow-collapse-up
pin:
number: GPIO2
mode:
input: true
pullup: true
# inverted: true
filters:
- delayed_on: 20ms
on_press:
then:
- rtttl.play: 'scale_up:d=32,o=7,b=100:c,c#,d#,e,f#,g#,a#,b'
- switch.turn_off: relay
#下降限位
- platform: gpio
id: jxw
name: "Down Limit"
icon: mdi:arrow-collapse-down
pin:
number: GPIO3
mode:
input: true
pullup: true
# inverted: true
filters:
- delayed_on: 20ms
on_press:
then:
- rtttl.play: 'scale_up:d=32,o=7,b=100:b,a#,g#,f#,e,d#,c#,c'
- switch.turn_off: relay1
#衣物检测限位
- platform: gpio
id: yzxq
name: "衣物检测"
pin:
number: GPIO5
mode:
input: true
pullup: true
inverted: true
filters:
- delayed_on: 20ms
# on_press:
# - switch.turn_off: relay
# - switch.turn_off: relay1
# - switch.turn_on: relay2
# - delay: 200ms
# - switch.turn_on: relay2
# - delay: 200ms
# - switch.turn_on: relay2
#上升按钮
- platform: gpio
id: up
pin:
number: GPIO21
mode:
input: true
pullup: true
inverted: true
filters:
- delayed_on: 50ms
on_press:
- cover.open: hanger
# - rtttl.play: 'scale_up:d=32,o=7,b=100:c,c#,d#'
#下降按钮
- platform: gpio
id: down
pin:
number: GPIO1
mode:
input: true
pullup: true
inverted: true
filters:
- delayed_on: 50ms
on_press:
- cover.close: hanger
# - rtttl.play: 'scale_up:d=32,o=7,b=100:b,a#'
#暂停按钮
- platform: gpio
id: stop
pin:
number: GPIO20
mode:
input: true
pullup: true
inverted: true
filters:
- delayed_on: 50ms
on_press:
- cover.stop: hanger
# - rtttl.play: 'two_short:d=4,o=5,b=100:16e6,16e6'
#灯按钮
- platform: gpio
id: blight
pin:
number: GPIO8
mode:
input: true
pullup: true
inverted: true
filters:
- delayed_on: 50ms
on_press:
- light.toggle: lamp
switch:
# 上升继电器控制
- platform: gpio
pin: GPIO7
id: relay
# name: "Up D15"
restore_mode: RESTORE_DEFAULT_OFF
interlock: &interlock_group [relay, relay1]
interlock_wait_time: 200ms
# 下降继电器控制
- platform: gpio
pin: GPIO10
id: relay1
# name: "Down D4"
restore_mode: RESTORE_DEFAULT_OFF
interlock: *interlock_group
interlock_wait_time: 200ms
cover:
- platform: endstop
name: "hanger"
id: hanger
open_action:
- switch.turn_on: relay
- rtttl.play: 'scale_up:d=32,o=7,b=100:c,c#,d#,e,f#,g#,a#,b'
open_duration: 12s
open_endstop: sxw
close_action:
- rtttl.play: 'scale_up:d=32,o=7,b=100:b,a#,g#,f#,e,d#,c#,c'
- switch.turn_on: relay1
close_duration: 13s
close_endstop: jxw
stop_action:
- switch.turn_off: relay
- switch.turn_off: relay1
- rtttl.play: two_short:d=4,o=5,b=100:16e6,16e6
light:
- platform: binary
id: lamp
name: "阳台灯"
output: light_output
output:
- id: light_output
platform: gpio
# inverted: False
pin: GPIO6
- platform: ledc
pin: GPIO4
id: rtttl_out
rtttl:
output: rtttl_out
text_sensor:
- platform: template
name: "晒衣杆状态"
update_interval: 1s
icon: mdi:hanger
lambda: |-
if (id(relay1).state == true){
return {"晒衣杆正在下降中..."};
} else if (id(relay).state == true){
return {"晒衣杆正在升起..."};
} else if (id(jxw).state == true ){
return {"晒衣杆已降下"};
} else if (id(sxw).state == true ){
return {"晒衣杆已升起"};
} else if (id(alarm1).state > 1 ){
return {"告警,晒衣杆超负荷!"};
} else {
return {"待机中"};
}