本帖最后由 情非殇 于 2019-10-26 21:48 编辑
esphome:
name: nodemcu_01
platform: ESP8266
board: nodemcuv2
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_passwd
use_address: 172.22.1.247
# Enable logging
logger:
# Enable Home Assistant API
api:
password: !secret api_passwd
reboot_timeout: 30min
ota:
safe_mode: True
password: !secret ota_passwd
port: 8266
web_server:
port: 80
#######################################################################
binary_sensor:
## 自复位按钮操作
- platform: gpio
pin:
number: D3
mode: INPUT_PULLUP
inverted: True
name: "BUTTON"
id: button
## 按下绿灯亮
on_press:
then:
- switch.turn_on: relay_green
## 复位绿灯灭(如果绿灯依然亮)
on_release:
if:
condition:
- switch.is_on: relay_green
then:
- switch.turn_off: relay_green
## 单击执行开门流程(beta_0.3将只在有呼入时可操作)
on_click:
min_length: 50ms
max_length: 500ms
then:
- script.execute: open_door
## 长按激活/停止红灯(2~4秒有效)
on_multi_click:
- timing:
- ON for 2s to 4s
- OFF for at least 0.5s
then:
- switch.toggle: relay_red
## 监听门铃
- platform: gpio
pin:
number: D2
mode: INPUT_PULLUP
inverted: True
name: "BELL"
id: bell
## 如果红灯亮,等待0.5秒,执行开门流程
on_press:
if:
condition:
- switch.is_on: relay_red
then:
- delay: 500ms
- script.execute: open_door
switch:
## 绿灯(按键指示)
- platform: gpio
pin: D0
name: "LED_GREEN"
id: relay_green
## 亮起时长,2秒/次
on_turn_on:
- delay: 2.1s
- if:
condition:
for:
time: 2s
condition:
switch.is_on: relay_green
then:
- switch.turn_off: relay_green
# - logger.log: Test has stayed connected for at least 1 minutes!
## 红灯(自动化流程条件)
- platform: gpio
pin: D1
name: "LED_RED"
id: relay_red
## 灯亮静音,灯灭恢复
on_turn_on:
- switch.turn_on: mute
# - logger.log: "Switch Turned On!"
on_turn_off:
- switch.turn_off: mute
# - logger.log: "Switch Turned Off!"
## 模拟接听(抬起/挂起话机)
- platform: gpio
pin: D5
name: "RELAY_KA1"
id: relay_ka1
- platform: gpio
pin: D6
name: "RELAY_KA2"
id: relay_ka2
## 开门
- platform: gpio
pin: D7
name: "RELAY_KEY"
id: relay_key
## 静音(门铃)(联动红灯)
- platform: gpio
pin: D8
name: "MUTE"
id: mute
## 8266运行时间
sensor:
- platform: uptime
name: Uptime Sensor
################################################################################
# Example configuration entry
script:
## 模拟手动开门完整流程
- id: open_door
then:
## 模拟抬起话筒,切换间隔10ms(ps:50ms模拟失败)
- switch.turn_on: relay_ka2
- delay: 10ms
- switch.turn_on: relay_ka1
## 等待0.8s后,短接并联0.1s模拟开门按键
- delay: 800ms
- switch.turn_on: relay_key
- delay: 100ms
- switch.turn_off: relay_key
## 等待1.5秒后,模拟挂起话筒
- delay: 1500ms
- switch.turn_off: relay_ka1
- delay: 10ms
- switch.turn_off: relay_ka2
## 模拟流程end,log装逼测试!
- logger.log: ok, the door is open! perfect!
## beta_0.1测试失败后,测试代码用
# - id: open_door1
# then:
# - switch.turn_on: relay_ka2
# - delay: 10ms
# - switch.turn_on: relay_ka1
# - id: open_door2
# then:
# - switch.turn_on: relay_key
# - delay: 100ms
# - switch.turn_off: relay_key
|