本帖最后由 trz0332 于 2022-12-7 09:04 编辑
千万不要用这种方案,你用的这种方案我4年前就用了,HC-SR04有一个大问题,不防水,用不了多久,电路板就被水蒸气腐蚀了。我后来还用过防水的超声波传感器,淘宝50块钱一个,解决了腐蚀问题,但是新问题出现了,夏天的时候水蒸气在传感器上凝结成了小水珠,导致数据会不准确,用了1年,也被我淘汰了,现在我的方案就是用投入式的液位传感器,虽然贵点,但是真的是太稳了,用了1年,数据和质量都是杠杠的。
我用的是485的投入式液位传感器。搭配一个ttl专485模块。屏幕用的是2004加了温湿度和气压在里面
#设备选型esp32,lcd2004,bme280,l298n,12V继电器,一个自复按钮开关
#
#
#
<<: !include config.yaml
substitutions:
device_name: pump
date_update_interval: 20s
esphome:
name: $device_name
platform: esp32
board: esp32doit-devkit-v1
web_server: #开启we功能
port: 80
globals:
- id: _water_pre
type: float
restore_value: no
initial_value: '50.0'
- id: auto_flag #设置全局变量,用于设置手自动
type: int
restore_value: yes
initial_value: '0'
font: #字题文件
- file: "simfang.ttf"
id: my_font
size: 20
time: #时间设置
- platform: sntp
id: my_time
logger: #是否开启日志
#level: NONE
i2c: #设置I2C的gpio
sda: 21
scl: 22
scan: True
display: #液晶屏设置
- platform: lcd_pcf8574 #
dimensions: 20x4 #使用lcd2004液晶屏
update_interval: 1s #刷新设置
address: 0x27 #i2c地址
lambda: |- #第一行显示时间,第二行显示水位,第三行显示温度和适度,第四行显示气压
it.strftime(0,0,"%Y-%m-%d %H:%M:%S", id(my_time).now());
it.printf(0,2,"T:%.1fC RH:%.1f%%", id(s10001).state, id(s10002).state);
it.printf(0,3,"pre:%.2fhPa", id(s10003).state);
it.printf(0,1,"WH:%.2fcm", id(water_cm).state);
uart:
rx_pin: GPIO16
tx_pin: GPIO17
baud_rate: 9600
id: mod_uart
modbus:
send_wait_time: 200ms
uart_id: mod_uart
id: mod_bus
modbus_controller:
- id: sdm
address: 1
modbus_id: mod_bus
command_throttle: 100ms
setup_priority: -10
update_interval: 10s
sensor:
- platform: modbus_controller
modbus_controller_id: sdm
name: "${device_name}_water_cm"
address: 4
register_type: "holding"
value_type: S_WORD
accuracy_decimals: 1
unit_of_measurement: 'cm'
filters:
- multiply: 0.1
id: water_cm
- platform: template
#internal: true
unit_of_measurement: '%'
name: "${device_name}_water_pre"
id: "water_pre"
lambda: |-
return id(water_cm).state*100/(id(_full_set).state);
# on_value_range:
# - above: !lambda |-
# return id(_hight_set).state;
# then:
# - switch.turn_off: dehumidifier1
# - below: !lambda |-
# return id(_low_set).state;
# then:
# - switch.turn_off: dehumidifier1
filters:
- lambda: |-
if (x>id(_hight_set).state and id(auto_flag) ){
id(dehumidifier1).turn_off();
}else if (x< id(_low_set).state and id(auto_flag) ){
id(dehumidifier1).turn_on();
}
return x ;
update_interval: 5s
- platform: bme280 #bme280设置
temperature: #温度名
name: "${device_name} Temperature"
id: s10001
oversampling: 16x
filters:
- or:
- heartbeat: $date_update_interval
- delta: 1
humidity: #湿度名
name: "${device_name} Humidity"
id: s10002
filters:
- or:
- heartbeat: $date_update_interval
- delta: 5
pressure: #气压名
name: "${device_name} Pressure"
id: s10003
filters:
- or:
- heartbeat: $date_update_interval
- delta: 20
address: 0x76
update_interval: 180s #数据刷新时间
binary_sensor:
- platform: gpio #添加一个按钮GPIO2
pin:
number: GPIO2
mode: INPUT_PULLUP
name: '${device_name} BUTTON'
id: s10004
on_multi_click:
- timing: #短按开启屏幕背光灯
- ON for at most 1s
- OFF for at least 0.5s
then:
- switch.toggle: s_led
- timing: #长按开启水泵
- ON for 1s to 5s
- OFF for at least 0.5s
then:
- switch.toggle: dehumidifier1
switch:
- platform: gpio #添加水泵开关,gpio14
pin: 14
name: "${device_name} pumpswitch"
id: dehumidifier1
restore_mode: RESTORE_DEFAULT_OFF
- platform: gpio #添加屏幕背光灯开关gpio23
pin: 23
name: "${device_name} s_led"
id: s_led
- platform: restart
name: "${device_name}_Restart"
- platform: template #模板开关-------手自动
name: "${device_name}_auto"
id: "${device_name}_auto"
lambda: |-
return id(auto_flag);
turn_on_action:
then:
- lambda: |-
id(auto_flag) = 1;
turn_off_action:
then:
- lambda: |-
id(auto_flag) = 0;
number:
- platform: template
name: "${device_name}_full_set"
id: "_full_set"
optimistic: true
min_value: 50
max_value: 100
initial_value: 75
restore_value: true
step: 1
- platform: template
name: "${device_name}_low_set"
id: "_low_set"
optimistic: true
min_value: 1
max_value: 30
initial_value: 10
restore_value: true
step: 1
- platform: template
name: "${device_name}_hight_set"
id: "_hight_set"
optimistic: true
min_value: 70
max_value: 100
restore_value: true
initial_value: 90
step: 1
复制代码