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

 找回密码
 立即注册
查看: 7872|回复: 13

[已解决] ESPhome 写鱼缸自动换水 已经搞好

[复制链接]

6

主题

292

帖子

2085

积分

金牌会员

Rank: 6Rank: 6

积分
2085
金钱
1793
HASS币
0
QQ
发表于 2020-2-16 21:58:27 | 显示全部楼层 |阅读模式
本帖最后由 924215947 于 2020-2-19 17:18 编辑

自从养了鱼后,发现换水是个问题,经常发现换水的时候,要么把水抽干了,不记得关,只是就是放水进去,忘记关水导致整个房间都泡水了,才有想法把鱼缸排水和进水改成自动化,但是小弟对于自动化里面要怎么写实在是不懂,请求帮助!其中有一部手机是
https://bbs.hassbian.com/thread-8269-1-1.html这位神大的代码


-------- ---------——————— —————————————————————————————————————————————————————— —————————————————————————————————————————————————————— —————————————————————————————————————————————————————— ———是我需要的自动化说明
1。当排水按钮按下去,检测两个水位高是否正常,进水开关处于关闭状态,正常开始排水,排水到下面一个水位监测线时,监测不到水位了,停止排水。
2当排水停止后,两个监测线都监测不到水位时,排水停止,开始进水,进水达到高水位监测线时,进水停止水完成!

正文1。添加一路按钮 给sw2812  开光灯使用
2.添加NTC 温度 做鱼缸监测
3.t添加4个继电器 做 进水  排水  供养  水循环  使用   
4添加一个按键  排水作用
5,添加两个监测水位高低模块   
6.添加一个鱼缸盖子打开  门磁模块

以下文件正常使用的
substitutions:
  device_name: yugangdeng
  #WiFi_SSID名称
  wifi_ssid: 'xxxxx'
  #WiFi密码
  wifi_password: 'xxxxxxxxxx'
  #如果SSID是隐藏的,设置为true
  wifi_fast_connect: 'false'
  #WiFi离线多久后重启设备,秒s/分钟min/小时h,不需要此功能设置为0s
  wifi_reboot_timeout: 0s
  #OTA密码
  ota_password: 'xxxxxxxx'
  #与客户端(如Home Assistant)失去连接多久后重启设备,秒s/分钟min/小时h,不需要此功能设置为0s
  api_reboot_timeout: 0s

esphome:
  name: $device_name
  platform: ESP8266
  board: 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
  manual_ip:
    static_ip: 192.168.21.242
    gateway: 192.168.21.1
    subnet: 255.255.255.0
  ap:
    ssid: "yugang Hotspot"
    password: "a1234567"
  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

globals:
   - id: lt
     type: int
     restore_value: no
     initial_value: '0b000'
   - id: red
     type: int
     restore_value: no
     initial_value: '0'
   - id: green
     type: int
     restore_value: no
     initial_value: '0'
   - id: blue
     type: int
     restore_value: no

binary_sensor:
  - platform: gpio #鱼缸排水开关
    pin:
      number: GPIO15
      mode: INPUT_PULLUP
    name: "paishui Button 1"
    on_press:
      - switch.toggle: paishui

  - platform: gpio #添加一个水位低开关
    pin:
      number: GPIO3
      mode: INPUT_PULLUP
#      inverted: True #定义反转为下拉模式
    name: "dishuiwei"
    id: dishuiwei
    device_class: opening
#    icon: "mdi:clipboard-alert"
    on_press:
      then:
      - switch.turn_off: paishui #关闭排水
      - delay: 2s
      - switch.turn_on: jingshui #打开进水

  - platform: gpio #添加一个水位高开关
    pin:
      number: GPIO1
      mode: INPUT_PULLUP
      inverted: True #定义反转为下拉模式
    name: "gaohuiwei"
    id: gaohuiwei
    device_class: opening
#    icon: "mdi:clipboard-alert-outline"
    on_press:
      then:
      - delay: 2s
      - switch.turn_off: jingshui #关闭进水

  - platform: gpio #添加一个鱼缸盖打开状态
    pin:
      number: GPIO04
      mode: INPUT_PULLUP
#      inverted: True #定义反转为下拉模式
    name: "yuganggai"
    id: yuganggai
    device_class: opening

  - platform: gpio  #添加一个按钮GPIO0 给SW2811开关灯使用
    pin:
      number: GPIO0
      mode: INPUT_PULLUP
    name: '${device_name} BUTTON'
    on_multi_click:
    - timing:
        - OFF for at most 1s
        - ON for at least 0.5s
      then:
        - lambda: |-
            if (id(lt) >= 0b111) {
              id(lt) = 0b000;
            } else {
              id(lt) +=1;
            }
        - lambda: |-
            id(red)=(id(lt) & 0b100)  >> 2;
            id(green)=(id(lt) & 0b010) >>1;
            id(blue)=(id(lt) & 0b001);

        - light.turn_on:
            id: w_led
            transition_length: 0.5s
            red:   !lambda |-
              return id(red);
            green:  !lambda |-
              return id(green);
            blue: !lambda |-
              return id(blue);
    - timing:
        - OFF for 1s to 5s
        - ON for at least 0.5s
      then:
        - light.turn_off: w_led

