本帖最后由 bugensui 于 2024-8-22 15:43 编辑
试试我的代码,星号的改成自己的,里面的ip改成自己这台存在传感器的内网ip,最好路由器端把它设成静态ip,下面是路由器网关地址,有些路由器是192.168.1.1. 下面是子网掩码,自己根据实际情况改,我买的很稳定,然后你编译试试,应该是可以用
esphome:
name: esp12f
friendly_name: esp12f
name_add_mac_suffix: yes
build_path: build/home-02
esp8266:
board: esp01_1m
# 启用日志记录
logger:
# 启用Home Assistant API
api:
encryption:
key: "MkCBW8LIV***********"
ota:
password: "dd0204********"
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# 如果wifi连接失败,启用后备热点(捕获门户)
manual_ip:
static_ip: 192.16****
gateway: 192.168.0.1
subnet: 255.255.255.0
ap:
ssid: "esp12f"
password: ""
captive_portal:
web_server:
port: 80
# 正确配置的I2C组件
i2c:
sda: GPIO4
scl: GPIO5
scan: True
# UART配置,用于LD2410传感器
uart:
id: uart_1
tx_pin: GPIO1
rx_pin: GPIO3
baud_rate: 256000
parity: NONE
stop_bits: 1
# LD2410传感器配置,调整以符合官方说明
ld2410:
uart_id: uart_1 # 指定使用的UART ID
switch:
- platform: ld2410
engineering_mode:
name: "engineering mode"
bluetooth:
name: "control bluetooth"
sensor:
- platform: uptime
id: uptime_s
update_interval: 5s
- platform: ld2410
light:
name: light
moving_distance:
name : Moving Distance
still_distance:
name: Still Distance
moving_energy:
name: Move Energy
still_energy:
name: Still Energy
detection_distance:
name: Detection Distance
# AHT10温湿度传感器配置,名称纠正
- platform: aht10
variant: AHT10
temperature:
name: "AHT10 Temperature"
filters:
- lambda: return x - 12.0;
humidity:
name: "AHT10 Humidity"
filters:
- lambda: return x + 21;
update_interval: 60s
# ADC光敏电阻传感器配置
- platform: adc
pin: A0
name: "Photoresistor"
id: photoresistor
unit_of_measurement: "%"
update_interval: 2s
filters:
# 基于原始值计算百分比
- lambda: |-
if (x <= 0.1) {
return 100;
} else if (x >= 0.75) {
return 1;
} else {
return (0.75 - x) / (0.75 - 0.1) * (100 - 1) + 8;
}
binary_sensor:
- platform: status
name: "esp12f Status"
- platform: ld2410
has_target:
name: Occupancy
id: Occupancy
icon: mdi:home #自定义图标
device_class: presence
has_moving_target:
name: Moving Target
has_still_target:
name: Still Target
out_pin_presence_status:
name: out pin presence status
# 基于光感+LD2410的存在检测
- platform: template
name: "Light Occupancy"
lambda: |-
int x = (id(photoresistor).state);
if (id(Occupancy).state && x <= 20) {
return true;
} else {
return false;
}
device_class: running
number:
- platform: ld2410
timeout:
name: timeout
max_move_distance_gate:
name: max move distance gate
max_still_distance_gate:
name: max still distance gate
button:
- platform: ld2410
#海凌科2410c恢复出厂设置 factory_reset:
#海凌科2410c恢复出厂设置 name: "factory reset"
restart:
name: "restart"
query_params:
name: query params
text_sensor:
- platform: version
name: version
- platform: wifi_info
ip_address:
name: "esp12f ip"
icon: mdi:ip
ssid:
name: ssid
icon: mdi:wifi
- platform: template
name: "Uptime"
lambda: |-
int seconds = (id(uptime_s).state);
int days = seconds / (24 * 3600);
seconds = seconds % (24 * 3600);
int hours = seconds / 3600;
seconds = seconds % 3600;
int minutes = seconds / 60;
seconds = seconds % 60;
return { (String(days) +"d " + String(hours) +"h " + String(minutes) +"m "+ String(seconds) +"s").c_str() };
icon: mdi:clock-start
update_interval: 5s
- platform: template
update_interval: 2s
name: "light sensor"
icon: mdi:brightness-5
# 添加新的lambda函数来显示有光,光照适中,没光
lambda: |-
int x = (id(photoresistor).state);
if (x <= 10) {
return {"无光"};
} else if (x > 10 && x <= 30) {
return {"光照适中"};
} else {
return {"有光"};
}
- platform: ld2410
version:
name: "hlk2410c version"
mac_address:
name: "hlk2410c mac"
select:
- platform: ld2410
distance_resolution:
name: "distance resolution"
|