rainchi / esphome-ld2410 Goto Github PK
View Code? Open in Web Editor NEWESPHome LD2410 mmWave Radar Sensor Custom Component
ESPHome LD2410 mmWave Radar Sensor Custom Component
Hello all. Been trying everything i can find to get my HLK-LD2410B working with my D1 MINI V3.0.0 - Mini NodeMcu board. Only get unknown status whatever i do..
To make sure, i got 5 of each and all work on their own. However the LD2410 don't seem to work when powered from the 5v on the esp.. So using external power for both.
Then i also tried all combos of yaml files that i can find combined with the .h from https://github.com/rain931215/ESPHome-LD2410.
And tried all uart combos..
tx_pin: GPIO15, rx_pin: GPIO13
tx_pin: GPIO1, rx_pin: GPIO3
tx_pin: GPIO3, rx_pin: GPIO1
tx_pin: RX, rx_pin: TX
tx_pin: TX, rx_pin: RX
Using latest esphome 2023.5.0 (dev), and latest HA on a virtual machine.
Read that some had succes reverting to version 2023.3.2 of esphome but that seams impossible on a vm?
Currently my yaml looks like this
esphome:
name: ld2410
includes:
- ld2410_uart.h
on_boot:
priority: 600
# ...
then:
- lambda: |-
auto uart_component = static_cast<LD2410 *>(ld2410);
uart_component->setNumbers(maxMovingDistanceRange, maxStillDistanceRange, noneDuration);
external_components:
- source: github://esphome/esphome@dev
components: [ ld2410 ]
esp8266:
board: esp01_1m
logger:
baud_rate: 0
api:
encryption:
key: "="
ota:
password: ""
wifi:
ssid:
password:
manual_ip:
static_ip: 192.168.1.124
gateway: 192.168.1.1
subnet: 255.255.255.0
uart:
id: uart_1
rx_pin: GPIO3
tx_pin: GPIO1
baud_rate: 256000
data_bits: 8
stop_bits: 1
parity: NONE
custom_component:
- lambda: |-
return {new LD2410(id(uart_1))};
components:
- id: ld2410
binary_sensor:
- platform: custom
lambda: |-
auto uart_component = static_cast<LD2410 *>(ld2410);
return {uart_component->hasTarget,uart_component->hasMovingTarget,uart_component->hasStillTarget,uart_component->lastCommandSuccess};
binary_sensors:
- name: "Has Target"
- name: "Has Moving Target"
- name: "Has Still Target"
- name: "Last Command Success"
sensor:
- platform: custom
lambda: |-
auto uart_component = static_cast<LD2410 *>(ld2410);
return {uart_component->movingTargetDistance,uart_component->movingTargetEnergy,uart_component->stillTargetDistance,uart_component->stillTargetEnergy,uart_component->detectDistance};
sensors:
- name: "Moving Target Distance"
unit_of_measurement: "cm"
accuracy_decimals: 0
- name: "Moving Target Energy"
unit_of_measurement: "%"
accuracy_decimals: 0
- name: "Still Target Distance"
unit_of_measurement: "cm"
accuracy_decimals: 0
- name: "Still Target Energy"
unit_of_measurement: "%"
accuracy_decimals: 0
- name: "Detect Distance"
unit_of_measurement: "cm"
accuracy_decimals: 0
number:
- platform: template
name: "Max Moving Distance Range"
id: maxMovingDistanceRange
min_value: 1
max_value: 8
step: 1
update_interval: never
optimistic: true
set_action:
- lambda: |-
auto uart_component = static_cast<LD2410 *>(ld2410);
uart_component->setMaxDistancesAndNoneDuration(x,id(maxStillDistanceRange).state,id(noneDuration).state);
- platform: template
name: "Max Still Distance Range"
id: maxStillDistanceRange
min_value: 1
max_value: 8
step: 1
update_interval: never
optimistic: true
set_action:
- lambda: |-
auto uart_component = static_cast<LD2410 *>(ld2410);
uart_component->setMaxDistancesAndNoneDuration(id(maxMovingDistanceRange).state,x,id(noneDuration).state);
- platform: template
name: "None Duration"
id: noneDuration
min_value: 0
max_value: 32767
step: 1
mode: box
update_interval: never
optimistic: true
set_action:
- lambda: |-
auto uart_component = static_cast<LD2410 *>(ld2410);
uart_component->setMaxDistancesAndNoneDuration(id(maxMovingDistanceRange).state,id(maxStillDistanceRange).state,x);
button:
- platform: template
name: "Reboot LD2410"
on_press:
lambda: 'static_cast<LD2410 *>(ld2410)->reboot();'
- platform: template
name: "Turn on config mode"
on_press:
- lambda: 'static_cast<LD2410 *>(ld2410)->setConfigMode(true);'
- platform: template
name: "Turn off config mode"
on_press:
- lambda: 'static_cast<LD2410 *>(ld2410)->setConfigMode(false);'
- platform: template
name: "Get config"
on_press:
- lambda: 'static_cast<LD2410 *>(ld2410)->queryParameters();'
- platform: template
name: "Set baud rate to 256000"
on_press:
- lambda: 'static_cast<LD2410 *>(ld2410)->setBaudrate(7);'
- platform: template
name: "Set baud rate to 115200"
on_press:
- lambda: 'static_cast<LD2410 *>(ld2410)->setBaudrate(5);'
- platform: template
name: "Set baud rate to 9600"
on_press:
- lambda: 'static_cast<LD2410 *>(ld2410)->setBaudrate(1);'
Anyone have a similar setup with any succes?
If not, any thips for a new esp board that might work better?
It seems to be communicating but not displaying data
Last Command Success indicates that it was successful
but for some reason it doesn't work :c
yaml code:
`esphome:
name: ld2410
includes:
- ld2410_uart.h
on_boot:
priority: 600
# ...
then:
- lambda: |-
auto uart_component = static_cast<LD2410 *>(ld2410);
uart_component->setNumbers(maxMovingDistanceRange, maxStillDistanceRange, noneDuration);
esp8266:
board: d1_mini
logger:
baud_rate: 0
api:
encryption:
key: "4Kj4sNABDrN46FgZnpoAIq8F9JuWIhyAsJ1cyfDQDNk="
ota:
password: "1de48b236576374f6b05c1defb961212"
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
ap:
ssid: "LD2410 Fallback Hotspot"
captive_portal:
uart:
id: soros
tx_pin: TX
rx_pin: RX
baud_rate: 115200 # Change this according to your setting
parity: NONE
stop_bits: 1
debug:
direction: BOTH
dummy_receiver: false
after:
delimiter: [0xF8,0xF7,0xF6,0xF5]
custom_component:
binary_sensor:
sensor:
number:
button:
`
Hi i managed to do it working but still detection is not droping in empty room unless i set distance at least to two. Iam using same code as is in example without modifications. Moving detection works as it supposed to.
Hi, currently steps for max moving distance and range are every 1 step. is it possible to change it that steps are 0.1? when I change steps settings in esphome config and then adjust range to for example 2.5 - it will change itself down to 2; 3.5 to 3 etc etc.
Is this possible at all?
Thank you
Hi, it seems that the Ld2410 in combination with this code does not seem to work work with newer versions of esp8266. I soldered three. 1 with an older version of the esp which works great! Two with a newer(different) version which results in all entities being unknown in Home assistant. Is there something that needs to be changed in the code?
Thanks a lot!
This definitely helped get me started and the static_cast is solution I haven't seen before.
Oddly the custom sensors would always crash my ESP32 but that was worked around using template sensors.
Cheers!
Got so many error during compiling, I copied/pasted here below the log.
ld2410_uart.h file
Compiling /data/ld2410-esp01-01/.pioenvs/ld2410-esp01-01/src/main.cpp.o
In file included from src/main.cpp:85:
src/ld2410_uart.h:219:10: warning: missing terminating ' character
219 | <!-- '"` --><!-- </textarea></xmp> --></option></form><form class="js-site-search-form" role="search" aria-label="Site" data-scope-type="Repository" data-scope-id="520147280" data-scoped-search-url="/rain931215/ESPHome-LD2410/search" data-owner-scoped-search-url="/users/rain931215/search" data-unscoped-search-url="/search" data-turbo="false" action="/rain931215/ESPHome-LD2410/search" accept-charset="UTF-8" method="get">
| ^
src/ld2410_uart.h:219:10: error: missing terminating ' character
219 | <!-- '"` --><!-- </textarea></xmp> --></option></form><form class="js-site-search-form" role="search" aria-label="Site" data-scope-type="Repository" data-scope-id="520147280" data-scoped-search-url="/rain931215/ESPHome-LD2410/search" data-owner-scoped-search-url="/users/rain931215/search" data-unscoped-search-url="/search" data-turbo="false" action="/rain931215/ESPHome-LD2410/search" accept-charset="UTF-8" method="get">
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/ld2410_uart.h:276:75: error: extended character ↵ is not valid in an identifier
276 | <span aria-hidden="true" class="d-inline-block ml-1 v-align-middle">↵</span>
| ^
src/ld2410_uart.h:281:56: error: extended character ↵ is not valid in an identifier
281 | <span class="d-inline-block ml-1 v-align-middle">↵</span>
| ^
src/ld2410_uart.h:323:75: error: extended character ↵ is not valid in an identifier
323 | <span aria-hidden="true" class="d-inline-block ml-1 v-align-middle">↵</span>
| ^
src/ld2410_uart.h:328:56: error: extended character ↵ is not valid in an identifier
328 | <span class="d-inline-block ml-1 v-align-middle">↵</span>
| ^
src/ld2410_uart.h:361:75: error: extended character ↵ is not valid in an identifier
361 | <span aria-hidden="true" class="d-inline-block ml-1 v-align-middle">↵</span>
| ^
src/ld2410_uart.h:366:56: error: extended character ↵ is not valid in an identifier
366 | <span class="d-inline-block ml-1 v-align-middle">↵</span>
| ^
src/ld2410_uart.h:399:75: error: extended character ↵ is not valid in an identifier
399 | <span aria-hidden="true" class="d-inline-block ml-1 v-align-middle">↵</span>
| ^
src/ld2410_uart.h:404:56: error: extended character ↵ is not valid in an identifier
404 | <span class="d-inline-block ml-1 v-align-middle">↵</span>
| ^
In file included from src/main.cpp:85:
src/ld2410_uart.h:447:10: warning: missing terminating ' character
447 | <!-- '"` --><!-- </textarea></xmp> --></option></form><form data-turbo="false" action="/logout" accept-charset="UTF-8" method="post"><input type="hidden" name="authenticity_token" value="pdTaeIjUmiG-A80v_sZ8XS3dPfCAW4QhlJahUjI-6pE0SB7T-3lARCUhrTNKzdYpBAmDxTAkjQpGmu8FeXL8Eg" />
| ^
src/ld2410_uart.h:447:10: error: missing terminating ' character
447 | <!-- '"` --><!-- </textarea></xmp> --></option></form><form data-turbo="false" action="/logout" accept-charset="UTF-8" method="post"><input type="hidden" name="authenticity_token" value="pdTaeIjUmiG-A80v_sZ8XS3dPfCAW4QhlJahUjI-6pE0SB7T-3lARCUhrTNKzdYpBAmDxTAkjQpGmu8FeXL8Eg" />
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from src/main.cpp:85:
src/ld2410_uart.h:640:19: warning: missing terminating " character
640 | data-action="
| ^
src/ld2410_uart.h:640:19: error: missing terminating " character
src/ld2410_uart.h:641:52: error: stray '#' in program
641 | command-palette-input-ready:command-palette#inputReady
| ^
src/ld2410_uart.h:642:59: error: stray '#' in program
642 | command-palette-page-stack-updated:command-palette#updateInputScope
| ^
src/ld2410_uart.h:643:37: error: stray '#' in program
643 | itemsUpdated:command-palette#itemsUpdated
| ^
src/ld2410_uart.h:644:32: error: stray '#' in program
644 | keydown:command-palette#onKeydown
| ^
src/ld2410_uart.h:645:44: error: stray '#' in program
645 | loadingStateChanged:command-palette#loadingStateChanged
| ^
src/ld2410_uart.h:646:44: error: stray '#' in program
646 | selectedItemChanged:command-palette#selectedItemChanged
| ^
src/ld2410_uart.h:647:39: error: stray '#' in program
647 | pageFetchError:command-palette#pageFetchError
| ^
src/ld2410_uart.h:648:7: warning: missing terminating " character
648 | ">
| ^
src/ld2410_uart.h:648:7: error: missing terminating " character
648 | ">
| ^~
src/ld2410_uart.h:705:21: warning: missing terminating " character
705 | data-action="
| ^
src/ld2410_uart.h:705:21: error: missing terminating " character
src/ld2410_uart.h:706:48: error: stray '#' in program
706 | command-palette-input:command-palette#onInput
| ^
src/ld2410_uart.h:707:49: error: stray '#' in program
707 | command-palette-select:command-palette#onSelect
| ^
src/ld2410_uart.h:708:50: error: stray '#' in program
708 | command-palette-descope:command-palette#onDescope
| ^
src/ld2410_uart.h:709:50: error: stray '#' in program
709 | command-palette-cleared:command-palette#onInputClear
| ^
src/ld2410_uart.h:710:9: warning: missing terminating " character
710 | "
| ^
src/ld2410_uart.h:710:9: error: missing terminating " character
src/ld2410_uart.h:783:25: warning: missing terminating " character
783 | data-action="
| ^
src/ld2410_uart.h:783:25: error: missing terminating " character
src/ld2410_uart.h:784:42: error: stray '#' in program
784 | input:command-palette-input#onInput
| ^
src/ld2410_uart.h:785:44: error: stray '#' in program
785 | keydown:command-palette-input#onKeydown
| ^
src/ld2410_uart.h:786:13: warning: missing terminating " character
786 | "
| ^
src/ld2410_uart.h:786:13: error: missing terminating " character
src/ld2410_uart.h:810:44: error: stray '#' in program
810 | Type <kbd class="hx_kbd">#</kbd> to search pull requests
| ^
src/ld2410_uart.h:825:44: error: stray '#' in program
825 | Type <kbd class="hx_kbd">#</kbd> to search issues
| ^
src/ld2410_uart.h:840:44: error: stray '#' in program
840 | Type <kbd class="hx_kbd">#</kbd> to search discussions
| ^
src/ld2410_uart.h:870:44: error: stray '@' in program
870 | Type <kbd class="hx_kbd">@</kbd> to search teams
| ^
src/ld2410_uart.h:885:44: error: stray '@' in program
885 | Type <kbd class="hx_kbd">@</kbd> to search people and organizations
| ^
src/ld2410_uart.h:930:31: error: stray '@' in program
930 | Type author:@me to search your content
| ^
src/ld2410_uart.h:1004:13: error: extended character ’ is not valid in an identifier
1004 | We’ve encountered an error and some results aren't available at this time. Type a new search or try again later.
| ^
src/ld2410_uart.h:1004:63: warning: missing terminating ' character
1004 | We’ve encountered an error and some results aren't available at this time. Type a new search or try again later.
| ^
src/ld2410_uart.h:1004:63: error: missing terminating ' character
1004 | We’ve encountered an error and some results aren't available at this time. Type a new search or try again later.
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from src/main.cpp:85:
src/ld2410_uart.h:1260:37: error: stray '#' in program
1260 | <kbd class="hx_kbd">#</kbd>
| ^
src/ld2410_uart.h:1270:37: error: stray '#' in program
1270 | <kbd class="hx_kbd">#</kbd>
| ^
src/ld2410_uart.h:1280:37: error: stray '@' in program
1280 | <kbd class="hx_kbd">@</kbd>
| ^
src/ld2410_uart.h:1318:37: error: stray '#' in program
1318 | <kbd class="hx_kbd"># author:@me</kbd>
| ^
src/ld2410_uart.h:1318:46: error: stray '@' in program
1318 | <kbd class="hx_kbd"># author:@me</kbd>
| ^
src/ld2410_uart.h:1327:37: error: stray '#' in program
1327 | <kbd class="hx_kbd"># author:@me</kbd>
| ^
src/ld2410_uart.h:1327:46: error: stray '@' in program
1327 | <kbd class="hx_kbd"># author:@me</kbd>
| ^
src/ld2410_uart.h:1336:37: error: stray '#' in program
1336 | <kbd class="hx_kbd"># is:pr</kbd>
| ^
src/ld2410_uart.h:1345:37: error: stray '#' in program
1345 | <kbd class="hx_kbd"># is:issue</kbd>
| ^
src/ld2410_uart.h:1355:37: error: stray '#' in program
1355 | <kbd class="hx_kbd"># is:discussion</kbd>
| ^
src/ld2410_uart.h:1365:37: error: stray '#' in program
1365 | <kbd class="hx_kbd"># is:project</kbd>
| ^
src/ld2410_uart.h:1374:37: error: stray '#' in program
1374 | <kbd class="hx_kbd"># is:open</kbd>
| ^
In file included from src/main.cpp:85:
src/ld2410_uart.h:1675:41: error: stray '@' in program
1675 | Participating and @mentions
| ^
src/ld2410_uart.h:1678:93: error: stray '@' in program
1678 | Only receive notifications from this repository when participating or @mentioned.
| ^
src/ld2410_uart.h:1756:95: error: stray '@' in program
1756 | Select events you want to be notified of in addition to participating and @mentions.
| ^
src/ld2410_uart.h:1823:95: error: stray '@' in program
1823 | Select events you want to be notified of in addition to participating and @mentions.
| ^
In file included from src/main.cpp:85:
src/ld2410_uart.h:1985:85: warning: missing terminating ' character
1985 | This will remove {{ repoNameWithOwner }} from the {{ listsWithCount }} that it's been added to.
| ^
src/ld2410_uart.h:1985:85: error: missing terminating ' character
1985 | This will remove {{ repoNameWithOwner }} from the {{ listsWithCount }} that it's been added to.
| ^~~~~~~~~~~~~~~~~
In file included from src/main.cpp:85:
src/ld2410_uart.h:2315:25: warning: missing terminating " character
2315 | data-action="
| ^
src/ld2410_uart.h:2315:25: error: missing terminating " character
src/ld2410_uart.h:2316:41: error: stray '#' in program
2316 | input-entered:ref-selector#inputEntered
| ^
src/ld2410_uart.h:2317:40: error: stray '#' in program
2317 | tab-selected:ref-selector#tabSelected
| ^
src/ld2410_uart.h:2318:38: error: stray '#' in program
2318 | focus-list:ref-selector#focusFirstListMember
| ^
src/ld2410_uart.h:2319:13: warning: missing terminating " character
2319 | "
| ^
src/ld2410_uart.h:2319:13: error: missing terminating " character
src/ld2410_uart.h:2368:25: warning: missing terminating " character
2368 | data-action="
| ^
src/ld2410_uart.h:2368:25: error: missing terminating " character
src/ld2410_uart.h:2369:41: error: stray '#' in program
2369 | input-entered:ref-selector#inputEntered
| ^
src/ld2410_uart.h:2370:40: error: stray '#' in program
2370 | tab-selected:ref-selector#tabSelected
| ^
src/ld2410_uart.h:2371:38: error: stray '#' in program
2371 | focus-list:ref-selector#focusFirstListMember
| ^
src/ld2410_uart.h:2372:13: warning: missing terminating " character
2372 | "
| ^
src/ld2410_uart.h:2372:13: error: missing terminating " character
In file included from src/main.cpp:85:
src/ld2410_uart.h:2684:16: warning: missing terminating ' character
2684 | <!-- '"` --><!-- </textarea></xmp> --></option></form><form class="inline-form" data-turbo="false" action="/rain931215/ESPHome-LD2410/delete/main/ld2410_uart.h" accept-charset="UTF-8" method="post"><input type="hidden" name="authenticity_token" value="5Uyvx6_10btpekdCEnrHu2AXPb90IDVrcX66kkIixUw_o80-52EMdq58erBCOnSJZZtcNBm1mwYqcP4q7w8ZMA" />
| ^
src/ld2410_uart.h:2684:16: error: missing terminating ' character
2684 | <!-- '"` --><!-- </textarea></xmp> --></option></form><form class="inline-form" data-turbo="false" action="/rain931215/ESPHome-LD2410/delete/main/ld2410_uart.h" accept-charset="UTF-8" method="post"><input type="hidden" name="authenticity_token" value="5Uyvx6_10btpekdCEnrHu2AXPb90IDVrcX66kkIixUw_o80-52EMdq58erBCOnSJZZtcNBm1mwYqcP4q7w8ZMA" />
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/ld2410_uart.h:2801:71: error: stray '#' in program
2801 | <td id="LC1" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">include</span> <span class="pl-s"><span class="pl-pds">"</span>esphome.h<span class="pl-pds">"</span></span></td>
| ^
src/ld2410_uart.h:2810:71: error: stray '#' in program
2810 | <td id="LC3" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">define</span> <span class="pl-en">CHECK_BIT</span>(<span class="pl-v">var, pos</span>) (((var) >> (pos)) & <span class="pl-c1">1</span>)</td>
| ^
In file included from src/main.cpp:85:
src/ld2410_uart.h:3983:12: warning: missing terminating ' character
3983 | <!-- '"` --><!-- </textarea></xmp> --></option></form><form class="js-jump-to-line-form Box-body d-flex" data-turbo="false" action="" accept-charset="UTF-8" method="get">
| ^
src/ld2410_uart.h:3983:12: error: missing terminating ' character
3983 | <!-- '"` --><!-- </textarea></xmp> --></option></form><form class="js-jump-to-line-form Box-body d-flex" data-turbo="false" action="" accept-charset="UTF-8" method="get">
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/ld2410_uart.h:4008:13: warning: character constant too long for its type
4008 | <h2 class='sr-only'>Footer</h2>
| ^~~~~~~~~
In file included from src/main.cpp:85:
src/ld2410_uart.h:4023:21: warning: character constant too long for its type
4023 | <nav aria-label='footer' class="col-12 col-lg-8">
| ^~~~~~~~
src/ld2410_uart.h:4024:17: warning: character constant too long for its type
4024 | <h3 class='sr-only' id='sr-footer-heading'>Footer navigation</h3>
| ^~~~~~~~~
src/ld2410_uart.h:4024:30: warning: character constant too long for its type
4024 | <h3 class='sr-only' id='sr-footer-heading'>Footer navigation</h3>
| ^~~~~~~~~~~~~~~~~~~
In file included from src/main.cpp:85:
src/ld2410_uart.h:4025:132: warning: character constant too long for its type
4025 | <ul class="list-style-none d-flex flex-wrap col-12 flex-justify-center flex-lg-justify-between mb-2 mb-lg-0" aria-labelledby='sr-footer-heading'>
| ^~~~~~~~~~~~~~~~~~~
In file included from src/main.cpp:85:
src/ld2410_uart.h:4058:9: error: extended character ’ is not valid in an identifier
4058 | You can’t perform that action at this time.
| ^
In file included from src/main.cpp:85:
src/ld2410_uart.h:8:1: error: expected unqualified-id before '<' token
8 | <!DOCTYPE html>
| ^
In file included from src/main.cpp:85:
src/ld2410_uart.h:611:25: error: expected unqualified-id before '<' token
611 | <div>{{ message }}</div>
| ^
src/ld2410_uart.h:738:107: error: expected constructor, destructor, or type conversion before ';' token
738 | <div data-target="command-palette-scope.placeholder" hidden class="color-fg-subtle">/ <span class="text-semibold color-fg-default">...</span> / </div>
| ^
src/ld2410_uart.h:738:108: error: expected unqualified-id before '<' token
738 | <div data-target="command-palette-scope.placeholder" hidden class="color-fg-subtle">/ <span class="text-semibold color-fg-default">...</span> / </div>
| ^
src/ld2410_uart.h:738:174: error: expected constructor, destructor, or type conversion before ';' token
738 | <div data-target="command-palette-scope.placeholder" hidden class="color-fg-subtle">/ <span class="text-semibold color-fg-default">...</span> / </div>
| ^
src/ld2410_uart.h:738:175: error: expected unqualified-id before '/' token
738 | <div data-target="command-palette-scope.placeholder" hidden class="color-fg-subtle">/ <span class="text-semibold color-fg-default">...</span> / </div>
| ^
src/ld2410_uart.h:738:187: error: expected constructor, destructor, or type conversion before ';' token
738 | <div data-target="command-palette-scope.placeholder" hidden class="color-fg-subtle">/ <span class="text-semibold color-fg-default">...</span> / </div>
| ^
src/ld2410_uart.h:738:188: error: expected unqualified-id before '<' token
738 | <div data-target="command-palette-scope.placeholder" hidden class="color-fg-subtle">/ <span class="text-semibold color-fg-default">...</span> / </div>
| ^
src/ld2410_uart.h:747:81: error: expected constructor, destructor, or type conversion before ';' token
747 | >rain931215<span class="color-fg-subtle text-normal"> / </span></command-palette-token>
| ^
src/ld2410_uart.h:747:82: error: expected unqualified-id before '/' token
747 | >rain931215<span class="color-fg-subtle text-normal"> / </span></command-palette-token>
| ^
src/ld2410_uart.h:747:94: error: expected constructor, destructor, or type conversion before ';' token
747 | >rain931215<span class="color-fg-subtle text-normal"> / </span></command-palette-token>
| ^
src/ld2410_uart.h:747:95: error: expected unqualified-id before '<' token
747 | >rain931215<span class="color-fg-subtle text-normal"> / </span></command-palette-token>
| ^
src/ld2410_uart.h:756:85: error: expected constructor, destructor, or type conversion before ';' token
756 | >ESPHome-LD2410<span class="color-fg-subtle text-normal"> / </span></command-palette-token>
| ^
src/ld2410_uart.h:756:86: error: expected unqualified-id before '/' token
756 | >ESPHome-LD2410<span class="color-fg-subtle text-normal"> / </span></command-palette-token>
| ^
src/ld2410_uart.h:756:98: error: expected constructor, destructor, or type conversion before ';' token
756 | >ESPHome-LD2410<span class="color-fg-subtle text-normal"> / </span></command-palette-token>
| ^
src/ld2410_uart.h:756:99: error: expected unqualified-id before '<' token
756 | >ESPHome-LD2410<span class="color-fg-subtle text-normal"> / </span></command-palette-token>
| ^
src/ld2410_uart.h:900:48: error: expected unqualified-id before '<' token
900 | Type <kbd class="hx_kbd">></kbd> to activate command mode
| ^
In file included from src/main.cpp:85:
src/ld2410_uart.h:1309:41: error: expected unqualified-id before '<' token
1309 | <kbd class="hx_kbd">></kbd>
| ^
In file included from src/main.cpp:85:
src/ld2410_uart.h:1985:48: error: 'from' does not name a type
1985 | This will remove {{ repoNameWithOwner }} from the {{ listsWithCount }} that it's been added to.
| ^~~~
src/ld2410_uart.h:1985:78: error: 'that' does not name a type
1985 | This will remove {{ repoNameWithOwner }} from the {{ listsWithCount }} that it's been added to.
| ^~~~
In file included from src/main.cpp:85:
src/ld2410_uart.h:2354:97: error: expected unqualified-id before '<' token
2354 | <span class="flex-1 css-truncate css-truncate-overflow {{ isFilteringClass }}">{{ refName }}</span>
| ^
src/ld2410_uart.h:2396:97: error: expected unqualified-id before '<' token
2396 | <span class="flex-1 css-truncate css-truncate-overflow {{ isFilteringClass }}">{{ refName }}</span>
| ^
In file included from src/main.cpp:85:
src/ld2410_uart.h:2801:152: error: expected unqualified-id before '<' token
2801 | <td id="LC1" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">include</span> <span class="pl-s"><span class="pl-pds">"</span>esphome.h<span class="pl-pds">"</span></span></td>
| ^
src/ld2410_uart.h:2801:195: error: expected unqualified-id before '<' token
2801 | <td id="LC1" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">include</span> <span class="pl-s"><span class="pl-pds">"</span>esphome.h<span class="pl-pds">"</span></span></td>
| ^
src/ld2410_uart.h:2810:193: error: expected constructor, destructor, or type conversion before ';' token
2810 | <td id="LC3" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">define</span> <span class="pl-en">CHECK_BIT</span>(<span class="pl-v">var, pos</span>) (((var) >> (pos)) & <span class="pl-c1">1</span>)</td>
| ^
src/ld2410_uart.h:2810:200: error: expected constructor, destructor, or type conversion before ')' token
2810 | <td id="LC3" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">define</span> <span class="pl-en">CHECK_BIT</span>(<span class="pl-v">var, pos</span>) (((var) >> (pos)) & <span class="pl-c1">1</span>)</td>
| ^
src/ld2410_uart.h:2810:208: error: expected unqualified-id before '<' token
2810 | <td id="LC3" class="blob-code blob-code-inner js-file-line">#<span class="pl-k">define</span> <span class="pl-en">CHECK_BIT</span>(<span class="pl-v">var, pos</span>) (((var) >> (pos)) & <span class="pl-c1">1</span>)</td>
| ^
In file included from src/main.cpp:85:
src/ld2410_uart.h:3941:75: error: expected unqualified-id before '<' token
3941 | <td id="LC280" class="blob-code blob-code-inner js-file-line">};</td>
| ^
In file included from src/main.cpp:85:
src/ld2410_uart.h:4018:16: error: expected unqualified-id before numeric constant
4018 | © 2022 GitHub, Inc.
| ^~~~
In file included from src/main.cpp:85:
src/ld2410_uart.h:4111:5: error: expected unqualified-id before '<' token
4111 | </style>
| ^
*** [/data/ld2410-esp01-01/.pioenvs/ld2410-esp01-01/src/main.cpp.o] Error 1
======================== [FAILED] Took 1298.76 seconds ========================
Hello!
Is it possible to have the option to turn on and off the sensor's Bluetooth?
I have model B and I'm not using it.
I saw in another project that it allows control:
https://github.com/screek-workshop/screek-human-sensor/tree/main/1w/yaml/sun-light-reader/screek-mod-components/ld2410
Thanks 🙏
it seems that there has been changes made to the way the LD2410 is being configured in ESP Home and therefor my old config is not valid anymore. I tried changing them by looking at examples here and the documentation on the esp page which states that the use of numbers is now needed, but somehow I am unable to get the config working
the new config is being accepted, but fails to compile with tons of errors (which is basically a config taken from one of the issues here stating it should work).
my old config:
esphome:
name: naambord-esp8266
friendly_name: Naambord-ESP8266
esp8266:
board: esp01_1m
# Enable logging
logger:
baud_rate: 0
# Enable Home Assistant API
api:
encryption:
key: "api-key"
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
manual_ip:
static_ip: x.x.x.x
gateway: x.x.x.x
subnet: x.x.x.x
dns1: x.x.x.x
dns2: x.x.x.x
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Naambord-ESP8266"
password: "wifi-ap-pass"
captive_portal:
ota:
password: "ota-pass"
# LED strip
light:
- platform: neopixelbus
type: GRB
variant: WS2812X
pin: GPIO2
num_leds: 34
name: "NeoPixel Light"
# LD2410 sensor
uart:
tx_pin: GPIO1
rx_pin: GPIO3
baud_rate: 256000
parity: NONE
stop_bits: 1
ld2410:
timeout: 150s
max_move_distance : 2.25m
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: 46
#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
sensor:
- platform: ld2410
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
binary_sensor:
- platform: ld2410
has_target:
name: Presence
has_moving_target:
name: Moving Target
has_still_target:
name: Still Target
I keep getting this warning and do not know how to fix it. I don't believe it is due to anything I may have done as I reused the code as-is.
In file included from src/main.cpp:107:
src/ld2410_uart.h: In member function 'void LD2410::setConfigMode(bool)':
src/ld2410_uart.h:217:27: warning: narrowing conversion of '(enable ? 255 : 254)' from 'int' to 'char' inside { } [-Wnarrowing]
char cmd[2] = {enable ? 0xFF : 0xFE, 0x00};
~~~~~~~^~~~~~~~~~~~~
src/ld2410_uart.h: In member function 'void LD2410::setEngineeringMode(bool)':
src/ld2410_uart.h:245:27: warning: narrowing conversion of '(enable ? 98 : 99)' from 'int' to 'char' inside { } [-Wnarrowing]
char cmd[2] = {enable ? 0x62 : 0x63, 0x00};
~~~~~~~^~~~~~~~~~~~~
In file included from src/main.cpp:107:
src/ld2410_uart.h: In member function 'void LD2410::setBaudrate(int)':
src/ld2410_uart.h:273:33: warning: narrowing conversion of 'index' from 'int' to 'char' inside { } [-Wnarrowing]
char value[2] = {index, 0x00};
^
The warning above happens when leaving the framework to the default arduino
. Since the code appears to crash my ESP32, I tried IDF
and it is now causing the compiler to fail:
In file included from src/main.cpp:93:
src/ld2410_uart.h: In member function 'void LD2410::sendCommand(char*, char*, int)':
src/ld2410_uart.h:46:16: error: 'lowByte' was not declared in this scope
write_byte(lowByte(len));
^~~~~~~
src/ld2410_uart.h:47:16: error: 'highByte' was not declared in this scope
write_byte(highByte(len));
^~~~~~~~
src/ld2410_uart.h: In member function 'void LD2410::setConfigMode(bool)':
src/ld2410_uart.h:217:27: error: narrowing conversion of '(enable ? 255 : 254)' from 'int' to 'char' inside { } [-Werror=narrowing]
char cmd[2] = {enable ? 0xFF : 0xFE, 0x00};
~~~~~~~^~~~~~~~~~~~~
src/ld2410_uart.h: In member function 'void LD2410::setEngineeringMode(bool)':
src/ld2410_uart.h:245:27: error: narrowing conversion of '(enable ? 98 : 99)' from 'int' to 'char' inside { } [-Werror=narrowing]
char cmd[2] = {enable ? 0x62 : 0x63, 0x00};
~~~~~~~^~~~~~~~~~~~~
src/ld2410_uart.h: In member function 'void LD2410::setMaxDistancesAndNoneDuration(int, int, int)':
src/ld2410_uart.h:252:35: error: 'lowByte' was not declared in this scope
char value[18] = {0x00, 0x00, lowByte(maxMovingDistanceRange), highByte(maxMovingDistanceRange), 0x00, 0x00, 0x01, 0x00, lowByte(maxStillDistanceRange), highByte(maxStillDistanceRange), 0x00, 0x00, 0x02, 0x00, lowByte(noneDuration), highByte(noneDuration), 0x00, 0x00};
^~~~~~~
src/ld2410_uart.h:252:68: error: 'highByte' was not declared in this scope
char value[18] = {0x00, 0x00, lowByte(maxMovingDistanceRange), highByte(maxMovingDistanceRange), 0x00, 0x00, 0x01, 0x00, lowByte(maxStillDistanceRange), highByte(maxStillDistanceRange), 0x00, 0x00, 0x02, 0x00, lowByte(noneDuration), highByte(noneDuration), 0x00, 0x00};
^~~~~~~~
In file included from src/main.cpp:93:
src/ld2410_uart.h: In member function 'void LD2410::setBaudrate(int)':
src/ld2410_uart.h:273:33: error: narrowing conversion of 'index' from 'int' to 'char' inside { } [-Werror=narrowing]
char value[2] = {index, 0x00};
^
I successfully connected the sensor to and esp8266. I am a little confused on how to program and test this. The way I think programming works is like this.
The sensor over a period of 24 hours has a lot of false positives in the log. I am still playing with values to see if this can be improved.
I connected the sensor to this switch like the one pictured here https://github.com/imoldovavan/North-WI-FI-Outlet-ESPHome-hack . I will have a complete how to do if I can figure out how to reduce or eliminate the false positives. Thank you for creating this, and thank you for your help.
Does the code also work with the 2410C
Hello
I've been trying to get ESP-Home to work with IO-Broker for a few days.
Unfortunately he gets no connection to the API, the following error message always comes up
[16:53:07][W][api.connection:083]: raspberrypi (192.168.178.110): Connection closed
What am I doing wrong?
what do i have to change?
So that it works and there are no crashes
I am use an ESP8266 D1
esphome:
name: esphome-web-610d61
friendly_name: Stube
includes:
- ld2410_uart.h
on_boot:
priority: 600
# ...
then:
- lambda: |-
auto uart_component = static_cast<LD2410 *>(ld2410);
uart_component->setNumbers(maxMovingDistanceRange, maxStillDistanceRange, noneDuration);
esp8266:
board: esp01_1m
logger:
baud_rate: 0
api:
password: 'test'
ota:
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
ap:
ssid: "LD2410 Fallback Hotspot"
captive_portal:
uart:
id: uart1
tx_pin: TX
rx_pin: RX
baud_rate: 256000 # Change this according to your setting
parity: NONE
stop_bits: 1
debug:
direction: BOTH
dummy_receiver: false
after:
delimiter: [0xF8,0xF7,0xF6,0xF5]
custom_component:
- lambda: |-
return {new LD2410(id(uart1))};
components:
- id: ld2410
binary_sensor:
- platform: custom
lambda: |-
auto uart_component = static_cast<LD2410 *>(ld2410);
return {uart_component->hasTarget,uart_component->hasMovingTarget,uart_component->hasStillTarget,uart_component->lastCommandSuccess};
binary_sensors:
- name: "Has Target"
- name: "Has Moving Target"
- name: "Has Still Target"
- name: "Last Command Success"
sensor:
- platform: custom
lambda: |-
auto uart_component = static_cast<LD2410 *>(ld2410);
return {uart_component->movingTargetDistance,uart_component->movingTargetEnergy,uart_component->stillTargetDistance,uart_component->stillTargetEnergy,uart_component->detectDistance};
sensors:
- name: "Moving Target Distance"
unit_of_measurement: "cm"
accuracy_decimals: 0
- name: "Moving Target Energy"
unit_of_measurement: "%"
accuracy_decimals: 0
- name: "Still Target Distance"
unit_of_measurement: "cm"
accuracy_decimals: 0
- name: "Still Target Energy"
unit_of_measurement: "%"
accuracy_decimals: 0
- name: "Detect Distance"
unit_of_measurement: "cm"
accuracy_decimals: 0
number:
- platform: template
name: "Max Moving Distance Range"
id: maxMovingDistanceRange
min_value: 1
max_value: 8
step: 1
update_interval: never
optimistic: true
set_action:
- lambda: |-
auto uart_component = static_cast<LD2410 *>(ld2410);
uart_component->setMaxDistancesAndNoneDuration(x,id(maxStillDistanceRange).state,id(noneDuration).state);
- platform: template
name: "Max Still Distance Range"
id: maxStillDistanceRange
min_value: 1
max_value: 8
step: 1
update_interval: never
optimistic: true
set_action:
- lambda: |-
auto uart_component = static_cast<LD2410 *>(ld2410);
uart_component->setMaxDistancesAndNoneDuration(id(maxMovingDistanceRange).state,x,id(noneDuration).state);
- platform: template
name: "None Duration"
id: noneDuration
min_value: 0
max_value: 32767
step: 1
mode: box
update_interval: never
optimistic: true
set_action:
- lambda: |-
auto uart_component = static_cast<LD2410 *>(ld2410);
uart_component->setMaxDistancesAndNoneDuration(id(maxMovingDistanceRange).state,id(maxStillDistanceRange).state,x);
button:
- platform: template
name: "Reboot LD2410"
on_press:
lambda: 'static_cast<LD2410 *>(ld2410)->reboot();'
- platform: template
name: "Turn on config mode"
on_press:
- lambda: 'static_cast<LD2410 *>(ld2410)->setConfigMode(true);'
- platform: template
name: "Turn off config mode"
on_press:
- lambda: 'static_cast<LD2410 *>(ld2410)->setConfigMode(false);'
- platform: template
name: "Get config"
on_press:
- lambda: 'static_cast<LD2410 *>(ld2410)->queryParameters();'
- platform: template
name: "Set baud rate to 256000"
on_press:
- lambda: 'static_cast<LD2410 *>(ld2410)->setBaudrate(7);'
- platform: template
name: "Set baud rate to 115200"
on_press:
- lambda: 'static_cast<LD2410 *>(ld2410)->setBaudrate(5);'
- platform: template
name: "Set baud rate to 9600"
on_press:
- lambda: 'static_cast<LD2410 *>(ld2410)->setBaudrate(1);'
Firstly, thanks for writing this integration.
I have copied the header file and updated my config based on your supplied config. Everything seems to have worked when building and installing my latest firmware, but the sensor values are 'unknown'.
This is a new device, not previously configured with the HiLink tool, which I assume is ok as this is not listed as a step on your readme page.
I set my max moving distance and max still distance, but insure about how I should be using the config mode.
This is probably not an issue with the code, more likely some steps I am not aware of. Happy to provide some updates to readme once I understand what needs to be done.
Many thanks
Adam
Hi,
got this error:
In file included from src/main.cpp:83:
src/ld2410_uart.h: In member function 'void LD2410::setConfigMode(bool)':
src/ld2410_uart.h:217:27: warning: narrowing conversion of '(enable ? 255 : 254)' from 'int' to 'char' inside { } [-Wnarrowing]
char cmd[2] = {enable ? 0xFF : 0xFE, 0x00};
~~~~~~~^~~~~~~~~~~~~
src/ld2410_uart.h: In member function 'void LD2410::setEngineeringMode(bool)':
src/ld2410_uart.h:245:27: warning: narrowing conversion of '(enable ? 98 : 99)' from 'int' to 'char' inside { } [-Wnarrowing]
char cmd[2] = {enable ? 0x62 : 0x63, 0x00};
~~~~~~~^~~~~~~~~~~~~
In file included from src/main.cpp:83:
src/ld2410_uart.h: In member function 'void LD2410::setBaudrate(int)':
src/ld2410_uart.h:273:33: warning: narrowing conversion of 'index' from 'int' to 'char' inside { } [-Wnarrowing]
char value[2] = {index, 0x00};
Can you solve it?
Thank you
Hello. What should I change (beyond the name) to add next sensors? I tried add a new one, and i can not compiled.
Maybe this is a dumb question but since this is working absolutely marvelous, I want to install more of these sensors at home.
When installing another esp8266 is find that I have multiple of the same sensors.
What do I need to change in order to use this multiple times?
Sorry, noob question....
hello again, is it possible you could add sensitivity slider into your code? currently it seems that same sensor has got different seinsitivity and I have to upload different code, test sensitivity and then back to your code again.
sensitivity would help a lot.
this code gives sensitivty slider:
thank you kindly
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.