techposts

LD2410 ESPHome Code

Aug 21st, 2024
12,255
3
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.21 KB | Software | 3 0
  1. #Paste Just below captive Portal - This is for LD2410 - Can be used with both ESP32 and ESP8266 Microcontrollers
  2.  
  3. web_server:
  4.   port: 80
  5.   include_internal: true
  6.  
  7. # ---------------------------------------------------------------------------------
  8.  
  9. light:
  10.   - platform: binary
  11.     name: "Blue Status Light"
  12.     output: light_output
  13.     id: led_light
  14.     restore_mode: ALWAYS_OFF
  15.  
  16. output:
  17.   - platform: gpio
  18.     pin: GPIO2
  19.     id: light_output
  20.  
  21. uart:
  22.   id: ld2410_uart
  23.   tx_pin: GPIO21 # TX
  24.   rx_pin: GPIO20 # RX
  25.   baud_rate: 256000
  26.   parity: NONE
  27.   stop_bits: 1
  28.  
  29. ld2410:
  30.   uart_id: ld2410_uart
  31.   throttle: 1500ms
  32.   id: ld2410_comp
  33.  
  34. select:
  35.   - platform: ld2410
  36.     distance_resolution:
  37.       name: distance resolution
  38.     baud_rate:
  39.       name: baud rate
  40.     light_function:
  41.       name: light function
  42.     out_pin_level:
  43.       name: out pin level
  44.  
  45. button:
  46.   - platform: ld2410
  47.     factory_reset:
  48.       name: "factory reset"
  49.     restart:
  50.       name: "restart"
  51.     query_params:
  52.       name: query params
  53.  
  54. number:
  55.   - platform: ld2410
  56.     timeout:
  57.       name: timeout
  58.     max_move_distance_gate:
  59.       name: max move distance gate
  60.     max_still_distance_gate:
  61.       name: max still distance gate
  62.     g0:
  63.       move_threshold:
  64.         name: g0 move threshold
  65.       still_threshold:
  66.         name: g0 still threshold
  67.     g1:
  68.       move_threshold:
  69.         name: g1 move threshold
  70.       still_threshold:
  71.         name: g1 still threshold
  72.     g2:
  73.       move_threshold:
  74.         name: g2 move threshold
  75.       still_threshold:
  76.         name: g2 still threshold
  77.     g3:
  78.       move_threshold:
  79.         name: g3 move threshold
  80.       still_threshold:
  81.         name: g3 still threshold
  82.     g4:
  83.       move_threshold:
  84.         name: g4 move threshold
  85.       still_threshold:
  86.         name: g4 still threshold
  87.     g5:
  88.       move_threshold:
  89.         name: g5 move threshold
  90.       still_threshold:
  91.         name: g5 still threshold
  92.     g6:
  93.       move_threshold:
  94.         name: g6 move threshold
  95.       still_threshold:
  96.         name: g6 still threshold
  97.     g7:
  98.       move_threshold:
  99.         name: g7 move threshold
  100.       still_threshold:
  101.         name: g7 still threshold
  102.     g8:
  103.       move_threshold:
  104.         name: g8 move threshold
  105.       still_threshold:
  106.         name: g8 still threshold
  107.     light_threshold:
  108.       name: light threshold
  109.  
  110. text_sensor:
  111.   - platform: ld2410
  112.     version:
  113.       name: "presenece sensor version"
  114.     mac_address:
  115.       name: "presenece sensor mac address"
  116.  
  117. switch:
  118.   - platform: ld2410
  119.     engineering_mode:
  120.       name: "engineering mode"
  121.     bluetooth:
  122.       name: control Bluetooth
  123.  
  124. sensor:
  125.   - platform: internal_temperature
  126.     name: "Internal Temperature"
  127.  
  128.   - platform: ld2410
  129.     moving_distance:
  130.       name: "Moving distance (cm)"
  131.     still_distance:
  132.       name: "Still Distance (cm)"
  133.     moving_energy:
  134.       name: "Move Energy (%)"
  135.     still_energy:
  136.       name: "Still Energy (%)"
  137.     detection_distance:
  138.       name: "Distance Detection (cm)"
  139.     g0:
  140.       move_energy:
  141.         name: g0 move energy
  142.       still_energy:
  143.         name: g0 still energy
  144.     g1:
  145.       move_energy:
  146.         name: g1 move energy
  147.       still_energy:
  148.         name: g1 still energy
  149.     g2:
  150.       move_energy:
  151.         name: g2 move energy
  152.       still_energy:
  153.         name: g2 still energy
  154.     g3:
  155.       move_energy:
  156.         name: g3 move energy
  157.       still_energy:
  158.         name: g3 still energy
  159.     g4:
  160.       move_energy:
  161.         name: g4 move energy
  162.       still_energy:
  163.         name: g4 still energy
  164.     g5:
  165.       move_energy:
  166.         name: g5 move energy
  167.       still_energy:
  168.         name: g5 still energy
  169.     g6:
  170.       move_energy:
  171.         name: g6 move energy
  172.       still_energy:
  173.         name: g6 still energy
  174.     g7:
  175.       move_energy:
  176.         name: g7 move energy
  177.       still_energy:
  178.         name: g7 still energy
  179.     g8:
  180.       move_energy:
  181.         name: g8 move energy
  182.       still_energy:
  183.         name: g8 still energy
  184.     light:
  185.       name: light
  186.  
  187. binary_sensor:
  188.  
  189.   - platform: ld2410
  190.     has_target:
  191.       name: Presence
  192.     has_moving_target:
  193.       name: Moving Target
  194.     has_still_target:
  195.       name: Still Target
