Compare commits

...

79 Commits

Author SHA1 Message Date
sen
bc35b79fd0 make l13 support esphome 2025.12 2026-01-15 20:24:50 +08:00
sen
8a9176a8c1 remove cpu speed 2025-12-21 15:19:58 +08:00
sen
51ae28f4aa l12 support esphome 2025.10+, beta 2025-12-21 08:53:03 +08:00
sen
7691ec381b Merge branch 'main' of https://github.com/screekworkshop/screek-human-sensor 2025-11-15 08:03:50 +08:00
sen
2463b7df59 update for esphome 2025.10 2025-11-15 08:03:45 +08:00
sen
396e597e99 update 2a for esphome 2025.10.x 2025-11-15 07:51:08 +08:00
Screek Worshop
d33f5c98a2
Update README.md 2025-11-05 11:17:44 +08:00
sen
fbd3107cf1 Merge branch 'main' of https://github.com/screekworkshop/screek-human-sensor 2025-11-04 15:42:15 +08:00
sen
5d26858a95 update f2 support esphome 2025.10.4 2025-11-04 15:42:12 +08:00
Screek Worshop
56fd154edb
Update README.md 2025-05-31 22:42:29 +08:00
sen
33000d2c7d add L13 2025-03-31 12:54:06 +08:00
Screek Worshop
a0d04643a2
Update human-sensor-f2-stable.yaml 2025-03-19 14:48:58 +08:00
sen
4a46abca2c make l12 support esphome 2025.02.02 2025-03-13 19:56:18 +08:00
sen
db2b68d53d Update: Support ESPHome 2025.2.0, remove kernel modifications
- Added support for ESPHome 2025.2.0.
- Removed unnecessary kernel modifications.
- Thanks to Swisch_99, OwlBawl, and athua for their contributions.
2025-02-28 17:56:09 +08:00
sen
ae0cb8f694 rename 2024-10-16 20:59:35 +08:00
sen
dae3b64753 Experimental YAML Configurations for 1wx 2024-10-16 20:59:04 +08:00
sen
0a79c4488f l12-beta 2024-09-10 21:22:31 +08:00
sen
590cac7b7f Remove github filename suffixes 2024-08-08 08:03:42 +08:00
sen
3780f499c9 Introduced @durd 's patch to beta firmware, bumping the original beta firmware to STABLE. 2024-08-08 08:03:02 +08:00
Screek Worshop
34b12bb3fd
Merge pull request #25 from durd/durd-patch-1
dedup logs and published states
2024-08-08 07:27:23 +08:00
sen
b08ba8f8cc Create human-sensor-1wx-github.yaml 2024-08-01 14:16:20 +08:00
David
402c6f57f6
Merge branch 'screekworkshop:main' into durd-patch-1 2024-07-30 20:01:47 +02:00
sen
1b251de387 add save to config 2024-07-26 21:34:49 +08:00
sen
565e7147b7 bug fixed 2024-07-26 21:24:16 +08:00
David
31d40b75c9
changed logic and added update_interval to distance sensor
Changed ">" to ">=" for time comparison, else Clearance and Movement time could be between set interval and the next second.

Also added "update_interval" to Distance sensor, this replaces heartbeat filter but is still subject to delta filter.

Also made binary sensors publish initial state. Now HA isn't "unknown" after reset device.
2024-07-25 12:25:19 +02:00
David
e1d3438972
fix a quotation mark 2024-07-25 00:44:19 +02:00
David
01a2d1d9b1
Update human-sensor-f2-stable-github.yaml 2024-07-24 15:52:53 +02:00
David
11519a1373
dedup logs and published states 2024-07-24 14:05:23 +02:00
sen
06f5726673 Filter for the rare occurrence of "occ, dis=0.00" and treat it as a non-trigger. Thanks to erchina , durd_ for the feedback. 2024-07-21 17:38:24 +08:00
sen
3cdec91387 Remove some comments 2024-07-21 17:37:00 +08:00
sen
c34f2f8264 fix for #21, thx restauffer. 2024-07-17 08:05:46 +08:00
sen
48179d02f3 Merge branch 'main' of https://github.com/screekworkshop/screek-human-sensor 2024-05-16 20:48:25 +08:00
sen
bad4dca45c Sync the beta's current content to stable, considering they've been running for over 7 months. 2024-05-16 20:48:22 +08:00
sen
6f463c3b79 Increase the maximum timeout interval to 1800 seconds. 2024-05-16 20:47:35 +08:00
Screek Worshop
9b8f9fea27
Create README.md 2024-05-04 12:05:15 +08:00
sen
baf247c932 Create human-sensor-f2-stable-github.yaml 2024-05-04 12:00:32 +08:00
sen
c8e6fd3884 Extend the maximum timeout to 1800 seconds. (Thanks to Stefan Hampden for his feedback) 2024-05-01 20:04:31 +08:00
Screek Worshop
6c35ad0edc
Update README.md 2024-01-02 12:50:00 +08:00
Screek Worshop
a233c453a6
Merge pull request #11 from TheZoker/fix-entity-categroy
Fix entity category
2023-12-28 15:34:43 +08:00
Florian Gareis
c11b6e21fa Fix entity category 2023-12-28 02:16:07 +00:00
sen
6238924f63 Merge branch 'main' of https://github.com/screekworkshop/screek-human-sensor 2023-10-17 23:48:20 +08:00
sen
d9ab720b14 Fix a syntax error in the check region judgment (code suggestion from Cossid) 2023-10-17 23:48:16 +08:00
Screek Worshop
9a237b7355
Merge pull request #7 from LaneaLucy/main
update Illuminance at least every 60 seconds, even if value not changed
2023-10-13 20:52:59 +08:00
Lanea Lucy S
0d366088b0 forget the force_update 2023-10-13 02:25:07 +02:00
Lanea Lucy S
4e3dd082fb update Illuminance at least every 60 seconds, even if value not changed 2023-10-13 01:59:22 +02:00
sen
4f6a13ee3d Update human-sensor-2a-beta-github.yaml
- Show target angle display, orientation and position status display. (It got the idea and key code from walberjunior.)
- Added a Zone global switch that can be turned off when the Zone feature is not needed. This may reduce the number of zone triggers if there are too many people.
- Adjusts the icons for target X and Y.
-
2023-09-08 16:38:45 +08:00
sen
a78e9b8050 Move infrequently used settings to the debug area, introduce a patch for haip to deal with the unstable state at startup, and fix the delay at startup that causes the zone presence state to become unknown. Corresponding to the public version: V230908_2_beta. 2023-09-08 11:47:36 +08:00
sen
509b209523 update stable version 2023-09-08 10:23:00 +08:00
sen
b60cc289f1 Fixed type of name, note that this may cause automation to need to re-correct references. 2023-09-06 20:41:31 +08:00
sen
291a4d4ba8 Update human-sensor-2a-beta-github.yaml
Fixed an issue where repeated triggers on the way to a delayed shutdown would not interrupt the cancel.Added Any Presence Timeout.(feedback from haip, code contributed by athua.)
2023-09-06 20:14:32 +08:00
sen
ed74f58897 Added Any Presence Timeout.(feedback from ferbulous, code contributed by athua.) 2023-09-05 18:07:37 +08:00
Screek Worshop
d8018761b8
Fix external library dependencies, thanks to Tiep Pham Minh for feedback. 2023-09-04 11:52:05 +08:00
sen
3df23400dc Tweak code to include region timeout support for athua. 2023-09-02 12:18:42 +08:00
sen
503ee2a2b6 Update human-sensor-2a-beta-github.yaml
Extending the x-axis maximum area to 4000 synthesizes athua's suggestion.
2023-08-29 12:09:11 +08:00
sen
33ea448705 Update human-sensor-2a-beta-github.yaml
Adjust the timing of the push initialization message to ensure that everything is initialized.
2023-08-29 12:08:07 +08:00
sen
8072db6e39 Optimize the last light update logic to ensure that switching fast update mode does not cause a delay in the update. (Thanks to rob_sm7219for for the feedback) 2023-08-28 17:47:43 +08:00
sen
71b88d18f9 Limit the detection distance of the X-axis to 3m left and right (thx to walberjunior) 2023-08-28 17:41:56 +08:00
sen
fc5eb97acb fix x_begin, thx walberjunior. 2023-08-28 17:35:31 +08:00
Screek Worshop
276ff4e8a5
fix last_illuminance with 0 if no light can cause na in ha. 2023-08-23 18:04:46 +08:00
Screek Worshop
c399570894
Update README.md 2023-08-21 18:53:30 +08:00
sen
226a6f4bec use external components from github repo 2023-08-21 18:51:00 +08:00
sen
1f7fbccb0f Update human-sensor-2a-beta-github.yaml 2023-08-21 18:23:40 +08:00
sen
0635c3cb7f add 2a beta, and fix some type. 2023-08-21 18:13:25 +08:00
sen
d4083a26cc Merge branch 'main' of https://github.com/screekworkshop/screek-human-sensor 2023-08-19 11:26:12 +08:00
sen
b8a7ed607a support 1m(s) 2023-08-19 11:26:07 +08:00
Screek Worshop
1562f0f29d
Update README.md 2023-08-15 13:51:11 +08:00
Screek Worshop
4b79dadc3d
Update README.md 2023-08-15 13:49:50 +08:00
sen
4202ddc4ba Merge branch 'main' of https://github.com/screekworkshop/screek-human-sensor 2023-08-10 19:31:50 +08:00
sen
fdb388f434 Update a beta 1w yaml source, it won't depend on a separate catalog library anymore. 2023-08-10 19:31:47 +08:00
Screek Worshop
3b1445fccb
Update screek-humen-sensor-2a.yaml
Thanks to JurnD for pointing out that we miscalculated a byte count on the distance resolution of p3.
2023-07-29 10:44:15 +08:00
sen
82ad16d842 Restructuring of directory 2a 2023-07-24 09:19:07 +08:00
sen
576fc9aa56 Create screek-humen-sensor-2a.yaml 2023-07-24 09:18:10 +08:00
sen
d1d0f3dd15 disable ota safemode 2023-07-18 07:16:10 +08:00
sen
3f36985241 Reduce the update interval of debug information 2023-07-07 17:45:16 +08:00
sen
b1bfbc231a remove dashboard import mode 2023-07-03 21:42:21 +08:00
sen
071f37aa44 beta-kick in ota firmware 2023-07-03 19:30:30 +08:00
Screek Worshop
0fd57d35fd
Update README.md 2023-07-02 10:26:16 +08:00
Screek Worshop
540b4e427d
Update README.md 2023-07-02 10:25:42 +08:00
Screek Worshop
7ef087d9fe
Create README.md 2023-07-02 10:25:09 +08:00
22 changed files with 3689 additions and 889 deletions

View File

@ -0,0 +1,181 @@
esphome:
name: humen-sensor-1m
comment: Human Sensor 1M
friendly_name: Human Sensor 1M
name_add_mac_suffix: True
platformio_options:
board_build.flash_mode: dio
project:
name: Screek.Human_Sensor
version: 1M
external_components:
- source:
type: git
url: https://github.com/screekworkshop/custom_components_support_for_screek_1w
ref: main
components: [uart, ld2410]
esp32:
board: lolin_c3_mini
framework:
type: arduino
version: 2.0.9
platform_version: 6.3.2
logger:
hardware_uart: uart0
api:
ota:
password: "YOUR_OTA_PASSWORD"
wifi:
# ssid: !secret wifi_ssid
# password: !secret wifi_password
# fast_connect: True
power_save_mode: LIGHT
# output_power: 20dB
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "HUMAN-SENSOR 1M"
captive_portal:
web_server:
port: 80
binary_sensor:
- platform: status
name: Online
id: ink_ha_connected
- platform: ld2410
has_target:
name: Presence
has_moving_target:
name: Moving Target
has_still_target:
name: Still Target
sensor:
- platform: template
id: sys_esp_temperature
name: ESP Temperature
lambda: return temperatureRead();
unit_of_measurement: °C
device_class: TEMPERATURE
update_interval: 30s
entity_category: "diagnostic"
- platform: uptime
name: Uptime
id: sys_uptime
update_interval: 10s
- platform: wifi_signal
name: RSSI
id: wifi_signal_db
update_interval: 1s
entity_category: "diagnostic"
- platform: template
id: esp_memory
icon: mdi:memory
name: ESP Free Memory
lambda: return heap_caps_get_free_size(MALLOC_CAP_INTERNAL) / 1024;
unit_of_measurement: 'kB'
state_class: measurement
entity_category: "diagnostic"
- platform: ld2410
moving_distance:
name : Moving Distance
id: moving_distance
still_distance:
name: Still Distance
id: still_distance
moving_energy:
name: Move Energy
still_energy:
name: Still Energy
detection_distance:
name: Detection Distance
light:
name: Sun Light
light:
- platform: status_led
name: sys_status
pin:
number: GPIO8
inverted: True
internal: True
restore_mode: ALWAYS_OFF
time:
- platform: sntp
id: time_now
servers:
- ntp.aliyun.com
uart:
id: uart_ld2410
tx_pin: GPIO4
rx_pin: GPIO3
baud_rate: 256000
parity: NONE
stop_bits: 1
ld2410:
timeout: 150s
id: ld2410_radar
# max_move_distance : 6m
# max_still_distance: 0.75m
# g0_move_threshold: 10
# g0_still_threshold: 20
# g1_move_threshold: 10
# g1_still_threshold: 20
# g2_move_threshold: 20
# g2_still_threshold: 21
# g3_move_threshold: 30
# g3_still_threshold: 31
# g4_move_threshold: 40
# g4_still_threshold: 41
# g5_move_threshold: 50
# g5_still_threshold: 51
# g6_move_threshold: 60
# g6_still_threshold: 61
# g7_move_threshold: 70
# g7_still_threshold: 71
# g8_move_threshold: 80
# g8_still_threshold: 81
button:
- platform: template
name: "Enable LD2410 BLE"
entity_category: "config"
icon: mdi:bluetooth
on_press:
lambda: |-
id(ld2410_radar) -> ble_control(true);
- platform: template
name: "Disable LD2410 BLE"
entity_category: "config"
icon: mdi:bluetooth-off
on_press:
lambda: |-
id(ld2410_radar) -> ble_control(false);
- platform: template
name: "LD2410 Reboot"
icon: mdi:radar
entity_category: "config"
on_press:
lambda: |-
// auto* radar = LD2410Component::get(ld2410);
// radar -> roboot();
id(ld2410_radar) -> reboot();
- platform: restart
icon: mdi:power-cycle
name: "ESP Reboot"
- platform: factory_reset
disabled_by_default: True
name: Factory Reset
id: factory_reset_all

