本帖最后由 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
|