Tags: smart Home
Advertisement
Comments
  • grf21a
    364 days
    # text 4.57 KB | 0 0
    1. Hi TechPosts, I found that the above code did not work for me and I suspect that this is because specific functions have been depreciated over time within the code and now cause errors to be reported. One example is "throttle: 1500ms" which is now replaced by Filters.
    2.  
    3. I managed to adjust several sections of the code to the following to get it working. I hope this can help some others out there that may be struggling:
    4.  
    5. web_server:
    6. port: 80
    7. include_internal: true
    8.  
    9. # ---------------------------------------------------------------------------------
    10.  
    11. light:
    12. - platform: binary
    13. name: "Blue Status Light"
    14. output: light_output
    15. id: led_light
    16. restore_mode: ALWAYS_OFF
    17.  
    18. output:
    19. - platform: gpio
    20. pin: GPIO2
    21. id: light_output
    22.  
    23. uart:
    24. id: uart_bus
    25. tx_pin: GPIO21 # Adjust pins depending on your ESP32-C3 board
    26. rx_pin: GPIO20
    27. baud_rate: 256000
    28. parity: NONE
    29. stop_bits: 1
    30.  
    31. ld2410:
    32. uart_id: uart_bus
    33. id: ld2410_comp
    34.  
    35. select:
    36. - platform: ld2410
    37. distance_resolution:
    38. name: distance resolution
    39. baud_rate:
    40. name: baud rate
    41. light_function:
    42. name: light function
    43. out_pin_level:
    44. name: out pin level
    45.  
    46. button:
    47. - platform: ld2410
    48. factory_reset:
    49. name: "factory reset"
    50. restart:
    51. name: "restart"
    52. query_params:
    53. name: query params
    54.  
    55. number:
    56. - platform: ld2410
    57. timeout:
    58. name: timeout
    59. max_move_distance_gate:
    60. name: max move distance gate
    61. max_still_distance_gate:
    62. name: max still distance gate
    63. g0:
    64. move_threshold:
    65. name: g0 move threshold
    66. still_threshold:
    67. name: g0 still threshold
    68. g1:
    69. move_threshold:
    70. name: g1 move threshold
    71. still_threshold:
    72. name: g1 still threshold
    73. g2:
    74. move_threshold:
    75. name: g2 move threshold
    76. still_threshold:
    77. name: g2 still threshold
    78. g3:
    79. move_threshold:
    80. name: g3 move threshold
    81. still_threshold:
    82. name: g3 still threshold
    83. g4:
    84. move_threshold:
    85. name: g4 move threshold
    86. still_threshold:
    87. name: g4 still threshold
    88. g5:
    89. move_threshold:
    90. name: g5 move threshold
    91. still_threshold:
    92. name: g5 still threshold
    93. g6:
    94. move_threshold:
    95. name: g6 move threshold
    96. still_threshold:
    97. name: g6 still threshold
    98. g7:
    99. move_threshold:
    100. name: g7 move threshold
    101. still_threshold:
    102. name: g7 still threshold
    103. g8:
    104. move_threshold:
    105. name: g8 move threshold
    106. still_threshold:
    107. name: g8 still threshold
    108. light_threshold:
    109. name: light threshold
    110.  
    111. text_sensor:
    112. - platform: ld2410
    113. version:
    114. name: "presenece sensor version"
    115. mac_address:
    116. name: "presenece sensor mac address"
    117.  
    118. switch:
    119. - platform: ld2410
    120. engineering_mode:
    121. name: "engineering mode"
    122. bluetooth:
    123. name: control Bluetooth
    124.  
    125. sensor:
    126. - platform: internal_temperature
    127. name: "Internal Temperature"
    128.  
    129. - platform: ld2410
    130. moving_distance:
    131. name: "Moving distance (cm)"
    132. filters:
    133. - throttle: 1s
    134. still_distance:
    135. name: "Still Distance (cm)"
    136. moving_energy:
    137. name: "Move Energy (%)"
    138. still_energy:
    139. name: "Still Energy (%)"
    140. detection_distance:
    141. name: "Distance Detection (cm)"
    142. g0:
    143. move_energy:
    144. name: g0 move energy
    145. still_energy:
    146. name: g0 still energy
    147. g1:
    148. move_energy:
    149. name: g1 move energy
    150. still_energy:
    151. name: g1 still energy
    152. g2:
    153. move_energy:
    154. name: g2 move energy
    155. still_energy:
    156. name: g2 still energy
    157. g3:
    158. move_energy:
    159. name: g3 move energy
    160. still_energy:
    161. name: g3 still energy
    162. g4:
    163. move_energy:
    164. name: g4 move energy
    165. still_energy:
    166. name: g4 still energy
    167. g5:
    168. move_energy:
    169. name: g5 move energy
    170. still_energy:
    171. name: g5 still energy
    172. g6:
    173. move_energy:
    174. name: g6 move energy
    175. still_energy:
    176. name: g6 still energy
    177. g7:
    178. move_energy:
    179. name: g7 move energy
    180. still_energy:
    181. name: g7 still energy
    182. g8:
    183. move_energy:
    184. name: g8 move energy
    185. still_energy:
    186. name: g8 still energy
    187. light:
    188. name: light
    189.  
    190. binary_sensor:
    191.  
    192. - platform: ld2410
    193. has_target:
    194. name: Presence
    195. has_moving_target:
    196. name: Moving Target
    197. has_still_target:
    198. name: Still Target
    199.  
Add Comment
Please, Sign In to add comment