# GPIO-14 红外 板载D5
# GPIO-5 开关继电器 D1
# GPIO-12 雷达 板载D6
# GPIO-13 温湿度 板载D7
# GPIO-1 SDA 板载D10
# GPIO-3 SCL 板载D9
# SR312红外传感器触发释出高电平3.3V,输入2.7V-12V
# LD1115H雷达传感器触发释出高电平3.2V,输入5V
# BH1750输入3V-5V
# ESP8266-12F输入4.5V-9V
substitutions:
area: kewei #家庭区域
board: esp8266 #芯片型号
devicename: $area-$board-light #设备名称
friendly_name: $devicename #友好名称
############################################
# Example configuration entry
esphome:
name: $devicename
includes:
- uart_read_line_sensor.h
esp8266:
board: esp01_1m
restore_from_flash: true
# Enable logging
logger:
# level: VERBOSE #makes uart stream available in esphome logstream
# baud_rate: 0 #disable logging over uart
# Enable Home Assistant 接入API
api:
# Enable Home Assistant OTA接入密码
ota:
password: "angie"
wifi:
networks:
- ssid: !secret wifi_ssid ##设置第一个WiFi;
password: !secret wifi_password
- ssid: SmartOS ##设置第二个WiFi;
password: angie
# Optional manual IP
manual_ip:
static_ip: 10.10.10.41 ##固定此设备IP地址;
gateway: 10.10.10.1 ##路由器、网关地址;
subnet: 255.255.255.0 ##子网掩码;
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: $devicename ##设置AP模式热点名称;
password: "angie"
captive_portal:
web_server: ## web控制,添加了这2行,就可以在网页端打开设备ip;
port: 80
globals:
- id: my_global_int
type: int
restore_value: no
initial_value: '0'
uart:
id: uart_bus
rx_pin: 2
tx_pin: 4
baud_rate: 115200
i2c:
sda: GPIO1 ##映射TX到GPIO1-SDA;
scl: GPIO3 ##映射RX到GPIO3-SCL;
scan: True
switch:
- platform: gpio
name: "客卫传感器 人体存在" #主开关
icon: "mdi:electric-switch"
pin: GPIO5
id: relay
number:
- platform: template
id: motion_th1
name: "客卫传感器 th1 移动灵敏度"
mode: box
optimistic: true
min_value: 0
max_value: 500
step: 1
restore_value: true
initial_value: 120
on_value:
then:
- uart.write: !lambda
int v = (int)x;
std::string cmd = "th1=" + to_string(v);
return std::vector<unsigned char>(cmd.begin(), cmd.end());
- delay: 100ms
- uart.write: "save"
- logger.log:
format: "th1 is %.1f"
args: [ 'id(motion_th1).state' ]
- platform: template
id: motion_th2
name: "客卫传感器 th2 存在灵敏度"
mode: box
optimistic: true
min_value: 0
max_value: 500
step: 1
restore_value: true
initial_value: 250
on_value:
then:
- uart.write: !lambda
int v = (int)x;
std::string cmd = "th2=" + to_string(v);
return std::vector<unsigned char>(cmd.begin(), cmd.end());
- delay: 100ms
- uart.write: "save"
- logger.log:
format: "th2 is %.1f"
args: [ 'id(motion_th2).state' ]
- platform: template
id: occ_sn
name: "客卫传感器 occ 维持条件"
disabled_by_default: true
optimistic: true
mode: box
min_value: 1
max_value: 100
step: 1
restore_value: true
initial_value: 3
on_value:
then:
- uart.write: !lambda
int v = (int)x;
std::string cmd = "occ_sn=" + to_string(v);
return std::vector<unsigned char>(cmd.begin(), cmd.end());
- delay: 100ms
- uart.write: "save"
- logger.log:
format: "occ_sn set %.1f"
args: [ 'id(occ_sn).state' ]
- platform: template
id: motion_dtime
name: "客卫传感器 gpio 检测延迟"
icon: "mdi:clock-time-four"
mode: box
disabled_by_default: true
optimistic: true
min_value: 1
max_value: 300
step: 1
restore_value: true
initial_value: 5
on_value:
then:
- uart.write: !lambda
int v = (int)x;
std::string cmd = "dtime=" + to_string(v);
return std::vector<unsigned char>(cmd.begin(), cmd.end());
- delay: 100ms
- uart.write: "save"
- logger.log:
format: "dtime set %.1f"
args: [ 'id(motion_dtime).state' ]
- platform: template
id: mov_sn
name: "客卫传感器 mov 触发条件"
optimistic: true
disabled_by_default: true
min_value: 1
max_value: 100
step: 1
restore_value: true
mode: box
initial_value: 5
on_value:
then:
- uart.write: !lambda
int v = (int)x;
std::string cmd = "mov_sn=" + to_string(v);
return std::vector<unsigned char>(cmd.begin(), cmd.end());
- delay: 100ms
- uart.write: "save"
- logger.log:
format: "mov_sn set %.1f"
args: [ 'id(mov_sn).state' ]
button:
- platform: restart
name: "客卫传感器 重启ESP 8266"
- platform: template
name: "查看配置"
on_press:
- uart.write: "get_all"
sensor:
- platform: bh1750
id: illuminance
name: "客卫传感器 光强度illuminance"
address: 0x23
update_interval: 15s
- platform: wifi_signal
id: espwifi
name: 客卫传感器 WiFi信号强度
update_interval: 300s
- platform: dht
pin: GPIO13
model: DHT11
update_interval: 60s
temperature:
name: 客卫传感器 温度Temperature
filters:
- sliding_window_moving_average:
window_size: 15
send_every: 15
send_first_at: 3
humidity:
name: 客卫传感器 湿度Humidity
filters:
- sliding_window_moving_average:
window_size: 15
send_every: 15
send_first_at: 3
binary_sensor:
- platform: gpio
pin:
number: 14 #io1接人体感应器
inverted: TRUE
mode: INPUT
name: "客卫传感器 红外Pir检测"
device_class: motion
id: pir312
filters:
- invert:
- delayed_on_off: 300ms
- platform: gpio
pin:
number: 12
mode: INPUT
inverted: TRUE
name: "客卫传感器 雷达CW检测"
device_class: motion
id: ld1115
filters:
- invert:
- delayed_on_off: 300ms
on_press: #按下(有人),打开开关
then:
- if:
condition:
and:
- sensor.in_range:
id: illuminance
below: 10.0 #above超过 below低于
- binary_sensor.is_on: pir312 #同时满足红外人体感应器感应到人,和光强度低,才会打开开关
- switch.is_off: relay
then:
- logger.log: "Detected somebody activity"
- switch.turn_on: relay
else:
- logger.log: "There is no one around"
- switch.turn_off: relay
on_release: #松开(雷达检测不到人),关闭开关.
then:
- switch.turn_off: relay
# Example configuration entry
text_sensor:
- platform: custom
lambda: |-
auto my_custom_sensor = new UartReadLineSensor(id(uart_bus));
App.register_component(my_custom_sensor);
return {my_custom_sensor};
text_sensors:
id: uart_readline
name: "客卫传感器 串口输出"
- platform: wifi_info
ip_address:
name: 客卫传感器 IP地址
icon: "mdi:ip-network"
ssid:
name: 客卫传感器 接入点名称
icon: "mdi:network-pos"
bssid:
name: 客卫传感器 Router MAC地址
icon: "mdi:router-network"
mac_address:
name: 客卫传感器 本机MAC地址
icon: "mdi:router-network"
- platform: version
name: "客卫传感器 ESP版本"
hide_timestamp: true