View File

@ -1,5 +1,5 @@
# This is a custom firmware for Human Presence Sensor 1U # This is a custom firmware for Human Presence Sensor 1U
# https://screek.tech # https://screek.io/1u
esphome: esphome:
name: screek-humen-sensor-1u name: screek-humen-sensor-1u
@ -9,22 +9,10 @@ esphome:
platformio_options: platformio_options:
board_build.flash_mode: dio board_build.flash_mode: dio
board_build.f_cpu: 80000000L board_build.f_cpu: 80000000L
on_boot:
priority: 900
then:
lambda: |-
// id(wake_up_reason) = esp_sleep_get_wakeup_cause();
id(cpu_speed) = ESP.getCpuFreqMHz() ;
project: project:
name: Screek.Human_Presence_Sensor name: Screek.Human_Presence_Sensor
version: 1U version: 1U
min_version: 2023.6.1 min_version: 2025.5.1
globals:
- id: cpu_speed
type: int
restore_value: no
initial_value: '0'
external_components: external_components:
# - source: github://screek-workshop/custom_components_support_for_screek_1u # - source: github://screek-workshop/custom_components_support_for_screek_1u
@ -32,14 +20,12 @@ external_components:
type: git type: git
url: https://github.com/screek-workshop/custom_components_support_for_screek_1u url: https://github.com/screek-workshop/custom_components_support_for_screek_1u
ref: master ref: master
# components: [ ld2410, uart ] components: [ ld2410 ]
esp32: esp32:
board: lolin_s2_mini board: lolin_s2_mini
framework: framework:
type: arduino type: esp-idf
version: 2.0.9
platform_version: 6.3.2
improv_serial: improv_serial:
@ -51,17 +37,15 @@ api:
# key: "YOUR-API-PASSWORD" # key: "YOUR-API-PASSWORD"
ota: ota:
# This won't work for the original firmware(we use diffrent ota password), - platform: esphome
# so if you want to turn it into your own OTA, # use your own ota password plz. this is a words by Socrates.
# make sure to completely flash your custom yaml in the firmware once.
# after that, you may always ota with your own password.
password: "all-things-in-their-being-are-good-for-something" # words by Socrates password: "all-things-in-their-being-are-good-for-something" # words by Socrates
# By automatically importing to the console, # By automatically importing to the console,
# subsequent adjustments can be easily made without having to manually fix a specific name. # subsequent adjustments can be easily made without having to manually fix a specific name.
dashboard_import: # dashboard_import:
package_import_url: github://screekworkshop/screek-human-sensor/1u/yaml/Screek-Humen-Dectet-1u.yaml@2023.06 # package_import_url: github://screekworkshop/screek-human-sensor/1u/yaml/Screek-Humen-Dectet-1u.yaml@2023.06
import_full_config: True # import_full_config: False
wifi: wifi:
# power_save_mode: NONE # power_save_mode: NONE
@ -90,29 +74,12 @@ binary_sensor:
name: Still Target name: Still Target
sensor: sensor:
- platform: template - platform: internal_temperature
name: "ESP Cpu Speed"
accuracy_decimals: 0
unit_of_measurement: Mhz
lambda: |-
return (id(cpu_speed));
entity_category: "diagnostic"
# - platform: internal_temperature
# id: sys_esp_temperature
# name: ESP Temperature
# unit_of_measurement: °C
# device_class: TEMPERATURE
# update_interval: 1s
# entity_category: "diagnostic"
- platform: template
id: sys_esp_temperature id: sys_esp_temperature
name: ESP Temperature name: ESP Temperature
lambda: return temperatureRead();
unit_of_measurement: °C unit_of_measurement: °C
device_class: TEMPERATURE device_class: TEMPERATURE
update_interval: 5s update_interval: 45s
entity_category: "diagnostic" entity_category: "diagnostic"
- platform: uptime - platform: uptime

Binary file not shown.

Binary file not shown.

View File

@ -1,16 +1,20 @@
esphome: esphome:
name: screek-humen-dectet-1w name: screek-humen-sensor-1w
comment: Screek Human Presence Sensor 24GHz PS-HPS comment: Screek Human Sensor 1W
friendly_name: Screek Human Presence Sensor friendly_name: Human Sensor 1W
name_add_mac_suffix: True name_add_mac_suffix: True
platformio_options: platformio_options:
board_build.flash_mode: dio board_build.flash_mode: dio
project: project:
name: Screek.Human_Presence_Sensor name: Screek.Human_Sensor
version: 1W version: 1W
external_components: external_components:
- source: screek-mod-components - source:
type: git
url: https://github.com/screekworkshop/custom_components_support_for_screek_1w
ref: main
components: [uart, ld2410]
esp32: esp32:
board: esp32-c3-devkitm-1 board: esp32-c3-devkitm-1
@ -99,7 +103,7 @@ time:
- ntp.aliyun.com - ntp.aliyun.com
uart: uart:
id: uart1 id: uart_ld2410
tx_pin: GPIO5 tx_pin: GPIO5
rx_pin: GPIO4 rx_pin: GPIO4
baud_rate: 256000 baud_rate: 256000

View File

@ -1,158 +0,0 @@
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import uart
from esphome.const import CONF_ID, CONF_TIMEOUT
from esphome import automation
from esphome.automation import maybe_simple_id
DEPENDENCIES = ["uart"]
CODEOWNERS = ["@sebcaps"]
MULTI_CONF = True
ld2410_ns = cg.esphome_ns.namespace("ld2410")
LD2410Component = ld2410_ns.class_("LD2410Component", cg.Component, uart.UARTDevice)
LD2410Restart = ld2410_ns.class_("LD2410Restart", automation.Action)
CONF_LD2410_ID = "ld2410_id"
CONF_MAX_MOVE_DISTANCE = "max_move_distance"
CONF_MAX_STILL_DISTANCE = "max_still_distance"
CONF_G0_MOVE_THRESHOLD = "g0_move_threshold"
CONF_G0_STILL_THRESHOLD = "g0_still_threshold"
CONF_G1_MOVE_THRESHOLD = "g1_move_threshold"
CONF_G1_STILL_THRESHOLD = "g1_still_threshold"
CONF_G2_MOVE_THRESHOLD = "g2_move_threshold"
CONF_G2_STILL_THRESHOLD = "g2_still_threshold"
CONF_G3_MOVE_THRESHOLD = "g3_move_threshold"
CONF_G3_STILL_THRESHOLD = "g3_still_threshold"
CONF_G4_MOVE_THRESHOLD = "g4_move_threshold"
CONF_G4_STILL_THRESHOLD = "g4_still_threshold"
CONF_G5_MOVE_THRESHOLD = "g5_move_threshold"
CONF_G5_STILL_THRESHOLD = "g5_still_threshold"
CONF_G6_MOVE_THRESHOLD = "g6_move_threshold"
CONF_G6_STILL_THRESHOLD = "g6_still_threshold"
CONF_G7_MOVE_THRESHOLD = "g7_move_threshold"
CONF_G7_STILL_THRESHOLD = "g7_still_threshold"
CONF_G8_MOVE_THRESHOLD = "g8_move_threshold"
CONF_G8_STILL_THRESHOLD = "g8_still_threshold"
DISTANCES = [0.75, 1.5, 2.25, 3, 3.75, 4.5, 5.25, 6]
CONFIG_SCHEMA = cv.All(
cv.Schema(
{
cv.GenerateID(): cv.declare_id(LD2410Component),
cv.Optional(CONF_MAX_MOVE_DISTANCE, default="4.5m"): cv.All(
cv.distance, cv.one_of(*DISTANCES, float=True)
),
cv.Optional(CONF_MAX_STILL_DISTANCE, default="4.5m"): cv.All(
cv.distance, cv.one_of(*DISTANCES, float=True)
),
cv.Optional(CONF_TIMEOUT, default="5s"): cv.All(
cv.positive_time_period_seconds,
cv.Range(max=cv.TimePeriod(seconds=32767)),
),
cv.Optional(CONF_G0_MOVE_THRESHOLD, default=50): cv.int_range(
min=0, max=100
),
cv.Optional(CONF_G0_STILL_THRESHOLD, default=0): cv.int_range(
min=0, max=100
),
cv.Optional(CONF_G1_MOVE_THRESHOLD, default=50): cv.int_range(
min=0, max=100
),
cv.Optional(CONF_G1_STILL_THRESHOLD, default=0): cv.int_range(
min=0, max=100
),
cv.Optional(CONF_G2_MOVE_THRESHOLD, default=40): cv.int_range(
min=0, max=100
),
cv.Optional(CONF_G2_STILL_THRESHOLD, default=40): cv.int_range(
min=0, max=100
),
cv.Optional(CONF_G3_MOVE_THRESHOLD, default=40): cv.int_range(
min=0, max=100
),
cv.Optional(CONF_G3_STILL_THRESHOLD, default=40): cv.int_range(
min=0, max=100
),
cv.Optional(CONF_G4_MOVE_THRESHOLD, default=40): cv.int_range(
min=0, max=100
),
cv.Optional(CONF_G4_STILL_THRESHOLD, default=40): cv.int_range(
min=0, max=100
),
cv.Optional(CONF_G5_MOVE_THRESHOLD, default=40): cv.int_range(
min=0, max=100
),
cv.Optional(CONF_G5_STILL_THRESHOLD, default=40): cv.int_range(
min=0, max=100
),
cv.Optional(CONF_G6_MOVE_THRESHOLD, default=30): cv.int_range(
min=0, max=100
),
cv.Optional(CONF_G6_STILL_THRESHOLD, default=15): cv.int_range(
min=0, max=100
),
cv.Optional(CONF_G7_MOVE_THRESHOLD, default=30): cv.int_range(
min=0, max=100
),
cv.Optional(CONF_G7_STILL_THRESHOLD, default=15): cv.int_range(
min=0, max=100
),
cv.Optional(CONF_G8_MOVE_THRESHOLD, default=30): cv.int_range(
min=0, max=100
),
cv.Optional(CONF_G8_STILL_THRESHOLD, default=15): cv.int_range(
min=0, max=100
),
}
)
.extend(uart.UART_DEVICE_SCHEMA)
.extend(cv.COMPONENT_SCHEMA)
)
FINAL_VALIDATE_SCHEMA = uart.final_validate_device_schema(
"ld2410",
baud_rate=256000,
require_tx=True,
require_rx=True,
parity="NONE",
stop_bits=1,
)
async def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])
await cg.register_component(var, config)
await uart.register_uart_device(var, config)
cg.add(var.set_timeout(config[CONF_TIMEOUT]))
cg.add(var.set_max_move_distance(int(config[CONF_MAX_MOVE_DISTANCE] / 0.75)))
cg.add(var.set_max_still_distance(int(config[CONF_MAX_STILL_DISTANCE] / 0.75)))
cg.add(
var.set_range_config(
config[CONF_G0_MOVE_THRESHOLD],
config[CONF_G0_STILL_THRESHOLD],
config[CONF_G1_MOVE_THRESHOLD],
config[CONF_G1_STILL_THRESHOLD],
config[CONF_G2_MOVE_THRESHOLD],
config[CONF_G2_STILL_THRESHOLD],
config[CONF_G3_MOVE_THRESHOLD],
config[CONF_G3_STILL_THRESHOLD],
config[CONF_G4_MOVE_THRESHOLD],
config[CONF_G4_STILL_THRESHOLD],
config[CONF_G5_MOVE_THRESHOLD],
config[CONF_G5_STILL_THRESHOLD],
config[CONF_G6_MOVE_THRESHOLD],
config[CONF_G6_STILL_THRESHOLD],
config[CONF_G7_MOVE_THRESHOLD],
config[CONF_G7_STILL_THRESHOLD],
config[CONF_G8_MOVE_THRESHOLD],
config[CONF_G8_STILL_THRESHOLD],
)
)
CALIBRATION_ACTION_SCHEMA = maybe_simple_id(
{
cv.Required(CONF_ID): cv.use_id(LD2410Component),
}
)

View File

