esphome:
name: bedroom-toilet
platform: esp8266
board: esp12e
# Enable logging
logger:
baud_rate: 0
# Enable Home Assistant API
api:
ota:
wifi:
ssid: "UBNT" #你的WiFi名称
password: "wii2dgbr" #你的WiFi密码
manual_ip:
static_ip: 192.168.50.252 #自己填一个IP地址
gateway: 192.168.50.1 #你家网络的网关地址
subnet: 255.255.255.0
ap:
ssid: "Motion_Bedroom_Toilet"
password: "12345678"
#wifi连接不上,自动释放一个AP节点
captive_portal:
i2c:
sda: GPIO4 #D2
scl: GPIO5 #D1
scan: true
uart:
id: uart_sensor
rx_pin: GPIO3 #RX
tx_pin: GPIO1 #TX
baud_rate: 256000
parity: NONE
stop_bits: 1
debug:
direction: BOTH
after:
delimiter: [0xF8,0xF7,0xF6,0xF5]
sensor:
- platform: bh1750 #BH1750光线传感器
name: "BH1750 Illuminance"
address: 0x23
update_interval: 20s
binary_sensor: #定义人体存在传感器
- platform: gpio
pin: GPIO16 #D0
name: "LD2410B_Sensor"
device_class: motion
id: motion_01
- platform: gpio #定义红外传感器
pin: GPIO14 #D5
name: "AS312_PIR_Sensor"
device_class: motion
switch:
- platform: template
name: "config mode"
id: config_mode
optimistic: true
on_turn_on:
- uart.write: [0xFD,0xFC,0xFB,0xFA,0x04,0x00,0xFF,0x00,0x01,0x00,0x04,0x03,0x02,0x01]
- delay: 1s
on_turn_off:
- uart.write: [0xFD,0xFC,0xFB,0xFA,0x02,0x00,0xFE,0x00,0x04,0x03,0x02,0x01]
- delay: 1s
- platform: template
name: "set all sensitivity"
id: set_all_sensitivity
optimistic: true
button:
- platform: template
name: "config get"
id: config_get
on_press:
- uart.write: [0xFD,0xFC,0xFB,0xFA,0x02,0x00,0x61,0x00,0x04,0x03,0x02,0x01]
- delay: 1s
- platform: template
name: "set distance"
id: set_distance
on_press:
- uart.write: !lambda
return {0xFD,0xFC,0xFB,0xFA, 0x14, 0x00, 0x60, 0x00, 0x00, 0x00, (unsigned char)(int)(id(max_mov_dis).state/0.75), 0x00, 0x00, 0x00, 0x01, 0x00, (unsigned char)(int)(id(max_occ_dis).state/0.75), 0x00, 0x00, 0x00, 0x02, 0x00, (unsigned char)id(none_dur).state, 0x00, 0x00, 0x00, 0x04, 0x03, 0x02, 0x01};
- delay: 1s
- platform: template
name: "set sensitivity"
id: set_sensitivity
on_press:
- uart.write: !lambda
if (id(set_all_sensitivity).state) {
return {0xFD,0xFC,0xFB,0xFA, 0x14, 0x00, 0x64, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x01, 0x00, (unsigned char)id(mov_sv).state, 0x00, 0x00, 0x00, 0x02, 0x00, (unsigned char)id(occ_sv).state, 0x00, 0x00, 0x00, 0x04, 0x03, 0x02, 0x01};
} else {
return {0xFD,0xFC,0xFB,0xFA, 0x14, 0x00, 0x64, 0x00, 0x00, 0x00, (unsigned char)(int)(id(dis_setup).state/0.75), 0x00, 0x00, 0x00, 0x01, 0x00, (unsigned char)id(mov_sv).state, 0x00, 0x00, 0x00, 0x02, 0x00, (unsigned char)id(occ_sv).state, 0x00, 0x00, 0x00, 0x04, 0x03, 0x02, 0x01};
}
- delay: 1s
- platform: template
name: "!set default!"
id: set_default
on_press:
- uart.write: [0xFD,0xFC,0xFB,0xFA,0x02,0x00,0xA2,0x00,0x04,0x03,0x02,0x01]
- delay: 1s
number:
- platform: template
name: "max_mov_dis" #最大运动距离
id: max_mov_dis
min_value: 0.75
max_value: 6
initial_value: 6
step: 0.75
restore_value: true
optimistic: true
# disabled_by_default: true
unit_of_measurement: m #单位:米
- platform: template
name: "max_occ_dis" #最大静止距离
id: max_occ_dis
min_value: 0.75
max_value: 6
initial_value: 6
step: 0.75
restore_value: true
optimistic: true
# disabled_by_default: true
unit_of_measurement: m #单位:米
- platform: template
name: "none_dur" #无人持续时间
id: none_dur
min_value: 0
max_value: 120
initial_value: 20
step: 1
restore_value: true
optimistic: true
# disabled_by_default: true
unit_of_measurement: s #单位:秒
- platform: template
name: "mov_sv" #运动灵敏度
id: mov_sv
min_value: 0
max_value: 100
initial_value: 40
step: 10
restore_value: true
optimistic: true
# disabled_by_default: true
- platform: template
name: "occ_sv" #静止灵敏度
id: occ_sv
min_value: 0
max_value: 100
initial_value: 40
step: 10
restore_value: true
optimistic: true
# disabled_by_default: true
- platform: template
name: "dis_setup" #灵敏度感应距离
id: dis_setup
min_value: 0
max_value: 6
initial_value: 6
step: 0.75
restore_value: true
optimistic: true
# disabled_by_default: true
unit_of_measurement: m #单位:米