| 本帖最后由 602293544 于 2019-12-7 11:18 编辑 
 更新了一下esp的自动化,加了温湿度传感器,就算ha崩溃了,也一样根据湿度运行,根据水位加水    OJ8K
 
 又到了该开空调制热的季节了,空调一开,室内的湿度就会降低,早上起来嗓子就像出火似的,然后咱就简单的小改造了一下,实现简单的智能化。
 没水了自动加水,加到一定高度停止     这个机子用的是干簧管判断,原来的干簧管用不了(不会搞电路看不懂)就自己加了一个干簧管判断(反正也不贵,带板子不到2元),水箱里加了一根管子(内有干簧管)还有浮球(磁铁)到达一定水位自动关闭抽水泵(以前买的,闲置利用)(或者可以计算潜水泵的抽水时间这样就不用破环水箱了)。
 
 测了一下看到风扇那儿是12v其他的都是33.9v,然后买了一个INA219可以测直流电流,可以和其他传感器一起工作用来判断加湿器现在的状态,比如有电流就是在工作,毕竟没水了他就不转了也没电流了,还有就是运行中可能会有人直接关闭原开关。
 
 先上个图
 
 
  里面的空间还是挺大的,能塞下不少东西,热熔胶固定的,凉水不会化。 
 ESP代码
 
 
substitutions:
  device_name: humidifier
  wifi_ssid: 'PDCN'
  wifi_password: '12345678'
  wifi_fast_connect: 'false'
  wifi_reboot_timeout: 60s
  ota_password: '123456'
  api_reboot_timeout: 60s
esphome:
  name: $device_name
  platform: ESP8266
  board: nodemcuv2  #esp01_1m
web_server:
  port: 80
  css_url: https://esphome.io/_static/webserver-v1.min.css
  js_url: https://esphome.io/_static/webserver-v1.min.js 
wifi:
  ssid: $wifi_ssid
  password: $wifi_password
  reboot_timeout: $wifi_reboot_timeout
  power_save_mode: none
  fast_connect: $wifi_fast_connect
logger:
api:
  reboot_timeout: $api_reboot_timeout
ota:
  safe_mode: true
  password: $ota_password
# Example output entry
switch:                   #2个继电器
  - platform: gpio
    name: "Submersible pump"
    pin: 
      number: GPIO12
      inverted: yes
    id: relay1
  - platform: gpio
    name: "humidifier"
    pin:
      number: GPIO14
      inverted: yes
    id: relay2
    
  - platform: restart     #重启按钮
    name: "Restart"
    
i2c:                 #电流传感器总线
  sda: 4
  scl: 5
  scan: True
  id: bus_a
  
sensor:                      #电流传感器
  - platform: ina219               
    address: 0x40
    shunt_resistance: 0.1 ohm
    current:
      name: "current"
      filters:
        - multiply: 1000
      unit_of_measurement: "mA"
    power:
      name: "power"
    bus_voltage:
      name: "voltage"
    shunt_voltage:
      name: "shunt_voltage"
    max_voltage: 12.0V
    max_current: 1A
    update_interval: 1s
  - platform: dht               #内置的温湿度传感器
    pin: D4
    model: DHT11
    humidity:
      name: "humidity_Hum"
      on_value_range:             #自动化
        - above: 70.0
          then:
            - switch.turn_off: relay2
        - below: 60.0
          then:
            - switch.turn_on: relay2
    temperature:
      name: "humidity_Temp"
    update_interval: 5s
     
     
binary_sensor:
  - platform: gpio                  #水箱水满了吗
    name: "water level"
    id : wl
    pin: 
      number: GPIO13
      inverted: yes
    device_class: opening
    
    on_press:
      then:
        - switch.turn_off: relay1
  - platform: gpio                  #机器运行状态
    name: "waterlevel"
    id: waterlevel
    pin:
      number: GPIO16
      inverted: yes
    device_class: opening
    
    on_release:
      then:
        - switch.turn_on: relay1
    
    
#time:
 # - platform: sntp
  #  id: sntp_time
   # timezone: Asia/Shanghai
#    on_time:
 #     - hours: 18-23,0-8
  #      then:
          
    
 
 刷机也刷完了接下来就是自动化(没办法,esp里自动化不会写,官方文档看不懂看不懂)
 就那么几个东西根据湿度开关加湿器
 加湿器没水时打开潜水泵
 到了预设水位关闭潜水泵
 
 手动关闭旋钮开关(恕我无能为力,解决不了这个,不知道怎么esp)可以蜂鸣器报警啥的
 
 
 
 
 
 |