本帖最后由 shadowba 于 2023-6-1 14:04 编辑
准备材料:
1.电机总成
2.esp8266开发板,继电器,万能板,接线端子,按钮,A0引脚的接入是为了检测电机工作后电阻的分压值,用以确定是够过载,如果过载就停止工作,这部分正在调试,等哪天多洗点衣服看一下值,然后在配置过载停机保护。
原电机总成遇阻限位需要安装时调整电机总成在钢丝两侧的角度才能起效,我没装好,只能折中用来检测杆上是否有衣服,自动化判断有衣服晾衣杆就在洗衣机完成洗衣后不降下晾衣杆。
制作国产省略,成品如下:
基本8266引脚能用的都用了,gpio16用的时候记得上拉,gpio2控制灯做继电器时要接光耦负极,光耦正极接3.3v,已接入小爱
代码如下:
esphome:
name: "clothes-hanger"
friendly_name: "clothes-hanger"
esp8266:
board: esp01_1m
# Enable logging
#logger:
# Enable Home Assistant API
api:
ota:
password: "xxxxxxxxxxxxxxx"
web_server:
port: 80
wifi:
networks:
- ssid: xxxxx
password: xxxxxxx
ap:
ssid: "zf-edf Fallback Hotspot"
password: "xxxxxxxxxxxx"
captive_portal:
sensor:
- platform: adc
pin: A0
name: "alarm V"
update_interval: 2s
binary_sensor:
#上升限位
- platform: gpio
id: bup
name: bup D12
pin:
number: GPIO12
mode:
input: true
pullup: true
inverted: false
filters:
- delayed_on: 50ms
on_press:
then:
- switch.turn_on: relay2
- switch.turn_off: relay
#下降限位
- platform: gpio
id: bdown
name: bdown D13
pin:
number: GPIO13
mode:
input: true
pullup: true
inverted: false
filters:
- delayed_on: 50ms
on_press:
then:
- switch.turn_on: relay2
- switch.turn_off: relay1
#衣物检测限位
- platform: gpio
id: yzxq
name: alarm D14
pin:
number: GPIO14
mode:
input: true
pullup: true
inverted: true
filters:
- delayed_on: 50ms
# 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
name: up D0
pin:
number: GPIO0
mode:
input: true
pullup: true
inverted: true
filters:
- delayed_on: 20ms
on_press:
- cover.close: hanger
- switch.turn_on: relay2
#下降按钮
- platform: gpio
id: down
name: down D5
pin:
number: GPIO5
mode:
input: true
pullup: true
inverted: true
filters:
- delayed_on: 20ms
on_press:
- cover.open: hanger
- switch.turn_on: relay2
#暂停按钮
- platform: gpio
id: stop
name: stop D16
pin:
number: GPIO16
mode:
input: true
inverted: true
filters:
- delayed_on: 20ms
on_press:
- cover.stop: hanger
- switch.turn_on: relay2
- delay: 100ms
- switch.turn_on: relay2
#灯按钮
- platform: gpio
id: blight
name: blight D3
pin:
number: GPIO3
mode:
input: true
pullup: true
inverted: true
filters:
- delayed_on: 20ms
on_press:
- light.toggle: lamp
switch:
# 上升继电器控制
- platform: gpio
pin: GPIO15
id: relay
# name: "Up D15"
restore_mode: RESTORE_DEFAULT_OFF
interlock: &interlock_group [relay, relay1]
interlock_wait_time: 200ms
# 下降继电器控制
- platform: gpio
pin: GPIO4
id: relay1
# name: "Down D4"
restore_mode: RESTORE_DEFAULT_OFF
interlock: *interlock_group
interlock_wait_time: 200ms
# 蜂鸣器控制
- platform: gpio
pin: GPIO1
id: relay2
name: "Buzzer D1"
inverted: true
on_turn_on:
- delay: 100ms
- switch.turn_off: relay2
cover:
- platform: template
name: "Clothes hanger"
id: hanger
open_action:
then:
- if:
condition:
- binary_sensor.is_on: bdown
then:
- switch.turn_on: relay2
- delay: 100ms
- switch.turn_on: relay2
else:
- switch.turn_on: relay2
- switch.turn_off: relay
- switch.turn_on: relay1
- delay: 19s
- switch.turn_off: relay1
close_action:
then:
- if:
condition:
- binary_sensor.is_on: bup
then:
- switch.turn_on: relay2
- delay: 100ms
- switch.turn_on: relay2
else:
- switch.turn_on: relay2
- switch.turn_off: relay1
- switch.turn_on: relay
- delay: 17s
- switch.turn_off: relay
stop_action:
- switch.turn_off: relay
- switch.turn_off: relay1
- switch.turn_on: relay2
- delay: 100ms
- switch.turn_on: relay2
optimistic: true
assumed_state: true
light:
- platform: binary
id: lamp
name: "Lamp"
output: light_output
output:
- id: light_output
platform: gpio
inverted: true
pin: GPIO2
|