『瀚思彼岸』» 智能家居技术论坛

 找回密码
 立即注册
123
返回列表 发新帖
楼主: ghostist

[基础教程] 基于esphome+自制硬件的即热饮水机自动补水方案

[复制链接]

40

主题

2178

帖子

8338

积分

元老级技术达人

积分
8338
金钱
6145
HASS币
110
 楼主| 发表于 3 天前 | 显示全部楼层
mimikiki 发表于 2024-12-23 18:32
大佬你好,up_water_now应该是每日零点清零的吧,up_water_last当天不做任何操作的话是不是保持前一天的值 ...

我后来改了一下,加水只通过按按钮,不通过流量判断了(冬天出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'


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-12-27 08:54 , Processed in 0.489597 second(s), 21 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表