LD21410 + ceiling fan. How to exclude detection distance range

Neat idea.
If you don’t mind, I’ve enhanced this exlusion feature by making the begin and end of the exclusion distance configurable.

Here is what you need to do to implement it:

Add the id values to the following existing entities:

number:
  - platform: ld2410
    timeout:
      name: "timeout"
      id: timeout

binary_sensor:
  - platform: ld2410
    has_target:
      name: "Presence"
      id: presence

sensor:
  - platform: ld2410
    detection_distance:
      name: "Distance Detection (cm)"
      id: detection_distance

Then add the following:

number:
  - platform: template
    name: Exclusion Begin
    id: ex_start
    min_value: 0
    max_value: 900
    mode: box
    device_class: distance
    entity_category: config
    unit_of_measurement: cm
    icon: mdi:arrow-right-bold
    step: 1
    optimistic: True
    initial_value: 0
    restore_value: True
  - platform: template
    name: Exclusion End
    id: ex_end
    min_value: 0
    max_value: 900
    mode: box
    device_class: distance
    entity_category: config
    unit_of_measurement: cm
    icon: mdi:arrow-left-bold
    step: 1
    optimistic: True
    initial_value: 0
    restore_value: True

binary_sensor:
  - platform: template
    name: Presence with Exclusion
    device_class: occupancy
    filters:
      - delayed_off: !lambda |-
          return id(timeout).state * 1000.0;
    lambda: !lambda |-
      if (id(presence).state && id(detection_distance).state >= id(ex_start).state && id(detection_distance).state <= id(ex_end).state) {
        return 0;
      } else {
        return id(presence).state;
      }
1 Like