我后来改了一下,加水只通过按按钮,不通过流量判断了(冬天出100°的水,水流就特别小 接近于没水,会误触发加水)
我把yaml贴出来你再看看,时间太久了我也记不清细节了
esphome:
name: water-dispenser
platform: ESP8266
board: d1
# Enable logging
logger:
# Enable Home Assistant API
api:
ota:
- platform: esphome
password: "xxxxxxxxxxxx"
wifi:
ssid: "xxxxxxxxxxxxxx"
password: "xxxxxxxxxxxx"
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Water-Dispenser Fallback Hotspot"
password: "1223334444"
globals:
- id: up_water_now #replenishment_water的total值不能直接调用,所以建立了这个全局变量
type: float
restore_value: no
- id: up_water_last
type: float
initial_value: "0.0"
restore_value: no
- id: replenishment_water_remaining
type: float
restore_value: no
- id: drink_water_daily_temp1 #累计出水量 上次
type: float
initial_value: "0.0"
restore_value: no
- id: drink_water_daily_temp2 #累计出水量 当前次
type: float
initial_value: "0.0"
restore_value: no
- id: drink_water_daily_temp3 #temp2 - temp1 当前次出水量
type: float
initial_value: "0.0"
restore_value: no
- id: drink_water_daily # +=temp3 当日累计出水量
type: float
initial_value: "0.0"
restore_value: no
sensor:
#################pulse_counter和pulse_meter不能同时作用于一个Pin上####################
#喝水流量
# - platform: pulse_counter
# pin: GPIO5
# name: "drink water alive"
# internal: false #开放到HA
# id: drink_water_now
# unit_of_measurement: 'mL/min'
# update_interval: 1s #传感器查询间隔
# filters:
# - multiply: 0.0055 #0.055g水/脉冲
#补水流量
# - platform: pulse_counter
# pin: GPIO4
# name: "replenishment water alive"
# internal: false #开放到HA
# id: replenishment_water_now
# unit_of_measurement: 'mL/min'
# update_interval: 1s
# filters:
# - multiply: 0.0055
#################pulse_counter和pulse_meter不能同时作用于一个Pin上####################
#水箱用水量统计
- platform: pulse_meter
pin: GPIO5
unit_of_measurement: 'mL/s'
name: 'drink water speed'
id: drink_water
internal_filter: 13us
accuracy_decimals: 2
internal: false #开放到HA
timeout: 1s
filters:
- multiply: 0.00091667 #原测量单位为pulse/min 水泵0.055g(mL)/pulse,相乘得到ml/min,再/60得到mL/s
# on_value_range: #抽不到水的时候触发自动化,此值为经过filter的
# below: 3.0 #原来为5 改为3是因为在85°以上的时候 出水本来就慢 5~6ml/s左右
# then:
# if:
# condition:
# or:
# - for:
# time: 800ms
# condition:
# sensor.in_range:
# id: drink_water
# below: 5.0
# - binary_sensor.is_on: internal_pump #条件:水泵还是开启的(缺水时 理论上是先测不到流量,再水泵停止;正常供水时,应该是水泵先停,流量再为0)
# then:
# - switch.turn_on: outside_pump
total:
name: "drink water remaining"
unit_of_measurement: "L"
accuracy_decimals: 2
filters: #水泵0.055g(mL)/pulse,total的单位为pulse,相乘得到mL单位,再/1000得到L
- lambda: |-
x = x * 0.055;
id(drink_water_daily_temp2) = x;
x = x * 0.001;
x = 2.0 - x;
return x ;
#水桶用水量统计
- platform: pulse_meter
pin: GPIO4
unit_of_measurement: 'mL/s'
name: 'replenishment water speed'
id: replenishment_water
internal_filter: 13us
accuracy_decimals: 2
internal: false
timeout: 1s
filters:
- multiply: 0.00091667
on_value_range: #抽不到水的时候 关闭水泵,此值为经过filter的
below: 5.0
then:
if:
condition:
for:
time: 800ms
condition:
sensor.in_range:
id: replenishment_water
below: 10.0
then:
- switch.turn_off: outside_pump
total:
name: "replenishment water total"
unit_of_measurement: "L"
accuracy_decimals: 2
internal: true
filters:
- lambda: |-
x = x * 0.000055;
id(up_water_now) = x;
id(replenishment_water_remaining) = 19.0-x;
return x ;
- platform: template
name: "replenishment water remaining"
unit_of_measurement: "L"
accuracy_decimals: 2
icon: "mdi:cup-water"
lambda: |-
return id(replenishment_water_remaining);
update_interval: 1s
- platform: template
name: "drink_water_daily"
unit_of_measurement: "mL"
accuracy_decimals: 2
icon: "mdi:cup-water"
lambda: |-
return id(drink_water_daily);
update_interval: 1s
binary_sensor:
#内置水泵工况
- platform: gpio
pin:
number: GPIO12
inverted: true
name: "internal pump"
id: internal_pump
internal: true #仅内部使用,不开放到HA
on_release:
then:
- lambda: |-
id(drink_water_daily_temp3) = id(drink_water_daily_temp2)-id(drink_water_daily_temp1);
id(drink_water_daily_temp1) = id(drink_water_daily_temp2);
id(drink_water_daily) += id(drink_water_daily_temp3);
#按键
- platform: gpio
pin:
number: GPIO2
inverted: true
mode:
input: true
pullup: true
name: "water dispenser button"
internal: true #仅内部使用,不开放到HA
on_multi_click:
- timing:
- ON for at most 1s
- OFF for at least 0.5s
then:
- switch.toggle: outside_pump
- logger.log: "[Single Click] toggle pump"
- timing:
- ON for 1s to 3s
- OFF for at least 0.5s
then:
- pulse_meter.set_total_pulses: #清空的是脉冲数
id: drink_water
value: '0'
- globals.set: #在重置水箱容量的时候,把用于统计今日饮水量的临时变量drink_water_daily_temp1(上次累计出水量)清零,因为在重置水箱容量后,temp2(当前次累计出水量)会从0开始重新计数
id: drink_water_daily_temp1
value: '0.0'
- logger.log: "[Single Long Click] set drink water total value to 2.0"
- timing:
- ON for at most 1s
- OFF for at most 0.3s
- ON for at most 1s
- OFF for at least 0.2s
then:
- globals.set:
id: up_water_last
value: '0.0'
- pulse_meter.set_total_pulses: #清空的是脉冲数
id: replenishment_water
value: '0'
- logger.log: "[Double Click] set replenishment water remaining value to 19.0"
switch:
#外置水泵开关 开放到HA 可以手动补水
- platform: gpio
pin: GPIO13
name: "outside pump"
icon: "mdi:water-pump"
id: outside_pump
on_turn_on: #打开后,本次加水超过2.0L,自动停止
- wait_until:
condition:
lambda: |-
return id(up_water_now)-id(up_water_last) > 2.0;
timeout: 150s #13mL/s+的流速,72秒即可达到1L
- switch.turn_off: outside_pump
on_turn_off:
- pulse_meter.set_total_pulses:
id: drink_water #重置水箱水量
value: '0'
- lambda: |-
id(up_water_last) = id(up_water_now);
- globals.set: #在重置水箱容量的时候,把用于统计今日饮水量的临时变量drink_water_daily_temp1(上次累计出水量)清零,因为在重置水箱容量后,temp2(当前次累计出水量)会从0开始重新计数
id: drink_water_daily_temp1
value: '0.0'
time:
- platform: homeassistant
id: my_time
timezone: UTC-8
on_time:
# Every morning
- seconds: 10
minutes: 0
hours: 0
days_of_week: 1-7
then:
- globals.set:
id: drink_water_daily
value: '0.0'
|