@ -1,36 +0,0 @@
import esphome.codegen as cg
from esphome.components import binary_sensor
import esphome.config_validation as cv
from esphome.const import DEVICE_CLASS_MOTION, DEVICE_CLASS_OCCUPANCY
from . import CONF_LD2410_ID, LD2410Component
DEPENDENCIES = ["ld2410"]
CONF_HAS_TARGET = "has_target"
CONF_HAS_MOVING_TARGET = "has_moving_target"
CONF_HAS_STILL_TARGET = "has_still_target"
CONFIG_SCHEMA = {
cv.GenerateID(CONF_LD2410_ID): cv.use_id(LD2410Component),
cv.Optional(CONF_HAS_TARGET): binary_sensor.binary_sensor_schema(
device_class=DEVICE_CLASS_OCCUPANCY
),
cv.Optional(CONF_HAS_MOVING_TARGET): binary_sensor.binary_sensor_schema(
device_class=DEVICE_CLASS_MOTION
),
cv.Optional(CONF_HAS_STILL_TARGET): binary_sensor.binary_sensor_schema(
device_class=DEVICE_CLASS_OCCUPANCY
),
}
async def to_code(config):
ld2410_component = await cg.get_variable(config[CONF_LD2410_ID])
if CONF_HAS_TARGET in config:
sens = await binary_sensor.new_binary_sensor(config[CONF_HAS_TARGET])
cg.add(ld2410_component.set_target_sensor(sens))
if CONF_HAS_MOVING_TARGET in config:
sens = await binary_sensor.new_binary_sensor(config[CONF_HAS_MOVING_TARGET])
cg.add(ld2410_component.set_moving_target_sensor(sens))
if CONF_HAS_STILL_TARGET in config:
sens = await binary_sensor.new_binary_sensor(config[CONF_HAS_STILL_TARGET])
cg.add(ld2410_component.set_still_target_sensor(sens))

View File

