本帖最后由 book123 于 2022-8-17 19:32 编辑
基于ESP32开发板之上,集合1115雷达、BH1750光照度、DHT11温湿度、热红外等传感模块的四合一传感器完整的esphome代码,其中1115可调节灵敏度。
共享给大家参考。(20220817对代码进行优化,如下)
esphome:
name: 换成你的信息
esp32:
board: esp32dev
framework:
type: arduino
# Enable logging
logger:
level: DEBUG #You Can Use "INFO" Level
baud_rate: 0 #disable logging over uart
# Enable Home Assistant API
api:
ota:
wifi:
ssid: "换成你的信息"
password: "换成你的信息"
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "换成你的信息"
password: "换成你的信息"
captive_portal:
# Enable Web
web_server:
port: 80
# Rada LD115H
binary_sensor:
- platform: gpio
pin: GPIO12
name: "LD115H Sensor"
device_class: motion
id: motion_01
#触发时打开GPIO2输出,点亮了板载LED
on_press:
- switch.turn_on: motion_01_light
#恢复时关闭GPIO2输出,熄灭了板载 LED
on_release:
- switch.turn_off: motion_01_light
switch:
- platform: gpio
pin: GPIO2
# inverted: true
name: "ESP32S-01-zhuwo body light"
id: motion_01_light
sensor:
# Wifi signal
- platform: wifi_signal
name: "ESP32-zhuwo WiFi Sensor"
update_interval: 60s
uart:
id: uart_bus
rx_pin: GPIO10
tx_pin: GPIO9
baud_rate: 115200
data_bits: 8
stop_bits: 1
parity: NONE
# debug:
# direction: BOTH
# dummy_receiver: true
# after:
# delimiter: "\n"
# sequence:
# - lambda: UARTDebug::log_string(direction, bytes);
number:
- platform: template
name: th1
id: human_presence_1_th1
min_value: 0
max_value: 500
initial_value: 120
optimistic: true
step: 10
restore_value: true
set_action:
- uart.write: !lambda
int th1v = (int)ceil(x);
std::string th1vs = "th1=" + to_string(th1v);
return std::vector<unsigned char>(th1vs.begin(), th1vs.end());
- delay: 3s
- uart.write: "save"
- platform: template
name: th2
id: human_presence_1_th2
min_value: 0
max_value: 1000
initial_value: 150
optimistic: true
step: 10
restore_value: true
set_action:
- uart.write: !lambda
int th2v = (int)ceil(x);
std::string th2vs = "th2= " + to_string(th2v);
return std::vector<unsigned char>(th2vs.begin(), th2vs.end());
- delay: 3s
- uart.write: "save"
- platform: template
name: dtime
id: human_presence_1_dtime
min_value: 0
max_value: 20
initial_value: 5
optimistic: true
step: 1
restore_value: true
unit_of_measurement: s
set_action:
- uart.write: !lambda
int dtimev = (int)ceil(x);
std::string dtimevs = "dtime=" + to_string(dtimev);
return std::vector<unsigned char>(dtimevs.begin(), dtimevs.end());
- delay: 3s
- uart.write: "save"
- platform: template
name: mov_sn
id: human_presence_1_mov_sn
min_value: 0
max_value: 10
initial_value: 3
optimistic: true
step: 1
restore_value: true
set_action:
- uart.write: !lambda
int mov_snv = (int)ceil(x);
std::string mov_snvs = "mov_sn=" + to_string(mov_snv);
return std::vector<unsigned char>(mov_snvs.begin(), mov_snvs.end());
- delay: 3s
- uart.write: "save"
- platform: template
name: occ_sn
id: human_presence_1_occ_sn
min_value: 0
max_value: 10
initial_value: 5
optimistic: true
step: 1
restore_value: true
set_action:
- uart.write: !lambda
int occ_snv = (int)ceil(x);
std::string occ_snvs = "occ_sn" + to_string(occ_snv);
return std::vector<unsigned char>(occ_snvs.begin(), occ_snvs.end());
- delay: 3s
- uart.write: "save"
在HA里:
|