light:
  - platform: fastled_clockless
    chipset: WS2811
    pin: GPIO02
    id: w_led
    num_leds: 16
    rgb_order: BRG
    name: "${device_name}  WS2811 Light"
    effects:
      - addressable_rainbow:
      - addressable_color_wipe:
      - addressable_random_twinkle:
      - addressable_fireworks:
      - addressable_scan:
      - addressable_twinkle:

switch:
  - platform: gpio
    name: "paishui"
    pin: GPIO16
    id: paishui
    inverted: True
    icon: "mdi:cart-arrow-up"
  - platform: gpio
    name: "jingshui"
    pin: GPIO14
    id: jingshui
    inverted: True
    icon: "mdi:cart-arrow-down"
  - platform: gpio
    name: "xunhuang"
    pin: GPIO12
    id: xunhuang
    inverted: True
    icon: "mdi:firefox"
  - platform: gpio
    name: "gongyang"
    pin: GPIO13
    id: gongyang
    inverted: True
    icon: "mdi:concourse-ci"

  - platform: gpio
    pin:
      number: GPIO05
    id: ntc_vcc

sensor:
  - platform: ntc
    sensor: resistance_sensor
    calibration:
      b_constant: 3950
      reference_temperature: 25°C
      reference_resistance: 10kOhm
    name: NTC Temperature

  # Example source sensors:
  - platform: resistance
    id: resistance_sensor
    sensor: source_sensor
    configuration: DOWNSTREAM
    resistor: 3.9kOhm
    name: Resistance Sensor
  - platform: adc
    id: source_sensor
    pin: A0
    filters:
      - multiply: 5
    update_interval: never

interval:
  - interval: 1s
    then:
      - switch.turn_on: ntc_vcc
      - component.update: source_sensor
      - switch.turn_off: ntc_vcc






回复

使用道具 举报

0

主题

48

帖子

318

积分

中级会员

Rank: 3Rank: 3

积分
318
金钱
270
HASS币
0
发表于 2020-2-17 15:33:00 | 显示全部楼层
使用time模块,就可以了
回复

使用道具 举报

4

主题

124

帖子

560

积分

高级会员

Rank: 4

积分
560
金钱
431
HASS币
20
发表于 2020-2-17 17:23:13 | 显示全部楼层
本帖最后由 my12005 于 2020-2-17 17:25 编辑

你搞的不错了!用传感器自动化on_value:
sensor:
  - platform: dallas
    # ...
    on_value:
      then:
        - light.turn_on:
            id: light_1
            red: !lambda "return x/255;"
我正在给DC1加个过载保护,想用功率参数,就是开启瞬间几千W马上就保护了,还有方案。没时间试。
回复

使用道具 举报

6

主题

292

帖子

2085

积分

金牌会员

Rank: 6Rank: 6

积分
2085
金钱
1793
HASS币
0
QQ
 楼主| 发表于 2020-2-17 17:45:01 | 显示全部楼层
miminzhang 发表于 2020-2-17 15:33
使用time模块,就可以了

请问下  这个要怎么填写  大概意识下 谢谢
回复

使用道具 举报

6

主题

292

帖子

2085

积分

金牌会员

Rank: 6Rank: 6

积分
2085
金钱
1793
HASS币
0
QQ
 楼主| 发表于 2020-2-17 17:51:26 | 显示全部楼层
my12005 发表于 2020-2-17 17:23
你搞的不错了!用传感器自动化on_value:
sensor:
  - platform: dallas

有的是抄袭的
回复

使用道具 举报

6

主题

292

帖子

2085

积分

金牌会员

Rank: 6Rank: 6

积分
2085
金钱
1793
HASS币
0
QQ
 楼主| 发表于 2020-2-19 17:19:27 | 显示全部楼层
已经解决问题
回复

使用道具 举报

5

主题

265

帖子

1899

积分

金牌会员

Rank: 6Rank: 6

积分
1899
金钱
1634
HASS币
0
发表于 2020-12-22 15:51:46 | 显示全部楼层
这个水位是咋监测的呢。。
回复

使用道具 举报

6

主题

292

帖子

2085

积分

金牌会员

Rank: 6Rank: 6

积分
2085
金钱
1793
HASS币
0
QQ
 楼主| 发表于 2020-12-23 08:35:41 | 显示全部楼层
通过判断IO值是高还是低来确定水位线的  这个最好的做法是用水位传感器来检测比较准确  
回复

使用道具 举报

6

主题

292

帖子

2085

积分

金牌会员

Rank: 6Rank: 6

积分
2085
金钱
1793
HASS币
0
QQ
 楼主| 发表于 2020-12-23 08:37:42 | 显示全部楼层
zkxa 发表于 2020-12-22 15:51
这个水位是咋监测的呢。。


通过判断IO值是高还是低来确定水位线的  这个最好的做法是用水位传感器来检测比较准确  
回复

使用道具 举报

5

主题

265

帖子

1899

积分

金牌会员

Rank: 6Rank: 6

积分
1899
金钱
1634
HASS币
0
发表于 2020-12-23 10:15:36 | 显示全部楼层
能推荐一下水位传感器么。。还有可以分享一下代码么。
回复

使用道具 举报

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

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-4-20 05:54 , Processed in 5.034891 second(s), 32 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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