@ -1,416 +0,0 @@
#include "ld2410.h"
#define highbyte(val) (uint8_t)((val) >> 8)
#define lowbyte(val) (uint8_t)((val) &0xff)
namespace esphome {
namespace ld2410 {
static const char *const TAG = "ld2410";
void LD2410Component::dump_config() {
ESP_LOGCONFIG(TAG, "LD2410:");
#ifdef USE_BINARY_SENSOR
LOG_BINARY_SENSOR(" ", "HasTargetSensor", this->target_binary_sensor_);
LOG_BINARY_SENSOR(" ", "MovingSensor", this->moving_binary_sensor_);
LOG_BINARY_SENSOR(" ", "StillSensor", this->still_binary_sensor_);
#endif
#ifdef USE_SENSOR
LOG_SENSOR(" ", "Moving Distance", this->moving_target_distance_sensor_);
LOG_SENSOR(" ", "Still Distance", this->still_target_distance_sensor_);
LOG_SENSOR(" ", "Moving Energy", this->moving_target_energy_sensor_);
LOG_SENSOR(" ", "Still Energy", this->still_target_energy_sensor_);
LOG_SENSOR(" ", "Detection Distance", this->detection_distance_sensor_);
LOG_SENSOR(" ", "Light", this->light_sensor_);
#endif
this->set_config_mode_(true);
this->get_version_();
this->set_config_mode_(false);
ESP_LOGCONFIG(TAG, " Firmware Version : %u.%u.%u%u%u%u", this->version_[0], this->version_[1], this->version_[2],
this->version_[3], this->version_[4], this->version_[5]);
}
void LD2410Component::setup() {
ESP_LOGCONFIG(TAG, "Setting up LD2410...");
// ESP_LOGCONFIG(TAG, "Apply screek patch...");
this->set_config_mode_(true);
/*
this->set_max_distances_timeout_(this->max_move_distance_, this->max_still_distance_, this->timeout_);
// Configure Gates sensitivity
this->set_gate_threshold_(0, this->rg0_move_threshold_, this->rg0_still_threshold_);
this->set_gate_threshold_(1, this->rg1_move_threshold_, this->rg1_still_threshold_);
this->set_gate_threshold_(2, this->rg2_move_threshold_, this->rg2_still_threshold_);
this->set_gate_threshold_(3, this->rg3_move_threshold_, this->rg3_still_threshold_);
this->set_gate_threshold_(4, this->rg4_move_threshold_, this->rg4_still_threshold_);
this->set_gate_threshold_(5, this->rg5_move_threshold_, this->rg5_still_threshold_);
this->set_gate_threshold_(6, this->rg6_move_threshold_, this->rg6_still_threshold_);
this->set_gate_threshold_(7, this->rg7_move_threshold_, this->rg7_still_threshold_);
this->set_gate_threshold_(8, this->rg8_move_threshold_, this->rg8_still_threshold_);
*/
this->get_version_();
this->set_config_mode_(false);
// this->factory_mode(true);
ESP_LOGCONFIG(TAG, "Firmware Version : %u.%u.%u%u%u%u", this->version_[0], this->version_[1], this->version_[2],
this->version_[3], this->version_[4], this->version_[5]);
ESP_LOGCONFIG(TAG, "LD2410 setup complete.");
}
void LD2410Component::loop() {
const int max_line_length = 80;
static uint8_t buffer[max_line_length];
while (available()) {
this->readline_(read(), buffer, max_line_length);
}
}
void LD2410Component::send_command_(uint8_t command, uint8_t *command_value, int command_value_len) {
// lastCommandSuccess->publish_state(false);
// frame start bytes
this->write_array(CMD_FRAME_HEADER, 4);
// length bytes
int len = 2;
if (command_value != nullptr)
len += command_value_len;
this->write_byte(lowbyte(len));
this->write_byte(highbyte(len));
// command
this->write_byte(lowbyte(command));
this->write_byte(highbyte(command));
// command value bytes
if (command_value != nullptr) {
for (int i = 0; i < command_value_len; i++) {
this->write_byte(command_value[i]);
}
}
// frame end bytes
this->write_array(CMD_FRAME_END, 4);
// FIXME to remove
delay(50); // NOLINT
}
long map(long x, long in_min, long in_max, long out_min, long out_max) {
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
void LD2410Component::handle_periodic_data_(uint8_t *buffer, int len) {
if (len < 12)
return; // 4 frame start bytes + 2 length bytes + 1 data end byte + 1 crc byte + 4 frame end bytes
if (buffer[0] != 0xF4 || buffer[1] != 0xF3 || buffer[2] != 0xF2 || buffer[3] != 0xF1) // check 4 frame start bytes
return;
if (buffer[7] != HEAD || buffer[len - 6] != END || buffer[len - 5] != CHECK) // Check constant values
return; // data head=0xAA, data end=0x55, crc=0x00
/*
Data Type: 6th
0x01: Engineering mode
0x02: Normal mode
*/
// char data_type = buffer[DATA_TYPES];
/*
Target states: 9th
0x00 = No target
0x01 = Moving targets
0x02 = Still targets
0x03 = Moving+Still targets
*/
#ifdef USE_BINARY_SENSOR
char target_state = buffer[TARGET_STATES];
if (this->target_binary_sensor_ != nullptr) {
this->target_binary_sensor_->publish_state(target_state != 0x00);
}
#endif
/*
Reduce data update rate to prevent home assistant database size grow fast
*/
int32_t current_millis = millis();
if (current_millis - last_periodic_millis < 1000)
return;
last_periodic_millis = current_millis;
#ifdef USE_BINARY_SENSOR
if (this->moving_binary_sensor_ != nullptr) {
this->moving_binary_sensor_->publish_state(CHECK_BIT(target_state, 0));
}
if (this->still_binary_sensor_ != nullptr) {
this->still_binary_sensor_->publish_state(CHECK_BIT(target_state, 1));
}
#endif
/*
Moving target distance: 10~11th bytes
Moving target energy: 12th byte
Still target distance: 13~14th bytes
Still target energy: 15th byte
Detect distance: 16~17th bytes
*/
#ifdef USE_SENSOR
if (this->moving_target_distance_sensor_ != nullptr) {
int new_moving_target_distance = this->two_byte_to_int_(buffer[MOVING_TARGET_LOW], buffer[MOVING_TARGET_HIGH]);
if (this->moving_target_distance_sensor_->get_state() != new_moving_target_distance)
this->moving_target_distance_sensor_->publish_state(new_moving_target_distance);
}
if (this->moving_target_energy_sensor_ != nullptr) {
int new_moving_target_energy = buffer[MOVING_ENERGY];
if (this->moving_target_energy_sensor_->get_state() != new_moving_target_energy)
this->moving_target_energy_sensor_->publish_state(new_moving_target_energy);
}
if (this->still_target_distance_sensor_ != nullptr) {
int new_still_target_distance = this->two_byte_to_int_(buffer[STILL_TARGET_LOW], buffer[STILL_TARGET_HIGH]);
if (this->still_target_distance_sensor_->get_state() != new_still_target_distance)
this->still_target_distance_sensor_->publish_state(new_still_target_distance);
}
if (this->still_target_energy_sensor_ != nullptr) {
int new_still_target_energy = buffer[STILL_ENERGY];
if (this->still_target_energy_sensor_->get_state() != new_still_target_energy)
this->still_target_energy_sensor_->publish_state(new_still_target_energy);
}
if (this->detection_distance_sensor_ != nullptr) {
int new_detect_distance = this->two_byte_to_int_(buffer[DETECT_DISTANCE_LOW], buffer[DETECT_DISTANCE_HIGH]);
if (this->detection_distance_sensor_->get_state() != new_detect_distance)
this->detection_distance_sensor_->publish_state(new_detect_distance);
}
if (this->light_sensor_ != nullptr) {
int data_type = buffer[6];
int new_light = -1;
if (data_type == 0x01){ // 0x01 = 工程模式!
new_light = buffer[37];
new_light = map(new_light, 85, 255, 0, 100);
if (new_light < 0){
new_light = 0;
}
if (new_light > 100){
new_light = 100;
}
ESP_LOGD(TAG,"LD2410 Sun Light: %d%%", new_light);
}else{
int32_t now_millis = millis();
if (now_millis - last_change_fatory_mode_millis > 2000){
ESP_LOGD(TAG,"Normal mode no light, change to factory mode");
this->factory_mode(true);
last_change_fatory_mode_millis = now_millis;
}
}
if (this->light_sensor_->get_state() != new_light){
this->light_sensor_->publish_state(new_light);
}
}
#endif
}
void LD2410Component::handle_ack_data_(uint8_t *buffer, int len) {
ESP_LOGV(TAG, "Handling ACK DATA for COMMAND");
if (len < 10) {
ESP_LOGE(TAG, "Error with last command : incorrect length");
return;
}
if (buffer[0] != 0xFD || buffer[1] != 0xFC || buffer[2] != 0xFB || buffer[3] != 0xFA) { // check 4 frame start bytes
ESP_LOGE(TAG, "Error with last command : incorrect Header");
return;
}
if (buffer[COMMAND_STATUS] != 0x01) {
ESP_LOGE(TAG, "Error with last command : status != 0x01");
return;
}
if (this->two_byte_to_int_(buffer[8], buffer[9]) != 0x00) {
ESP_LOGE(TAG, "Error with last command , last buffer was: %u , %u", buffer[8], buffer[9]);
return;
}
switch (buffer[COMMAND]) {
case lowbyte(CMD_ENABLE_CONF):
ESP_LOGV(TAG, "Handled Enable conf command");
break;
case lowbyte(CMD_DISABLE_CONF):
ESP_LOGV(TAG, "Handled Disabled conf command");
break;
case lowbyte(CMD_VERSION):
ESP_LOGV(TAG, "FW Version is: %u.%u.%u%u%u%u", buffer[13], buffer[12], buffer[17], buffer[16], buffer[15],
buffer[14]);
this->version_[0] = buffer[13];
this->version_[1] = buffer[12];
this->version_[2] = buffer[17];
this->version_[3] = buffer[16];
this->version_[4] = buffer[15];
this->version_[5] = buffer[14];
break;
case lowbyte(CMD_GATE_SENS):
ESP_LOGV(TAG, "Handled sensitivity command");
break;
case lowbyte(CMD_QUERY): // Query parameters response
{
if (buffer[10] != 0xAA)
return; // value head=0xAA
/*
Moving distance range: 13th byte
Still distance range: 14th byte
*/
// TODO
// maxMovingDistanceRange->publish_state(buffer[12]);
// maxStillDistanceRange->publish_state(buffer[13]);
/*
Moving Sensitivities: 15~23th bytes
Still Sensitivities: 24~32th bytes
*/
for (int i = 0; i < 9; i++) {
moving_sensitivities[i] = buffer[14 + i];
}
for (int i = 0; i < 9; i++) {
still_sensitivities[i] = buffer[23 + i];
}
/*
None Duration: 33~34th bytes
*/
// noneDuration->publish_state(this->two_byte_to_int_(buffer[32], buffer[33]));
} break;
default:
break;
}
}
void LD2410Component::readline_(int readch, uint8_t *buffer, int len) {
static int pos = 0;
if (readch >= 0) {
if (pos < len - 1) {
buffer[pos++] = readch;
buffer[pos] = 0;
} else {
pos = 0;
}
if (pos >= 4) {
if (buffer[pos - 4] == 0xF8 && buffer[pos - 3] == 0xF7 && buffer[pos - 2] == 0xF6 && buffer[pos - 1] == 0xF5) {
ESP_LOGV(TAG, "Will handle Periodic Data");
this->handle_periodic_data_(buffer, pos);
pos = 0; // Reset position index ready for next time
} else if (buffer[pos - 4] == 0x04 && buffer[pos - 3] == 0x03 && buffer[pos - 2] == 0x02 &&
buffer[pos - 1] == 0x01) {
ESP_LOGV(TAG, "Will handle ACK Data");
this->handle_ack_data_(buffer, pos);
pos = 0; // Reset position index ready for next time
}
}
}
}
void LD2410Component::set_config_mode_(bool enable) {
uint8_t cmd = enable ? CMD_ENABLE_CONF : CMD_DISABLE_CONF;
uint8_t cmd_value[2] = {0x01, 0x00};
this->send_command_(cmd, enable ? cmd_value : nullptr, 2);
}
void LD2410Component::query_parameters_() { this->send_command_(CMD_QUERY, nullptr, 0); }
void LD2410Component::get_version_() { this->send_command_(CMD_VERSION, nullptr, 0); }
void LD2410Component::set_max_distances_timeout_(uint8_t max_moving_distance_range, uint8_t max_still_distance_range,
uint16_t timeout) {
uint8_t value[18] = {0x00,
0x00,
lowbyte(max_moving_distance_range),
highbyte(max_moving_distance_range),
0x00,
0x00,
0x01,
0x00,
lowbyte(max_still_distance_range),
highbyte(max_still_distance_range),
0x00,
0x00,
0x02,
0x00,
lowbyte(timeout),
highbyte(timeout),
0x00,
0x00};
this->send_command_(CMD_MAXDIST_DURATION, value, 18);
this->query_parameters_();
}
void LD2410Component::set_gate_threshold_(uint8_t gate, uint8_t motionsens, uint8_t stillsens) {
// reference
// https://drive.google.com/drive/folders/1p4dhbEJA3YubyIjIIC7wwVsSo8x29Fq-?spm=a2g0o.detail.1000023.17.93465697yFwVxH
// Send data: configure the motion sensitivity of distance gate 3 to 40, and the static sensitivity of 40
// 00 00 (gate)
// 03 00 00 00 (gate number)
// 01 00 (motion sensitivity)
// 28 00 00 00 (value)
// 02 00 (still sensitivtiy)
// 28 00 00 00 (value)
uint8_t value[18] = {0x00, 0x00, lowbyte(gate), highbyte(gate), 0x00, 0x00,
0x01, 0x00, lowbyte(motionsens), highbyte(motionsens), 0x00, 0x00,
0x02, 0x00, lowbyte(stillsens), highbyte(stillsens), 0x00, 0x00};
this->send_command_(CMD_GATE_SENS, value, 18);
}
void LD2410Component::factoryReset()
{
this->set_config_mode_(true);
uint8_t cmd = 0x00A2;
this -> send_command_(cmd, nullptr, 0);
}
void LD2410Component::reboot()
{
ESP_LOGD(TAG, "reboot ld2410b...");
this->set_config_mode_(true);
uint8_t cmd = 0x00A3;
this -> send_command_(cmd, nullptr, 0);
// not need to exit config mode because the ld2410 will reboot automatically
}
void LD2410Component::ble_control(bool enable)
{
this->set_config_mode_(true);
uint8_t CMD_BLE_CONF = 0x00A4;
uint8_t CMD_REBOOT = 0x00A3;
uint8_t cmd_value[2] = {0x00, 0x00};
if (enable){
cmd_value[0] = 0x01;
ESP_LOGD(TAG, "Enable BLE...");
}else{
ESP_LOGD(TAG, "Disable BLE...");
}
this -> send_command_(CMD_BLE_CONF, cmd_value, 2);
//this -> send_command_(CMD_REBOOT, nullptr, 0);
this->set_config_mode_(false);
this -> reboot();
}
void LD2410Component::factory_mode(bool enable){
uint8_t CMD_FACTORY_ON = 0x0062;
uint8_t CMD_FACTORY_OFF = 0x0063;
this->set_config_mode_(true);
uint8_t cmd = enable ? CMD_FACTORY_ON: CMD_FACTORY_OFF;
this->send_command_(cmd, nullptr, 0);
this->set_config_mode_(false);
}
} // namespace ld2410
} // namespace esphome

View File

@ -1,158 +0,0 @@
#pragma once
#include "esphome/core/defines.h"
#include "esphome/core/component.h"
#ifdef USE_BINARY_SENSOR
#include "esphome/components/binary_sensor/binary_sensor.h"
#endif
#ifdef USE_SENSOR
#include "esphome/components/sensor/sensor.h"
#endif
#include "esphome/components/uart/uart.h"
#include "esphome/core/automation.h"
#include "esphome/core/helpers.h"
namespace esphome {
namespace ld2410 {
#define CHECK_BIT(var, pos) (((var) >> (pos)) & 1)
// Commands
static const uint8_t CMD_ENABLE_CONF = 0x00FF;
static const uint8_t CMD_DISABLE_CONF = 0x00FE;
static const uint8_t CMD_MAXDIST_DURATION = 0x0060;
static const uint8_t CMD_QUERY = 0x0061;
static const uint8_t CMD_GATE_SENS = 0x0064;
static const uint8_t CMD_VERSION = 0x00A0;
// Commands values
static const uint8_t CMD_MAX_MOVE_VALUE = 0x0000;
static const uint8_t CMD_MAX_STILL_VALUE = 0x0001;
static const uint8_t CMD_DURATION_VALUE = 0x0002;
// Command Header & Footer
static const uint8_t CMD_FRAME_HEADER[4] = {0xFD, 0xFC, 0xFB, 0xFA};
static const uint8_t CMD_FRAME_END[4] = {0x04, 0x03, 0x02, 0x01};
// Data Header & Footer
static const uint8_t DATA_FRAME_HEADER[4] = {0xF4, 0xF3, 0xF2, 0xF1};
static const uint8_t DATA_FRAME_END[4] = {0xF8, 0xF7, 0xF6, 0xF5};
/*
Data Type: 6th byte
Target states: 9th byte
Moving target distance: 10~11th bytes
Moving target energy: 12th byte
Still target distance: 13~14th bytes
Still target energy: 15th byte
Detect distance: 16~17th bytes
*/
enum PeriodicDataStructure : uint8_t {
DATA_TYPES = 5,
TARGET_STATES = 8,
MOVING_TARGET_LOW = 9,
MOVING_TARGET_HIGH = 10,
MOVING_ENERGY = 11,
STILL_TARGET_LOW = 12,
STILL_TARGET_HIGH = 13,
STILL_ENERGY = 14,
DETECT_DISTANCE_LOW = 15,
DETECT_DISTANCE_HIGH = 16,
};
// 上报数据的固定结构。(23年3月13日_16时54分_)
enum PeriodicDataValue : uint8_t { HEAD = 0XAA, END = 0x55, CHECK = 0x00 };
enum AckDataStructure : uint8_t { COMMAND = 6, COMMAND_STATUS = 7 };
// char cmd[2] = {enable ? 0xFF : 0xFE, 0x00};
class LD2410Component : public Component, public uart::UARTDevice {
#ifdef USE_SENSOR
SUB_SENSOR(moving_target_distance)
SUB_SENSOR(still_target_distance)
SUB_SENSOR(moving_target_energy)
SUB_SENSOR(still_target_energy)
SUB_SENSOR(detection_distance)
SUB_SENSOR(light)
#endif
public:
void setup() override;
void dump_config() override;
void loop() override;
#ifdef USE_BINARY_SENSOR
void set_target_sensor(binary_sensor::BinarySensor *sens) { this->target_binary_sensor_ = sens; };
void set_moving_target_sensor(binary_sensor::BinarySensor *sens) { this->moving_binary_sensor_ = sens; };
void set_still_target_sensor(binary_sensor::BinarySensor *sens) { this->still_binary_sensor_ = sens; };
#endif
void set_timeout(uint16_t value) { this->timeout_ = value; };
void set_max_move_distance(uint8_t value) { this->max_move_distance_ = value; };
void set_max_still_distance(uint8_t value) { this->max_still_distance_ = value; };
void set_range_config(int rg0_move, int rg0_still, int rg1_move, int rg1_still, int rg2_move, int rg2_still,
int rg3_move, int rg3_still, int rg4_move, int rg4_still, int rg5_move, int rg5_still,
int rg6_move, int rg6_still, int rg7_move, int rg7_still, int rg8_move, int rg8_still) {
this->rg0_move_threshold_ = rg0_move;
this->rg0_still_threshold_ = rg0_still;
this->rg1_move_threshold_ = rg1_move;
this->rg1_still_threshold_ = rg1_still;
this->rg2_move_threshold_ = rg2_move;
this->rg2_still_threshold_ = rg2_still;
this->rg3_move_threshold_ = rg3_move;
this->rg3_still_threshold_ = rg3_still;
this->rg4_move_threshold_ = rg4_move;
this->rg4_still_threshold_ = rg4_still;
this->rg5_move_threshold_ = rg5_move;
this->rg5_still_threshold_ = rg5_still;
this->rg6_move_threshold_ = rg6_move;
this->rg6_still_threshold_ = rg6_still;
this->rg7_move_threshold_ = rg7_move;
this->rg7_still_threshold_ = rg7_still;
this->rg8_move_threshold_ = rg8_move;
this->rg8_still_threshold_ = rg8_still;
};
int moving_sensitivities[9] = {0};
int still_sensitivities[9] = {0};
int32_t last_periodic_millis = millis();
int32_t last_change_fatory_mode_millis = 0;
void factoryReset();
void reboot();
void ble_control(bool enable);
void factory_mode(bool enable);
protected:
#ifdef USE_BINARY_SENSOR
binary_sensor::BinarySensor *target_binary_sensor_{nullptr};
binary_sensor::BinarySensor *moving_binary_sensor_{nullptr};
binary_sensor::BinarySensor *still_binary_sensor_{nullptr};
#endif
std::vector<uint8_t> rx_buffer_;
int two_byte_to_int_(char firstbyte, char secondbyte) { return (int16_t)(secondbyte << 8) + firstbyte; }
void send_command_(uint8_t command_str, uint8_t *command_value, int command_value_len);
void set_max_distances_timeout_(uint8_t max_moving_distance_range, uint8_t max_still_distance_range,
uint16_t timeout);
void set_gate_threshold_(uint8_t gate, uint8_t motionsens, uint8_t stillsens);
void set_config_mode_(bool enable);
void handle_periodic_data_(uint8_t *buffer, int len);
void handle_ack_data_(uint8_t *buffer, int len);
void readline_(int readch, uint8_t *buffer, int len);
void query_parameters_();
void get_version_();
uint16_t timeout_;
uint8_t max_move_distance_;
uint8_t max_still_distance_;
uint8_t version_[6];
uint8_t rg0_move_threshold_, rg0_still_threshold_, rg1_move_threshold_, rg1_still_threshold_, rg2_move_threshold_,
rg2_still_threshold_, rg3_move_threshold_, rg3_still_threshold_, rg4_move_threshold_, rg4_still_threshold_,
rg5_move_threshold_, rg5_still_threshold_, rg6_move_threshold_, rg6_still_threshold_, rg7_move_threshold_,
rg7_still_threshold_, rg8_move_threshold_, rg8_still_threshold_;
};
} // namespace ld2410
} // namespace esphome

View File

@ -1,70 +0,0 @@
import esphome.codegen as cg
from esphome.components import sensor
import esphome.config_validation as cv
from esphome.const import (
DEVICE_CLASS_DISTANCE,
DEVICE_CLASS_ENERGY,
UNIT_CENTIMETER,
UNIT_PERCENT,
STATE_CLASS_NONE,
ICON_BRIGHTNESS_5,
UNIT_EMPTY,
UNIT_LUX,
)
from . import CONF_LD2410_ID, LD2410Component
DEPENDENCIES = ["ld2410"]
CONF_MOVING_DISTANCE = "moving_distance"
CONF_STILL_DISTANCE = "still_distance"
CONF_MOVING_ENERGY = "moving_energy"
CONF_STILL_ENERGY = "still_energy"
CONF_DETECTION_DISTANCE = "detection_distance"
CONF_LIGHT = "light"
CONFIG_SCHEMA = {
cv.GenerateID(CONF_LD2410_ID): cv.use_id(LD2410Component),
cv.Optional(CONF_MOVING_DISTANCE): sensor.sensor_schema(
device_class=DEVICE_CLASS_DISTANCE, unit_of_measurement=UNIT_CENTIMETER
),
cv.Optional(CONF_STILL_DISTANCE): sensor.sensor_schema(
device_class=DEVICE_CLASS_DISTANCE, unit_of_measurement=UNIT_CENTIMETER
),
cv.Optional(CONF_MOVING_ENERGY): sensor.sensor_schema(
device_class=DEVICE_CLASS_ENERGY, unit_of_measurement=UNIT_PERCENT
),
cv.Optional(CONF_STILL_ENERGY): sensor.sensor_schema(
device_class=DEVICE_CLASS_ENERGY, unit_of_measurement=UNIT_PERCENT
),
cv.Optional(CONF_DETECTION_DISTANCE): sensor.sensor_schema(
device_class=DEVICE_CLASS_DISTANCE, unit_of_measurement=UNIT_CENTIMETER
),
cv.Optional(CONF_LIGHT): sensor.sensor_schema(
device_class=STATE_CLASS_NONE,
icon=ICON_BRIGHTNESS_5,
unit_of_measurement=UNIT_PERCENT
),
}
async def to_code(config):
ld2410_component = await cg.get_variable(config[CONF_LD2410_ID])
if CONF_MOVING_DISTANCE in config:
sens = await sensor.new_sensor(config[CONF_MOVING_DISTANCE])
cg.add(ld2410_component.set_moving_target_distance_sensor(sens))
if CONF_STILL_DISTANCE in config:
sens = await sensor.new_sensor(config[CONF_STILL_DISTANCE])
cg.add(ld2410_component.set_still_target_distance_sensor(sens))
if CONF_MOVING_ENERGY in config:
sens = await sensor.new_sensor(config[CONF_MOVING_ENERGY])
cg.add(ld2410_component.set_moving_target_energy_sensor(sens))
if CONF_STILL_ENERGY in config:
sens = await sensor.new_sensor(config[CONF_STILL_ENERGY])
cg.add(ld2410_component.set_still_target_energy_sensor(sens))
if CONF_DETECTION_DISTANCE in config:
sens = await sensor.new_sensor(config[CONF_DETECTION_DISTANCE])
cg.add(ld2410_component.set_detection_distance_sensor(sens))
if CONF_LIGHT in config:
sens = await sensor.new_sensor(config[CONF_LIGHT])
cg.add(ld2410_component.set_light_sensor(sens))

View File

@ -0,0 +1,3 @@
Experimental YAML Configurations
The YAML configuration files in this directory are experimental and are intended for testing and exploratory development purposes. They have not undergone comprehensive testing or validation and may contain unresolved bugs and issues. Please use these configurations with caution, keeping in mind that they are meant solely for experimentation and learning, and their functionality and stability cannot be guaranteed.

View File

@ -0,0 +1,156 @@
esphome:
name: screek-humen-sensor-1wx
comment: Screek Human Sensor 1WX
friendly_name: Human Sensor 1WX
name_add_mac_suffix: True
platformio_options:
board_build.flash_mode: dio
project:
name: Screek.Human_Sensor
version: 1W
external_components:
- source:
type: git
url: https://github.com/screekworkshop/custom_components_support_for_screek_1w
ref: main
components: [esp32, uart]
esp32:
board: esp32-c3-devkitm-1
logger:
api:
ota:
- platform: esphome
password: "YOUR_OTA_PASSWORD"
wifi:
# ssid: !secret wifi_ssid
# password: !secret wifi_password
# fast_connect: True
power_save_mode: NONE
# output_power: 20dB
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "HUMAN-SENSOR 1WX"
captive_portal:
web_server:
port: 80
binary_sensor:
- platform: status
name: Online
id: ink_ha_connected
- platform: ld2410
has_target:
name: Presence
has_moving_target:
name: Moving Target
has_still_target:
name: Still Target
sensor:
- platform: template
id: sys_esp_temperature
name: ESP Temperature
lambda: return temperatureRead();
unit_of_measurement: °C
device_class: TEMPERATURE
update_interval: 30s
entity_category: "diagnostic"
- platform: uptime
name: Uptime
id: sys_uptime
update_interval: 10s
- platform: wifi_signal
name: RSSI
id: wifi_signal_db
update_interval: 1s
entity_category: "diagnostic"
- platform: template
id: esp_memory
icon: mdi:memory
name: ESP Free Memory
lambda: return heap_caps_get_free_size(MALLOC_CAP_INTERNAL) / 1024;
unit_of_measurement: 'kB'
state_class: measurement
entity_category: "diagnostic"
- platform: ld2410
moving_distance:
name : Moving Distance
id: moving_distance
still_distance:
name: Still Distance
id: still_distance
moving_energy:
name: Move Energy
still_energy:
name: Still Energy
detection_distance:
name: Detection Distance
light:
name: Sun Light
time:
- platform: sntp
id: time_now
servers:
- ntp.aliyun.com
uart:
id: uart_ld2410
tx_pin: GPIO7
rx_pin: GPIO6
baud_rate: 256000
parity: NONE
stop_bits: 1
switch:
- platform: ld2410
engineering_mode:
name: "engineering mode"
bluetooth:
name: "control bluetooth"
ld2410:
id: ld2410_radar
text_sensor:
- platform: ld2410
version:
name: "firmware version"
mac_address:
name: "mac address"
button:
- platform: ld2410
factory_reset:
name: "ld2410 factory reset"
restart:
name: "LD2410 Reboot"
icon: mdi:radar
entity_category: "config"
- platform: restart
icon: mdi:power-cycle
name: "ESP Reboot"
- platform: factory_reset
disabled_by_default: True
name: Factory Reset
id: factory_reset_all
number:
- platform: ld2410
timeout:
name: timeout
light_threshold:
name: light threshold
max_move_distance_gate:
name: max move distance gate
max_still_distance_gate:
name: max still distance gate

View File

@ -0,0 +1,168 @@
esphome:
name: screek-humen-sensor-1wx
comment: Screek Human Sensor 1WX
friendly_name: Human Sensor 1WX
name_add_mac_suffix: True
platformio_options:
board_build.flash_mode: dio
project:
name: Screek.Human_Sensor
version: 1W
external_components:
- source:
type: git
url: https://github.com/screekworkshop/custom_components_support_for_screek_1w
ref: main
components: [uart, ld2410]
esp32:
board: esp32-c3-devkitm-1
logger:
api:
ota:
- platform: esphome
password: "YOUR_OTA_PASSWORD"
wifi:
# ssid: !secret wifi_ssid
# password: !secret wifi_password
# fast_connect: True
power_save_mode: NONE
# output_power: 20dB
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "SCREEK HUMAN-SENSOR"
captive_portal:
web_server:
port: 80
binary_sensor:
- platform: status
name: Online
id: ink_ha_connected
- platform: ld2410
has_target:
name: Presence
has_moving_target:
name: Moving Target
has_still_target:
name: Still Target
sensor:
- platform: template
id: sys_esp_temperature
name: ESP Temperature
lambda: return temperatureRead();
unit_of_measurement: °C
device_class: TEMPERATURE
update_interval: 30s
entity_category: "diagnostic"
- platform: uptime
name: Uptime
id: sys_uptime
update_interval: 10s
- platform: wifi_signal
name: RSSI
id: wifi_signal_db
update_interval: 1s
entity_category: "diagnostic"
- platform: template
id: esp_memory
icon: mdi:memory
name: ESP Free Memory
lambda: return heap_caps_get_free_size(MALLOC_CAP_INTERNAL) / 1024;
unit_of_measurement: 'kB'
state_class: measurement
entity_category: "diagnostic"
- platform: ld2410
moving_distance:
name : Moving Distance
id: moving_distance
still_distance:
name: Still Distance
id: still_distance
moving_energy:
name: Move Energy
still_energy:
name: Still Energy
detection_distance:
name: Detection Distance
light:
name: Sun Light
time:
- platform: sntp
id: time_now
servers:
- ntp.aliyun.com
uart:
id: uart_ld2410
tx_pin: GPIO7
rx_pin: GPIO6
baud_rate: 256000
parity: NONE
stop_bits: 1
ld2410:
timeout: 150s
id: ld2410_radar
# max_move_distance : 6m
# max_still_distance: 0.75m
# g0_move_threshold: 10
# g0_still_threshold: 20
# g1_move_threshold: 10
# g1_still_threshold: 20
# g2_move_threshold: 20
# g2_still_threshold: 21
# g3_move_threshold: 30
# g3_still_threshold: 31
# g4_move_threshold: 40
# g4_still_threshold: 41
# g5_move_threshold: 50
# g5_still_threshold: 51
# g6_move_threshold: 60
# g6_still_threshold: 61
# g7_move_threshold: 70
# g7_still_threshold: 71
# g8_move_threshold: 80
# g8_still_threshold: 81
button:
- platform: template
name: "Enable LD2410 BLE"
entity_category: "config"
icon: mdi:bluetooth
on_press:
lambda: |-
id(ld2410_radar) -> ble_control(true);
- platform: template
name: "Disable LD2410 BLE"
entity_category: "config"
icon: mdi:bluetooth-off
on_press:
lambda: |-
id(ld2410_radar) -> ble_control(false);
- platform: template
name: "LD2410 Reboot"
icon: mdi:radar
entity_category: "config"
on_press:
lambda: |-
// auto* radar = LD2410Component::get(ld2410);
// radar -> roboot();
id(ld2410_radar) -> reboot();
- platform: restart
icon: mdi:power-cycle
name: "ESP Reboot"
- platform: factory_reset
disabled_by_default: True
name: Factory Reset
id: factory_reset_all

File diff suppressed because it is too large Load Diff

37
README.md Normal file
View File

@ -0,0 +1,37 @@
# SCREEK Human Sensor DIY Firmware Support
## About
This is the source code for the DIY sensors we make, you are free to modify them and use them, and feel free to provide suggestions to us.
Consider the current privacy so extravagant, and the severe dependence on cloud services. Open source can bring better privacy, and more personalized customization.
If you would like to purchase one of our DIY products, or take a look at our documentation, feel free to visit
https://www.screek.io/
Our Store:
https://shop.screek.io
Our eBay Store:
https://www.ebay.com/str/screekworkshop
And Here is A FB Group:
https://www.facebook.com/groups/screekworkshop
And Reddit:
https://www.reddit.com/r/screekworkshop/
Happy DIYing!
## 🙏
The sensor builds and code have gotten a lot of concerted effort, and ingenuity, from many, many people.
## Something else to say
We insist on keeping our principles of code openness on Home Assistant sensors because we strongly believe in it:
- Code that is fully localized to run without malicious behavior and is readily available for everyone to review is more reassuring.
- It's great to have the wisdom of everyone working together to improve the source code.
But at the same time we must apologize that we don't have enough energy to run an open source community at the moment, so our open source code may not be up to date or well commented.
We hope you'll forgive us for having to spend most of our spare time limited to building and testing hardware, as well as exploring some new areas, and hopefully often getting a chance to take a walk with our families.

5
f2/yaml/README.md Normal file
View File

@ -0,0 +1,5 @@
sensor main page: https://docs.screek.io/f2
The main LD1125F part of the code comes from the LD1125H code driver from [Link_mmWave_Radar_ESPHome](https://github.com/patrick3399/Hi-Link_mmWave_Radar_ESPHome).
Acknowledgements patrick3399, ssieb.

View File

@ -0,0 +1,516 @@
# screek f2 yaml code
# main ld1125h code from: https://github.com/patrick3399/Hi-Link_mmWave_Radar_ESPHome
#
substitutions:
devicename: ""
upper_devicename: ""
esphome:
name: screek-human-sensor-f2
comment: Screek Human Sensor F2
friendly_name: Human Sensor F2
name_add_mac_suffix: True
platformio_options:
board_build.flash_mode: dio
# board_build.f_cpu: 80000000L
project:
name: Screek.Human_Presence_Sensor
version: F2
on_boot:
- priority: 100
then:
lambda: |-
id(cpu_speed) = ESP.getCpuFreqMHz();
- priority: 300
then:
lambda: |-
id(screek_version).publish_state("Beta_V240708_1");
- priority: -200
then:
- uart.write:
id: LD1125F_UART_BUS
data: !lambda |-
std::string th1st = "mth1=" + str_sprintf("%.0f",id(LD1125F_mth1).state) +"\r\n";
return std::vector<uint8_t>(th1st.begin(), th1st.end());
- delay: 100ms
- uart.write:
id: LD1125F_UART_BUS
data: !lambda |-
std::string th2st = "mth2=" + str_sprintf("%.0f",id(LD1125F_mth2).state) +"\r\n";
return std::vector<uint8_t>(th2st.begin(), th2st.end());
- delay: 100ms
- uart.write:
id: LD1125F_UART_BUS
data: !lambda |-
std::string th3st = "mth3=" + str_sprintf("%.0f",id(LD1125F_mth3).state) +"\r\n";
return std::vector<uint8_t>(th3st.begin(), th3st.end());
- delay: 100ms
- uart.write:
id: LD1125F_UART_BUS
data: !lambda |-
std::string rmaxst = "rmax=" + str_sprintf("%.1f",id(LD1125F_rmax).state) +"\r\n";
return std::vector<uint8_t>(rmaxst.begin(), rmaxst.end());
- delay: 100ms
- uart.write:
id: LD1125F_UART_BUS
data: !lambda |-
std::string utonsst = "utons=" + str_sprintf("%.1f",id(LD1125F_utons).state) +"\r\n";
return std::vector<uint8_t>(utonsst.begin(), utonsst.end());
safe_mode:
disabled: true
preferences:
flash_write_interval: 5s
external_components:
- source:
type: git
url: https://github.com/screekworkshop/custom_components_support_for_screek_2a
ref: main
components: [uart]
- source:
type: git
url: https://github.com/ssieb/custom_components #Thanks for @ssieb components.
components: [ serial ]
esp32:
board: lolin_c3_mini
framework:
type: arduino
version: 2.0.9
platform_version: 6.3.0
globals:
- id: cpu_speed
type: int
restore_value: no
initial_value: '0'
- id: last_update_ld2450
type: unsigned long
restore_value: no
initial_value: '0'
- id: init_zone_publish
type: bool
restore_value: no
initial_value: "false"
- id: last_illuminance
type: float
restore_value: no
initial_value: "-1"
- id: LD1125F_Last_Time
type: time_t
restore_value: no
initial_value: time(NULL)
- id: LD1125F_Last_Mov_Time
type: time_t
restore_value: no
initial_value: time(NULL)
- id: LD1125F_Clearence_Status
type: bool
restore_value: no
initial_value: "false"
improv_serial:
logger:
logs:
bh1750.sensor: INFO
debug:
update_interval: 30s
# Enable Home Assistant API
api:
# encryption:
# key: "your-api-key"
ota:
- platform: esphome
password: "your-ota-password"
wifi:
# output_power: 15dB
power_save_mode: LIGHT
# power_save_mode: NONE
reboot_timeout: 10min
ap:
ssid: "HUMAN-SENSOR F2"
captive_portal:
web_server:
port: 80
text_sensor:
- platform: template
name: "SCREEK Version"
id: screek_version
icon: mdi:information-outline
entity_category: "diagnostic"
update_interval: never
- platform: debug
reset_reason:
name: "ESP Reset Reason"
icon: mdi:anchor
disabled_by_default: True
- platform: wifi_info
ip_address:
name: ESP IP Address
entity_category: "diagnostic"
disabled_by_default: True
icon: mdi:ip-network
mac_address:
name: ESP MAC
entity_category: "diagnostic"
icon: mdi:ip-network
disabled_by_default: True
- platform: serial
uart_id: LD1125F_UART_BUS
name: ${upper_devicename} UART Text
id: LD1125F_UART_Text
icon: "mdi:format-text"
entity_category: "diagnostic"
internal: False #If Don't Want to See UART Receive Data, Set To True
filters:
- lambda: |-
static std::string last;
if (x == last)
return {};
last = x;
return x;
on_value:
lambda: |-
std::string uart_text = id(LD1125F_UART_Text).state;
if (uart_text == "null"){
return;
}
float distance = -1;
std::string uart_state = "";
if (uart_text.length() > 3) {
uart_state = id(LD1125F_UART_Text).state.substr(0,3);
if (uart_text.length() >= 9) {
if (uart_state == "occ" || uart_state == "mov") {
distance = std::stof(uart_text.substr(9));
}
}
}
if (uart_state == "occ" && distance > 0) {
id(LD1125F_Distance).publish_state(distance);
if ((time(NULL)-id(LD1125F_Last_Mov_Time)) >= id(LD1125F_Mov_Time).state) {
id(LD1125F_Occupancy).publish_state("Occupancy");
if (id(LD1125F_MovOcc_Binary).state == false) {
id(LD1125F_MovOcc_Binary).publish_state(true);
}
if (id(LD1125F_Mov_Binary).state == true) {
id(LD1125F_Mov_Binary).publish_state(false);
}
}
if (id(LD1125F_MovOcc_Binary).state == false) {
id(LD1125F_MovOcc_Binary).publish_state(true);
}
id(LD1125F_Last_Time) = time(NULL);
if (id(LD1125F_Clearence_Status) == true) {
id(LD1125F_Clearence_Status) = false;
}
}
else if (uart_state == "mov" && distance > 0) {
id(LD1125F_Distance).publish_state(distance);
id(LD1125F_Occupancy).publish_state("Movement");
if (id(LD1125F_MovOcc_Binary).state == false) {
id(LD1125F_MovOcc_Binary).publish_state(true);
}
if (id(LD1125F_Mov_Binary).state == false) {
id(LD1125F_Mov_Binary).publish_state(true);
}
id(LD1125F_Last_Mov_Time) = time(NULL);
id(LD1125F_Last_Time) = time(NULL);
if (id(LD1125F_Clearence_Status) == true) {
id(LD1125F_Clearence_Status) = false;
}
}
- platform: template
name: ${upper_devicename} Occupancy Status
id: LD1125F_Occupancy
icon: "mdi:motion-sensor"
binary_sensor:
- platform: status
name: Online
id: ink_ha_connected
- platform: template
name: ${upper_devicename} Occupancy or Movement
id: LD1125F_MovOcc_Binary
device_class: occupancy
publish_initial_state: True
- platform: template
name: ${upper_devicename} Movement
id: LD1125F_Mov_Binary
device_class: motion
publish_initial_state: True
sensor:
- platform: template
name: "ESP CPU Speed"
accuracy_decimals: 0
icon: mdi:cpu-32-bit
unit_of_measurement: Mhz
disabled_by_default: True
lambda: |-
return (id(cpu_speed));
entity_category: "diagnostic"
update_interval: 600s
- platform: template
id: sys_esp_temperature
name: ESP Temperature
lambda: return temperatureRead();
unit_of_measurement: "°C"
device_class: TEMPERATURE
update_interval: 45s
entity_category: "diagnostic"
- platform: uptime
name: ESP Uptime
id: sys_uptime
update_interval: 60s
- platform: wifi_signal
name: RSSI
id: wifi_signal_db
update_interval: 60s
entity_category: "diagnostic"
- platform: template
id: esp_memory
icon: mdi:memory
name: ESP Free Memory
lambda: return heap_caps_get_free_size(MALLOC_CAP_INTERNAL) / 1024;
unit_of_measurement: 'kB'
state_class: measurement
entity_category: "diagnostic"
update_interval: 60s
- platform: template
name: ${upper_devicename} Distance
id: LD1125F_Distance
icon: "mdi:signal-distance-variant"
unit_of_measurement: "m"
accuracy_decimals: 2
# filters: # Use Fliter To Debounce
# - sliding_window_moving_average:
# window_size: 8
# send_every: 2
# - heartbeat: 0.2s
- platform: bh1750
name: "Illuminance"
accuracy_decimals: 1
id: bh1750_light
update_interval: 1s
filters:
- delta: 0.1
light:
- platform: status_led
name: sys_status
pin:
number: GPIO13
ignore_pin_validation_error: true
internal: True
restore_mode: ALWAYS_OFF
- platform: binary
name: "Red Info Light"
output: board_info_ed
entity_category: "config"
restore_mode: ALWAYS_OFF
i2c:
sda: GPIO7
scl: GPIO11
scan: true
id: bus_a
output:
- platform: gpio
id: board_info_ed
pin:
number: GPIO12
ignore_pin_validation_error: true
switch:
- platform: factory_reset
name: Factory Reset
disabled_by_default: True
icon: mdi:heart-broken
button:
- platform: restart
icon: mdi:power-cycle
name: "ESP Reboot"
entity_category: diagnostic
uart:
id: LD1125F_UART_BUS
rx_pin: GPIO5
tx_pin: GPIO4
baud_rate: 115200
data_bits: 8
stop_bits: 1
parity: NONE
interval:
- interval: 1s #Clearance Scan Time
setup_priority: -200
then:
lambda: |-
if ((time(NULL)-id(LD1125F_Last_Time))>id(LD1125F_Clear_Time).state) {
if (id(LD1125F_Distance).state != 0){
id(LD1125F_Distance).publish_state(0);
}
if ((id(LD1125F_Clearence_Status) == false) || (id(LD1125F_Occupancy).state != "Clearance")) {
id(LD1125F_Occupancy).publish_state("Clearance");
id(LD1125F_Clearence_Status) = true;
}
if (id(LD1125F_MovOcc_Binary).state == true) {
id(LD1125F_MovOcc_Binary).publish_state(false);
}
if (id(LD1125F_Mov_Binary).state == true) {
id(LD1125F_Mov_Binary).publish_state(false);
}
}
number:
- platform: template
name: ${upper_devicename} mth1 #mth1 is 0~2.8m Sensitivity.
id: LD1125F_mth1
icon: "mdi:cogs"
optimistic: true
entity_category: config
restore_value: true #If you don't want to store the setting at ESP, set it to false.
initial_value: "60.0" #Default mth1 Setting
min_value: 10.0
max_value: 600.0
step: 5.0
set_action:
then:
- uart.write:
id: LD1125F_UART_BUS
data: !lambda |-
std::string th1st = "mth1=" + str_sprintf("%.0f",x) +"\r\n";
return std::vector<uint8_t>(th1st.begin(), th1st.end());
- delay: 100ms
- uart.write: # save
id: LD1125F_UART_BUS
data: "save\r\n"
- platform: template
name: ${upper_devicename} mth2 #mth2 is 2.8~8m Sensitivity.
id: LD1125F_mth2
icon: "mdi:cogs"
optimistic: true
entity_category: config
restore_value: true #If you don't want to store the setting at ESP, set it to false.
initial_value: "30" #Default mth2 Setting
min_value: 5
max_value: 300
step: 5
set_action:
then:
- uart.write:
id: LD1125F_UART_BUS
data: !lambda |-
std::string th2st = "mth2=" + str_sprintf("%.0f",x) +"\r\n";
return std::vector<uint8_t>(th2st.begin(), th2st.end());
- delay: 100ms
- uart.write: # save
id: LD1125F_UART_BUS
data: "save\r\n"
- platform: template
name: ${upper_devicename} mth3 #mth3 is above 8m Sensitivity.
id: LD1125F_mth3
icon: "mdi:cogs"
entity_category: config
optimistic: true
restore_value: true #If you don't want to store the setting at ESP, set it to false.
initial_value: "20" #Default mth3 Setting
min_value: 5
max_value: 200
step: 5
set_action:
then:
- uart.write:
id: LD1125F_UART_BUS
data: !lambda |-
std::string th3st = "mth3=" + str_sprintf("%.0f",x) +"\r\n";
return std::vector<uint8_t>(th3st.begin(), th3st.end());
- delay: 100ms
- uart.write: # save
id: LD1125F_UART_BUS
data: "save\r\n"
- platform: template
name: ${upper_devicename} Max Distance #rmax is max detection distance.
id: LD1125F_rmax
icon: "mdi:cogs"
entity_category: config
optimistic: true
unit_of_measurement: m
restore_value: true #If you don't want to store the setting at ESP, set it to false.
initial_value: "8" #Default rmax Setting
min_value: 0.4
max_value: 12
step: 0.2
set_action:
then:
- uart.write:
id: LD1125F_UART_BUS
data: !lambda |-
std::string rmaxst = "rmax=" + str_sprintf("%.1f",x) +"\r\n";
return std::vector<uint8_t>(rmaxst.begin(), rmaxst.end());
- delay: 100ms
- uart.write: # save
id: LD1125F_UART_BUS
data: "save\r\n"
- platform: template
name: ${upper_devicename} LD1125F Refresh Rate
id: LD1125F_utons
icon: "mdi:refresh"
entity_category: config
optimistic: true
unit_of_measurement: ms
restore_value: true
initial_value: "100"
min_value: 100
max_value: 5000
step: 50
set_action:
then:
- uart.write:
id: LD1125F_UART_BUS
data: !lambda |-
std::string utonsst = "utons=" + std::to_string(x) + "\r\n";
return std::vector<uint8_t>(utonsst.begin(), utonsst.end());
- delay: 100ms
- uart.write: # save
id: LD1125F_UART_BUS
data: "save\r\n"
- platform: template
name: ${upper_devicename} Clearence Time
id: LD1125F_Clear_Time
icon: "mdi:cogs"
optimistic: true
entity_category: config
restore_value: true #If you don't want to store the setting at ESP, set it to false.
initial_value: "5" #LD1125F Mov/Occ > Clearence Time Here
min_value: 0.5
max_value: 20
step: 0.5
- platform: template
name: ${upper_devicename} Movement Time
id: LD1125F_Mov_Time
icon: "mdi:cogs"
optimistic: true
entity_category: config
restore_value: true #If you don't want to store the setting at ESP, set it to false.
initial_value: "1" #LD1125F Mov > Occ Time Here
min_value: 0.5
max_value: 10
step: 0.5

View File

@ -0,0 +1,482 @@
# screek f2 yaml code
# main ld1125h code from: https://github.com/patrick3399/Hi-Link_mmWave_Radar_ESPHome
#
substitutions:
devicename: ""
upper_devicename: ""
esphome:
name: screek-human-sensor-f2
comment: Screek Human Sensor F2
friendly_name: Human Sensor F2
name_add_mac_suffix: True
platformio_options:
board_build.flash_mode: dio
# board_build.f_cpu: 80000000L
project:
name: Screek.Human_Presence_Sensor
version: F2
on_boot:
- priority: 300
then:
lambda: |-
id(screek_version).publish_state("V251104_1");
- priority: -200
then:
- uart.write:
id: LD1125F_UART_BUS
data: !lambda |-
std::string th1st = "mth1=" + str_sprintf("%.0f",id(LD1125F_mth1).state) +"\r\n";
return std::vector<uint8_t>(th1st.begin(), th1st.end());
- delay: 100ms
- uart.write:
id: LD1125F_UART_BUS
data: !lambda |-
std::string th2st = "mth2=" + str_sprintf("%.0f",id(LD1125F_mth2).state) +"\r\n";
return std::vector<uint8_t>(th2st.begin(), th2st.end());
- delay: 100ms
- uart.write:
id: LD1125F_UART_BUS
data: !lambda |-
std::string th3st = "mth3=" + str_sprintf("%.0f",id(LD1125F_mth3).state) +"\r\n";
return std::vector<uint8_t>(th3st.begin(), th3st.end());
- delay: 100ms
- uart.write:
id: LD1125F_UART_BUS
data: !lambda |-
std::string rmaxst = "rmax=" + str_sprintf("%.1f",id(LD1125F_rmax).state) +"\r\n";
return std::vector<uint8_t>(rmaxst.begin(), rmaxst.end());
- delay: 100ms
- uart.write:
id: LD1125F_UART_BUS
data: !lambda |-
std::string utonsst = "utons=" + str_sprintf("%.1f",id(LD1125F_utons).state) +"\r\n";
return std::vector<uint8_t>(utonsst.begin(), utonsst.end());
safe_mode:
disabled: true
preferences:
flash_write_interval: 5s
external_components:
- source:
type: git
url: https://github.com/ssieb/custom_components #Thanks for @ssieb components.
components: [ serial ]
esp32:
board: lolin_c3_mini
framework:
type: esp-idf
# version: 2.0.9
# platform_version: 6.3.0
globals:
- id: last_update_ld2450
type: unsigned long
restore_value: no
initial_value: '0'
- id: init_zone_publish
type: bool
restore_value: no
initial_value: "false"
- id: last_illuminance
type: float
restore_value: no
initial_value: "-1"
- id: LD1125F_Last_Time
type: time_t
restore_value: no
initial_value: time(NULL)
- id: LD1125F_Last_Mov_Time
type: time_t
restore_value: no
initial_value: time(NULL)
- id: LD1125F_Clearence_Status
type: bool
restore_value: no
initial_value: "false"
improv_serial:
logger:
debug:
update_interval: 30s
# Enable Home Assistant API
api:
# encryption:
# key: "your-api-key"
ota:
- platform: esphome
password: "your-ota-password"
wifi:
# output_power: 15dB
power_save_mode: LIGHT
# power_save_mode: NONE
reboot_timeout: 10min
ap:
ssid: "HUMAN-SENSOR F2"
captive_portal:
web_server:
port: 80
text_sensor:
- platform: template
name: "SCREEK Version"
id: screek_version
icon: mdi:information-outline
entity_category: "diagnostic"
update_interval: never
- platform: debug
reset_reason:
name: "ESP Reset Reason"
icon: mdi:anchor
disabled_by_default: True
- platform: wifi_info
ip_address:
name: ESP IP Address
entity_category: "diagnostic"
disabled_by_default: True
icon: mdi:ip-network
mac_address:
name: ESP MAC
entity_category: "diagnostic"
icon: mdi:ip-network
disabled_by_default: True
- platform: serial
uart_id: LD1125F_UART_BUS
name: ${upper_devicename} UART Text
id: LD1125F_UART_Text
icon: "mdi:format-text"
entity_category: "diagnostic"
internal: False #If Don't Want to See UART Receive Data, Set To True
on_value:
lambda: |-
std::string uart_text = id(LD1125F_UART_Text).state;
if (uart_text == "null"){
return;
}
float distance = -1;
std::string uart_state = "";
if (uart_text.length() > 3){
uart_state = id(LD1125F_UART_Text).state.substr(0,3);
if (uart_text.length() >= 9) {
if (uart_state == "occ" || uart_state =="mov") {
distance = std::stof(uart_text.substr(9));
}
}
}
if (uart_state == "occ" && distance > 0) {
id(LD1125F_Distance).publish_state(distance);
if ((time(NULL)-id(LD1125F_Last_Mov_Time))>id(LD1125F_Mov_Time).state) {
id(LD1125F_Occupancy).publish_state("Occupancy");
if (id(LD1125F_MovOcc_Binary).state == false) {
id(LD1125F_MovOcc_Binary).publish_state(true);
}
if (id(LD1125F_Mov_Binary).state == true) {
id(LD1125F_Mov_Binary).publish_state(false);
}
}
if (id(LD1125F_MovOcc_Binary).state == false) {
id(LD1125F_MovOcc_Binary).publish_state(true);
}
id(LD1125F_Last_Time) = time(NULL);
if (id(LD1125F_Clearence_Status) == true) {
id(LD1125F_Clearence_Status) = false;
}
}
else if (uart_state == "mov" && distance > 0) {
id(LD1125F_Distance).publish_state(distance);
id(LD1125F_Occupancy).publish_state("Movement");
if (id(LD1125F_MovOcc_Binary).state == false) {
id(LD1125F_MovOcc_Binary).publish_state(true);
}
if (id(LD1125F_Mov_Binary).state == false) {
id(LD1125F_Mov_Binary).publish_state(true);
}
id(LD1125F_Last_Mov_Time) = time(NULL);
id(LD1125F_Last_Time) = time(NULL);
if (id(LD1125F_Clearence_Status) == true) {
id(LD1125F_Clearence_Status) = false;
}
}
- platform: template
name: ${upper_devicename} Occupancy Status
id: LD1125F_Occupancy
icon: "mdi:motion-sensor"
binary_sensor:
- platform: status
name: Online
id: ink_ha_connected
- platform: template
name: ${upper_devicename} Occupancy or Movement
id: LD1125F_MovOcc_Binary
device_class: occupancy
- platform: template
name: ${upper_devicename} Movement
id: LD1125F_Mov_Binary
device_class: motion
sensor:
- platform: internal_temperature
id: sys_esp_temperature
name: ESP Temperature
unit_of_measurement: °C
device_class: TEMPERATURE
update_interval: 45s
entity_category: "diagnostic"
- platform: uptime
name: ESP Uptime
id: sys_uptime
update_interval: 60s
- platform: wifi_signal
name: RSSI
id: wifi_signal_db
update_interval: 60s
entity_category: "diagnostic"
- platform: template
id: esp_memory
icon: mdi:memory
name: ESP Free Memory
lambda: return heap_caps_get_free_size(MALLOC_CAP_INTERNAL) / 1024;
unit_of_measurement: 'kB'
state_class: measurement
entity_category: "diagnostic"
update_interval: 60s
- platform: template
name: ${upper_devicename} Distance
id: LD1125F_Distance
icon: "mdi:signal-distance-variant"
unit_of_measurement: "m"
accuracy_decimals: 2
# filters: # Use Fliter To Debounce
# - sliding_window_moving_average:
# window_size: 8
# send_every: 2
# - heartbeat: 0.2s
- platform: bh1750
name: "Illuminance"
accuracy_decimals: 1
id: bh1750_light
update_interval: 1s
filters:
- delta: 0.1
light:
- platform: status_led
name: sys_status
pin:
number: GPIO13
ignore_pin_validation_error: true
internal: True
restore_mode: ALWAYS_OFF
- platform: binary
name: "Red Info Light"
output: board_info_ed
entity_category: "config"
restore_mode: ALWAYS_OFF
i2c:
sda: GPIO7
scl: GPIO11
scan: true
id: bus_a
output:
- platform: gpio
id: board_info_ed
pin:
number: GPIO12
ignore_pin_validation_error: true
switch:
- platform: factory_reset
name: Factory Reset
disabled_by_default: True
icon: mdi:heart-broken
button:
- platform: restart
icon: mdi:power-cycle
name: "ESP Reboot"
entity_category: diagnostic
uart:
id: LD1125F_UART_BUS
rx_pin: GPIO5
tx_pin: GPIO4
baud_rate: 115200
data_bits: 8
stop_bits: 1
parity: NONE
interval:
- interval: 1s #Clearance Scan Time
setup_priority: -200
then:
lambda: |-
if ((time(NULL)-id(LD1125F_Last_Time))>id(LD1125F_Clear_Time).state) {
if (id(LD1125F_Distance).state != 0){
id(LD1125F_Distance).publish_state(0);
}
if ((id(LD1125F_Clearence_Status) == false) || (id(LD1125F_Occupancy).state != "Clearance")) {
id(LD1125F_Occupancy).publish_state("Clearance");
id(LD1125F_Clearence_Status) = true;
}
if (id(LD1125F_MovOcc_Binary).state == true) {
id(LD1125F_MovOcc_Binary).publish_state(false);
}
if (id(LD1125F_Mov_Binary).state == true) {
id(LD1125F_Mov_Binary).publish_state(false);
}
}
number:
- platform: template
name: ${upper_devicename} mth1 #mth1 is 0~2.8m Sensitivity.
id: LD1125F_mth1
icon: "mdi:cogs"
optimistic: true
entity_category: config
restore_value: true #If you don't want to store the setting at ESP, set it to false.
initial_value: "60.0" #Default mth1 Setting
min_value: 10.0
max_value: 600.0
step: 5.0
set_action:
then:
- uart.write:
id: LD1125F_UART_BUS
data: !lambda |-
std::string th1st = "mth1=" + str_sprintf("%.0f",x) +"\r\n";
return std::vector<uint8_t>(th1st.begin(), th1st.end());
- delay: 100ms
- uart.write: # save
id: LD1125F_UART_BUS
data: "save\r\n"
- platform: template
name: ${upper_devicename} mth2 #mth2 is 2.8~8m Sensitivity.
id: LD1125F_mth2
icon: "mdi:cogs"
optimistic: true
entity_category: config
restore_value: true #If you don't want to store the setting at ESP, set it to false.
initial_value: "30" #Default mth2 Setting
min_value: 5
max_value: 300
step: 5
set_action:
then:
- uart.write:
id: LD1125F_UART_BUS
data: !lambda |-
std::string th2st = "mth2=" + str_sprintf("%.0f",x) +"\r\n";
return std::vector<uint8_t>(th2st.begin(), th2st.end());
- delay: 100ms
- uart.write: # save
id: LD1125F_UART_BUS
data: "save\r\n"
- platform: template
name: ${upper_devicename} mth3 #mth3 is above 8m Sensitivity.
id: LD1125F_mth3
icon: "mdi:cogs"
entity_category: config
optimistic: true
restore_value: true #If you don't want to store the setting at ESP, set it to false.
initial_value: "20" #Default mth3 Setting
min_value: 5
max_value: 200
step: 5
set_action:
then:
- uart.write:
id: LD1125F_UART_BUS
data: !lambda |-
std::string th3st = "mth3=" + str_sprintf("%.0f",x) +"\r\n";
return std::vector<uint8_t>(th3st.begin(), th3st.end());
- delay: 100ms
- uart.write: # save
id: LD1125F_UART_BUS
data: "save\r\n"
- platform: template
name: ${upper_devicename} Max Distance #rmax is max detection distance.
id: LD1125F_rmax
icon: "mdi:cogs"
entity_category: config
optimistic: true
unit_of_measurement: m
restore_value: true #If you don't want to store the setting at ESP, set it to false.
initial_value: "8" #Default rmax Setting
min_value: 0.4
max_value: 12
step: 0.2
set_action:
then:
- uart.write:
id: LD1125F_UART_BUS
data: !lambda |-
std::string rmaxst = "rmax=" + str_sprintf("%.1f",x) +"\r\n";
return std::vector<uint8_t>(rmaxst.begin(), rmaxst.end());
- delay: 100ms
- uart.write: # save
id: LD1125F_UART_BUS
data: "save\r\n"
- platform: template
name: ${upper_devicename} LD1125F Refresh Rate
id: LD1125F_utons
icon: "mdi:refresh"
entity_category: config
optimistic: true
unit_of_measurement: ms
restore_value: true
initial_value: "100"
min_value: 100
max_value: 5000
step: 50
set_action:
then:
- uart.write:
id: LD1125F_UART_BUS
data: !lambda |-
std::string utonsst = "utons=" + std::to_string(x) + "\r\n";
return std::vector<uint8_t>(utonsst.begin(), utonsst.end());
- delay: 100ms
- uart.write: # save
id: LD1125F_UART_BUS
data: "save\r\n"
- platform: template
name: ${upper_devicename} Clearence Time
id: LD1125F_Clear_Time
icon: "mdi:cogs"
optimistic: true
entity_category: config
restore_value: true #If you don't want to store the setting at ESP, set it to false.
initial_value: "5" #LD1125F Mov/Occ > Clearence Time Here
min_value: 0.5
max_value: 20
step: 0.5
- platform: template
name: ${upper_devicename} Movement Time
id: LD1125F_Mov_Time
icon: "mdi:cogs"
optimistic: true
entity_category: config
restore_value: true #If you don't want to store the setting at ESP, set it to false.
initial_value: "1" #LD1125F Mov > Occ Time Here
min_value: 0.5
max_value: 10
step: 0.5

6
l12/yaml/README.md Normal file
View File

@ -0,0 +1,6 @@
sensor main page: https://docs.screek.io/l12
The ld2412 library is heavily based on @sebcaps ld2410 library. Many thanks to him for his outstanding work.
We would also like to express our gratitude to all the users who participated in the early testing of the L12 sensor.
We are excited to have developed a new DIY sensor together.

View File

@ -0,0 +1,236 @@
esphome:
name: screek-human-sensor-l12
comment: Screek Human Sensor L12
friendly_name: Human Sensor L12
name_add_mac_suffix: True
platformio_options:
board_build.flash_mode: dio
project:
name: SCREEK.Human Sensor L12
version: 25.12.21-B
logger:
# level: VERY_VERBOSE
# level: DEBUG
preferences:
flash_write_interval: 5s
external_components:
- source:
type: git
url: https://github.com/screekworkshop/custom_components_support_for_screek_l12
ref: main
components: [ld2412]
esp32:
board: lolin_c3_mini
framework:
type: esp-idf
globals:
- id: last_illuminance
type: float
restore_value: no
initial_value: "-1"
improv_serial:
debug:
update_interval: 30s
# Enable Home Assistant API
api:
# encryption:
# use you own password
# key: "your-api-key"
ota:
- platform: esphome
password: "your-ota-password"
safe_mode:
disabled: true
wifi:
# output_power: 15dB
power_save_mode: LIGHT
# power_save_mode: NONE
reboot_timeout: 10min
ap:
ssid: "HUMAN-SENSOR L12"
captive_portal:
web_server:
port: 80
text_sensor:
- platform: template
name: "SCREEK Version"
id: screek_version
icon: mdi:information-outline
entity_category: "diagnostic"
update_interval: never
- platform: debug
reset_reason:
name: "ESP Reset Reason"
icon: mdi:anchor
disabled_by_default: True
- platform: wifi_info
ip_address:
name: ESP IP Address
entity_category: "diagnostic"
disabled_by_default: True
icon: mdi:ip-network
mac_address:
name: ESP MAC
entity_category: "diagnostic"
icon: mdi:ip-network
disabled_by_default: True
- platform: ld2412
version:
name: LD2412 FM Version
id: ld2412_fm_version
mac_address:
name: LD2412 Mac
id: ld2412_mac
binary_sensor:
- platform: status
name: Online
id: ink_ha_connected
- platform: ld2412
has_target:
name: Presence
has_moving_target:
name: Moving Target
has_still_target:
name: Still Target
sensor:
- platform: internal_temperature
name: "ESP Temperature"
unit_of_measurement: °C
device_class: TEMPERATURE
update_interval: 30s
entity_category: "diagnostic"
- platform: uptime
name: ESP Uptime
id: sys_uptime
update_interval: 60s
- platform: wifi_signal
name: RSSI
id: wifi_signal_db
update_interval: 60s
entity_category: "diagnostic"
- platform: template
id: esp_memory
icon: mdi:memory
name: ESP Free Memory
lambda: return heap_caps_get_free_size(MALLOC_CAP_INTERNAL) / 1024;
unit_of_measurement: 'kB'
state_class: measurement
entity_category: "diagnostic"
update_interval: 60s
- platform: ld2412
moving_distance:
name : Moving Distance
id: moving_distance
still_distance:
name: Still Distance
id: still_distance
moving_energy:
name: Move Energy
still_energy:
name: Still Energy
luminance:
name: luminance
light:
- platform: status_led
name: sys_status
pin:
number: GPIO13
ignore_pin_validation_error: true
internal: True
restore_mode: ALWAYS_OFF
- platform: binary
name: "Red Info Light"
output: board_info_ed
entity_category: diagnostic
restore_mode: ALWAYS_OFF
time:
- platform: sntp
id: time_now
output:
- platform: gpio
id: board_info_ed
pin:
number: GPIO12
ignore_pin_validation_error: true
switch:
- platform: factory_reset
name: "L12 Factory Reset"
disabled_by_default: True
icon: mdi:heart-broken
entity_category: diagnostic
button:
- platform: restart
icon: mdi:power-cycle
name: "ESP Reboot"
entity_category: diagnostic
- platform: template
name: "LD2412 BLE Enable"
# disabled_by_default: True
entity_category: "config"
icon: mdi:bluetooth
on_press:
lambda: |-
id(ld2412_radar) -> ble_control(true);
- platform: template
name: "LD2412 BLE Disable"
# disabled_by_default: True
entity_category: "config"
icon: mdi:bluetooth-off
on_press:
lambda: |-
id(ld2412_radar) -> ble_control(false);
- platform: template
name: "LD2412 Reboot"
icon: mdi:radar
entity_category: "config"
on_press:
lambda: |-
id(ld2412_radar) -> reboot();
- platform: template
name: "LD2412 Factory Reset"
icon: mdi:restart
entity_category: "config"
on_press:
- lambda: |-
id(ld2412_radar) -> factoryReset();
uart:
id: uart_bus
tx_pin:
number: GPIO11
mode:
input: true
pullup: true
rx_pin:
number: GPIO7
mode:
input: true
pullup: true
baud_rate: 115200
parity: NONE
stop_bits: 1
data_bits: 8
ld2412:
id: ld2412_radar

View File

@ -0,0 +1,272 @@
esphome:
name: screek-human-sensor-l12
comment: Screek Human Sensor L12
friendly_name: Human Sensor L12
name_add_mac_suffix: True
platformio_options:
board_build.flash_mode: dio
project:
name: Screek.Human_Presence_Sensor
version: L12
on_boot:
- priority: 100
then:
lambda: |-
id(cpu_speed) = ESP.getCpuFreqMHz();
- priority: 300
then:
lambda: |-
id(screek_version).publish_state("BETA_V240712_2");
logger:
# level: VERY_VERBOSE
# level: DEBUG
preferences:
flash_write_interval: 5s
external_components:
- source:
type: git
url: https://github.com/screekworkshop/custom_components_support_for_screek_l12
ref: main
components: [uart, ld2412]
esp32:
board: lolin_c3_mini
framework:
type: arduino
version: 2.0.9
platform_version: 6.3.0
globals:
- id: cpu_speed
type: int
restore_value: no
initial_value: '0'
- id: last_update_ld2450
type: unsigned long
restore_value: no
initial_value: '0'
- id: init_zone_publish
type: bool
restore_value: no
initial_value: "false"
- id: last_illuminance
type: float
restore_value: no
initial_value: "-1"
improv_serial:
debug:
update_interval: 30s
# Enable Home Assistant API
api:
# encryption:
# use you own password
# key: "your-api-key"
ota:
- platform: esphome
password: "your-ota-password"
safe_mode:
disabled: true
wifi:
# output_power: 15dB
power_save_mode: LIGHT
# power_save_mode: NONE
reboot_timeout: 10min
ap:
ssid: "HUMAN-SENSOR L12"
captive_portal:
web_server:
port: 80
text_sensor:
- platform: template
name: "SCREEK Version"
id: screek_version
icon: mdi:information-outline
entity_category: "diagnostic"
update_interval: never
- platform: debug
reset_reason:
name: "ESP Reset Reason"
icon: mdi:anchor
disabled_by_default: True
- platform: wifi_info
ip_address:
name: ESP IP Address
entity_category: "diagnostic"
disabled_by_default: True
icon: mdi:ip-network
mac_address:
name: ESP MAC
entity_category: "diagnostic"
icon: mdi:ip-network
disabled_by_default: True
- platform: ld2412
version:
name: LD2412 FM Version
id: ld2412_fm_version
mac_address:
name: LD2412 Mac
id: ld2412_mac
binary_sensor:
- platform: status
name: Online
id: ink_ha_connected
- platform: ld2412
has_target:
name: Presence
has_moving_target:
name: Moving Target
has_still_target:
name: Still Target
sensor:
- platform: template
name: "ESP CPU Speed"
accuracy_decimals: 0
icon: mdi:cpu-32-bit
unit_of_measurement: Mhz
disabled_by_default: True
lambda: |-
return (id(cpu_speed));
entity_category: "diagnostic"
update_interval: 600s
- platform: template
id: sys_esp_temperature
name: ESP Temperature
lambda: return temperatureRead();
unit_of_measurement: °C
device_class: TEMPERATURE
update_interval: 45s
entity_category: "diagnostic"
- platform: uptime
name: ESP Uptime
id: sys_uptime
update_interval: 60s
- platform: wifi_signal
name: RSSI
id: wifi_signal_db
update_interval: 60s
entity_category: "diagnostic"
- platform: template
id: esp_memory
icon: mdi:memory
name: ESP Free Memory
lambda: return heap_caps_get_free_size(MALLOC_CAP_INTERNAL) / 1024;
unit_of_measurement: 'kB'
state_class: measurement
entity_category: "diagnostic"
update_interval: 60s
- platform: ld2412
moving_distance:
name : Moving Distance
id: moving_distance
still_distance:
name: Still Distance
id: still_distance
moving_energy:
name: Move Energy
still_energy:
name: Still Energy
luminance:
name: luminance
light:
- platform: status_led
name: sys_status
pin:
number: GPIO13
ignore_pin_validation_error: true
internal: True
restore_mode: ALWAYS_OFF
- platform: binary
name: "Red Info Light"
output: board_info_ed
entity_category: diagnostic
restore_mode: ALWAYS_OFF
time:
- platform: sntp
id: time_now
output:
- platform: gpio
id: board_info_ed
pin:
number: GPIO12
ignore_pin_validation_error: true
switch:
- platform: factory_reset
name: "L12 Factory Reset"
disabled_by_default: True
icon: mdi:heart-broken
entity_category: diagnostic
button:
- platform: restart
icon: mdi:power-cycle
name: "ESP Reboot"
entity_category: diagnostic
- platform: template
name: "LD2412 BLE Enable"
# disabled_by_default: True
entity_category: "config"
icon: mdi:bluetooth
on_press:
lambda: |-
id(ld2412_radar) -> ble_control(true);
- platform: template
name: "LD2412 BLE Disable"
# disabled_by_default: True
entity_category: "config"
icon: mdi:bluetooth-off
on_press:
lambda: |-
id(ld2412_radar) -> ble_control(false);
- platform: template
name: "LD2412 Reboot"
icon: mdi:radar
entity_category: "config"
on_press:
lambda: |-
id(ld2412_radar) -> reboot();
- platform: template
name: "LD2412 Factory Reset"
icon: mdi:restart
entity_category: "config"
on_press:
- lambda: |-
id(ld2412_radar) -> factoryReset();
uart:
id: uart_bus
tx_pin:
number: GPIO11
mode:
input: true
pullup: true
rx_pin:
number: GPIO7
mode:
input: true
pullup: true
baud_rate: 115200
parity: NONE
stop_bits: 1
data_bits: 8
ld2412:
id: ld2412_radar

View File

@ -0,0 +1,292 @@
esphome:
name: screek-human-sensor-l13
comment: Screek Human Sensor L13
friendly_name: Human Sensor L13
name_add_mac_suffix: True
platformio_options:
board_build.flash_mode: dio
# board_build.f_cpu: 80000000L
project:
name: Screek.Human_Presence_Sensor
version: L13
on_boot:
- priority: 1000
then:
- lambda: |-
pinMode(2, OUTPUT);
digitalWrite(2, LOW);
delay(100);
- priority: 100
then:
lambda: |-
id(cpu_speed) = ESP.getCpuFreqMHz();
logger:
# level: VERY_VERBOSE
# level: DEBUG
preferences:
flash_write_interval: 5s
external_components:
- source:
type: git
url: https://github.com/screekworkshop/custom_components_support_for_screek_l12
ref: main
components: [ld2412]
esp32:
board: lolin_c3_mini
framework:
type: arduino
# version: 2.0.9
# platform_version: 6.3.0
globals:
- id: cpu_speed
type: int
restore_value: no
initial_value: '0'
- id: last_update_ld2450
type: unsigned long
restore_value: no
initial_value: '0'
- id: init_zone_publish
type: bool
restore_value: no
initial_value: "false"
- id: last_illuminance
type: float
restore_value: no
initial_value: "-1"
improv_serial:
debug:
update_interval: 30s
# Enable Home Assistant API
api:
# encryption:
# use you own password
# key: "b1b1F1ArnSZmIvk7WLL9oG19gjPTCmBP1irQlSlSDGY="
ota:
- platform: esphome
password: "your-ota-password"
safe_mode:
disabled: true
wifi:
# power_save_mode: LIGHT
reboot_timeout: 10min
ap:
ssid: "HUMAN-SENSOR L13"
captive_portal:
web_server:
port: 80
text_sensor:
- platform: debug
reset_reason:
name: "ESP Reset Reason"
icon: mdi:anchor
disabled_by_default: True
- platform: wifi_info
ip_address:
name: ESP IP Address
entity_category: "diagnostic"
disabled_by_default: True
icon: mdi:ip-network
mac_address:
name: ESP MAC
entity_category: "diagnostic"
icon: mdi:ip-network
disabled_by_default: True
- platform: ld2412
version:
name: LD2412S FM Version
id: ld2412_fm_version
mac_address:
name: LD2412S Mac
id: ld2412_mac
binary_sensor:
- platform: status
name: Online
id: ink_ha_connected
- platform: ld2412
has_target:
name: Presence
has_moving_target:
name: Moving Target
has_still_target:
name: Still Target
sensor:
- platform: template
name: "ESP CPU Speed"
accuracy_decimals: 0
icon: mdi:cpu-32-bit
unit_of_measurement: Mhz
disabled_by_default: True
lambda: |-
return (id(cpu_speed));
entity_category: "diagnostic"
update_interval: 600s
- platform: template
id: sys_esp_temperature
name: ESP Temperature
lambda: return temperatureRead();
unit_of_measurement: °C
device_class: TEMPERATURE
update_interval: 45s
entity_category: "diagnostic"
- platform: uptime
name: ESP Uptime
id: sys_uptime
update_interval: 60s
- platform: wifi_signal
name: RSSI
id: wifi_signal_db
update_interval: 60s
entity_category: "diagnostic"
- platform: template
id: esp_memory
icon: mdi:memory
name: ESP Free Memory
lambda: return heap_caps_get_free_size(MALLOC_CAP_INTERNAL) / 1024;
unit_of_measurement: 'kB'
state_class: measurement
entity_category: "diagnostic"
update_interval: 60s
- platform: ld2412
moving_distance:
name : Moving Distance
id: moving_distance
still_distance:
name: Still Distance
id: still_distance
moving_energy:
name: Move Energy
still_energy:
name: Still Energy
luminance:
name: LD2412S luminance
entity_category: diagnostic
- platform: bh1750
name: "BH1750 Illuminance"
address: 0x23
update_interval: 1s
light:
- platform: status_led
name: sys_status
pin:
number: GPIO13
ignore_pin_validation_error: True
internal: True
restore_mode: ALWAYS_OFF
- platform: binary
name: "Red Info Light"
output: board_info_ed
entity_category: diagnostic
restore_mode: ALWAYS_OFF
time:
- platform: sntp
id: time_now
output:
- platform: gpio
id: board_info_ed
pin:
number: GPIO12
ignore_pin_validation_error: True
esp32_improv:
authorizer: none
on_start:
then:
- logger.log: "Improv awaiting authorization/authorized"
on_provisioned:
then:
- logger.log: "Improv provisioned"
on_provisioning:
then:
- logger.log: "Improv provisioning"
on_stop:
then:
- logger.log: "Improv stopped"
switch:
- platform: factory_reset
name: "L13 Factory Reset" # 或许最好把雷达模块也重新初始化
disabled_by_default: True
icon: mdi:heart-broken
entity_category: diagnostic
button:
- platform: restart
icon: mdi:power-cycle
name: "ESP Reboot"
entity_category: diagnostic
- platform: template
name: "LD2412S BLE Enable"
# disabled_by_default: True
entity_category: "config"
icon: mdi:bluetooth
on_press:
lambda: |-
id(ld2412s_radar) -> ble_control(true);
- platform: template
name: "LD2412S BLE Disable"
# disabled_by_default: True
entity_category: "config"
icon: mdi:bluetooth-off
on_press:
lambda: |-
id(ld2412s_radar) -> ble_control(false);
- platform: template
name: "LD2412S Reboot"
icon: mdi:radar
entity_category: "config"
on_press:
lambda: |-
id(ld2412s_radar) -> reboot();
- platform: template
name: "LD2412S Factory Reset"
icon: mdi:restart
entity_category: "config"
on_press:
- lambda: |-
id(ld2412s_radar) -> factoryReset();
uart:
id: uart_bus
tx_pin:
number: GPIO11
mode:
input: true
pullup: true
rx_pin:
number: GPIO7
mode:
input: true
pullup: true
baud_rate: 115200
parity: NONE
stop_bits: 1
data_bits: 8
i2c:
sda: 10
scl: 3
scan: True
ld2412:
id: ld2412s_radar