I on the latest ESPHome v2024.4.2 with LD2410C pair with lolin_s2_mini. Possible to set a fixed “move_threshold” & “still_threshold” in yaml file as I already know the effective value? last year ESPHome still can set this fixed value in yaml file, but latest ESPHome required user to be set at HA interface.
There is a disadvantage to set this gate threshold value on HA interface, once your ESP board die & you configure a new board to use the existing setting, all the gate threshold value will be gone & need to set again ![:frowning: :frowning:](https://community.home-assistant.io/images/emoji/twitter/frowning.png?v=12)
old config:
ld2410:
timeout: 5s
id: uart_1
max_move_distance : 1.5m
max_still_distance: 0.75m
g0_move_threshold: 100
g0_still_threshold: 100
g1_move_threshold: 100
g1_still_threshold: 100
g2_move_threshold: 20
g2_still_threshold: 40
g3_move_threshold: 20
g3_still_threshold: 40
new config:
number:
- platform: ld2410
timeout:
name: timeout
max_move_distance_gate:
name: max move distance gate
max_still_distance_gate:
name: max still distance gate
g0:
move_threshold:
name: g0 move threshold
still_threshold:
name: g0 still threshold
g1:
move_threshold:
name: g1 move threshold
still_threshold:
name: g1 still threshold
g2:
move_threshold:
name: g2 move threshold
still_threshold:
name: g2 still threshold
g3:
move_threshold:
name: g3 move threshold
still_threshold:
name: g3 still threshold
You should be able to set the number in the ESPHome configuration. Give “max move distance gate” and “max still distance gate” some ids and use the number.set action (or a lambda) to set the number in the on_boot: section.
esphome:
# ...
on_boot:
priority: 600
# ...
then:
- number.set: max_move_distance_gate
value: 5
- number.set: max_still_distance_gate
value: 7
number:
- platform: ld2410
timeout:
max_move_distance_gate:
name: max move distance gate
id: max_move_distance_gate
max_still_distance_gate:
name: max still distance gate
id: max_still_distance_gate
And if you don’t want the number to show up in HA, you can just remove the name:
I haven’t tested this though.
PS. I find it easier to just use the HLKRadarTool app and bluetooth to set up the ld2410c and skip the number section in the ESPHome config altogether.
Thank for the reply, I already have some code on lambda as below
esphome:
#....
on_boot:
priority: 900
then:
lambda: |-
id(cpu_speed) = ESP.getCpuFreqMHz();
globals:
- id: cpu_speed
type: int
restore_value: no
initial_value: '0'
how to I add that fixed value inside? I really poor in this programing.
I put the code below
on_boot:
priority: 900
then:
lambda: |-
id(cpu_speed) = ESP.getCpuFreqMHz();
max_move_distance_gate = 3;
max_still_distance_gate = 3;
globals:
- id: cpu_speed
type: int
restore_value: no
initial_value: '0'
but when compile, it come out below error
/config/esphome/common25w-1d9b-ld2410c-esp32.yaml: In lambda function:
/config/esphome/common25w-1d9b-ld2410c-esp32.yaml:15:32: error: invalid conversion from 'int' to 'esphome::ld2410::MaxDistanceTimeoutNumber*' [-fpermissive]
max_move_distance_gate = 3;
^
/config/esphome/common25w-1d9b-ld2410c-esp32.yaml:16:33: error: invalid conversion from 'int' to 'esphome::ld2410::MaxDistanceTimeoutNumber*' [-fpermissive]
max_still_distance_gate = 3;
^
*** [.pioenvs/common25w-1d9b-ld2410c-esp32/src/main.cpp.o] Error 1
I modify the code abit then come out different error
on_boot:
priority: 900
then:
lambda: |-
id(cpu_speed) = ESP.getCpuFreqMHz();
"max_move_distance_gate" = 3;
"max_still_distance_gate" = 3;
globals:
- id: cpu_speed
type: int
restore_value: no
initial_value: '0'
different error come out
/config/esphome/common25w-1d9b-ld2410c-esp32.yaml: In lambda function:
/config/esphome/common25w-1d9b-ld2410c-esp32.yaml:15:34: error: assignment of read-only location '"max_move_distance_gate"'
"max_move_distance_gate" = 3;
^
/config/esphome/common25w-1d9b-ld2410c-esp32.yaml:16:35: error: assignment of read-only location '"max_still_distance_gate"'
"max_still_distance_gate" = 3;
^
Compiling .pioenvs/common25w-1d9b-ld2410c-esp32/libcce/WiFi/WiFiSTA.cpp.o
*** [.pioenvs/common25w-1d9b-ld2410c-esp32/src/main.cpp.o] Error 1
You need to make sure you’ve given the Number an id, as shown in my previous post. Then you can do it like this:
on_boot:
priority: 900
then:
lambda: |-
id(cpu_speed) = ESP.getCpuFreqMHz();
auto call = id(max_move_distance_gate).make_call();
call.set_value(3);
call.perform();
auto call = id(max_still_distance_gate).make_call();
call.set_value(3);
call.perform();
or like this:
on_boot:
priority: 900
then:
- lambda: |-
id(cpu_speed) = ESP.getCpuFreqMHz();
- number.set: max_move_distance_gate
value: 3
- number.set: max_still_distance_gate
value: 3
I would lower the on_boot priority to 600 though.
on_boot:
priority: 900
then:
lambda: |-
id(cpu_speed) = ESP.getCpuFreqMHz();
auto call = id(max_move_distance_gate).make_call();
call.set_value(3);
call.perform();
auto call = id(max_still_distance_gate).make_call();
call.set_value(3);
call.perform();
above code generate error when compile but ok on validate
/config/esphome/common25w-1d9b-ld2410c-esp32.yaml: In lambda function:
/config/esphome/common25w-1d9b-ld2410c-esp32.yaml:18:12: error: conflicting declaration 'auto call'
auto call = id(max_still_distance_gate).make_call();
^~~~
/config/esphome/common25w-1d9b-ld2410c-esp32.yaml:15:12: note: previous declaration as 'esphome::number::NumberCall call'
auto call = id(max_move_distance_gate).make_call();
^~~~
*** [.pioenvs/common25w-1d9b-ld2410c-esp32/src/main.cpp.o] Error 1
while below code also generate error code on validate,
on_boot:
priority: 900
then:
- lambda: |-
id(cpu_speed) = ESP.getCpuFreqMHz();
- number.set: max_move_distance_gate
value: 3
- number.set: max_still_distance_gate
value: 3
on_boot:
priority: 900
then:
- lambda: id(cpu_speed) = ESP.getCpuFreqMHz();
Cannot have two actions in one item. Key 'number.set' overrides 'value'! Did you forget to indent the block inside the number.set?.
- number.set: max_move_distance_gate
value: 3
Cannot have two actions in one item. Key 'number.set' overrides 'value'! Did you forget to indent the block inside the number.set?.
- number.set: max_still_distance_gate
value: 3
That’s the problem when I’m not at my computer and can’t test it. In the first one, it looks like you can’t reuse a variable. With the second, I think it’s just a matter of indentation.
on_boot:
priority: 900
then:
lambda: |-
id(cpu_speed) = ESP.getCpuFreqMHz();
auto call1 = id(max_move_distance_gate).make_call();
call1.set_value(3);
call1.perform();
auto call2 = id(max_still_distance_gate).make_call();
call2.set_value(3);
call2.perform();
on_boot:
priority: 900
then:
- lambda: |-
id(cpu_speed) = ESP.getCpuFreqMHz();
- number.set:
id: max_move_distance_gate
value: 3
- number.set:
id: max_still_distance_gate
value: 3
I try the 2nd code below
on_boot:
priority: 900
then:
- lambda: |-
id(cpu_speed) = ESP.getCpuFreqMHz();
- number.set:
id: max_move_distance_gate
value: 3
- number.set:
id: max_still_distance_gate
value: 3
above code can compile without error but somehow the set value not effective, I still can set the value on HA interface(let said i set it to 5) then try restart the ESP, value 5 will remain there, it didnt follow the value in yaml which is value 3
I trying 1st code as well, compile without error but
on_boot:
priority: 900
then:
lambda: |-
id(cpu_speed) = ESP.getCpuFreqMHz();
auto call1 = id(max_move_distance_gate).make_call();
call1.set_value(3);
call1.perform();
auto call2 = id(max_still_distance_gate).make_call();
call2.set_value(3);
call2.perform();
seem like same problem as 2nd code, after restart ESP, ESP didn’t follow the set value in yaml but follow the value set in HA.
Hmm. You could try to either remove the name: and only have the id: (or set internal: true), so the Number component won’t get exposed to HA. I don’t know if this would work, as I can’t test it at the moment.
number:
- platform: ld2410
timeout:
name: timeout
max_move_distance_gate:
id: max_move_distance_gate
max_still_distance_gate:
id: max_still_distance_gate
If that doesn’t work either, then I would suggest to drop the number and just use the HLKRadarTool app.
Also, unless you have a good reason to use priority 900 in on_boot, you should probably lower it.
1 Like