Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ld2450 detect only 1 target #6

Open
ayubn opened this issue Nov 4, 2024 · 1 comment
Open

ld2450 detect only 1 target #6

ayubn opened this issue Nov 4, 2024 · 1 comment

Comments

@ayubn
Copy link

ayubn commented Nov 4, 2024

hi,

after applying this code ld2450 only detects one target even if there are multiple persons in room

here is my Code

#Make on https://53l3cu5.github.io/
#Origin https://github.com/53l3cu5/ESP32_LD2450
#Inspire by https://docs.screek.io/2a
substitutions:
devicename: espwtceoroom
friendly_name: EspWtCEORoom
entity_name: "" # Leave empty if you want entities named "Target..." otherwise put "Room" to have an entity named "Room Target..."

specify below pin numbers of your LD2450

tx_pin_ld2450: GPIO17
rx_pin_ld2450: GPIO5

external_components:

#ESP32/LD2450 : Human Presence Sensor by Zone
esphome:
name: $devicename
friendly_name: ${friendly_name}
comment: Human Presence Sensor by Zone (ESP32/LD2450)
#name_add_mac_suffix: True
platformio_options:
board_build.flash_mode: dio
# board_build.f_cpu: 80000000L
project:
name: 53l3cu5.Human_Presence_Sensor_by_Zone
version: "2.2"
on_boot:
- priority: -200
then:
lambda: |-
id(zone1_target_exist).publish_state(false);
id(zone2_target_exist).publish_state(false);
id(zone3_target_exist).publish_state(false);
id(zone_ex1_target_exist).publish_state(false);
id(zone_ex2_target_exist).publish_state(false);
id(zone_ex3_target_exist).publish_state(false);
includes:
- zone.h

preferences:
flash_write_interval: 5s

esp32:
board: esp32dev

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"

logger:

debug:
update_interval: 30s

api:
encryption:
key: "GXIGHnGfRNqpBFMvpuV4xZgvs5x/yJzw39bYLtlwQu4="

ota:

  • platform: esphome
    password: "4ef162ddae1f5f45b55bdc10d8eb1333"

ethernet:
type: LAN8720
mdc_pin: GPIO23
mdio_pin: GPIO18
clk_mode: GPIO0_IN
phy_addr: 1
power_pin: GPIO16

manual_ip:
static_ip: 192.168.2.230
gateway: 192.168.2.3
subnet: 255.255.255.0

web_server:
port: 80
one_wire:

  • platform: gpio
    pin: 4

text_sensor:

  • platform: version
    name: "Version"
  • platform: debug
    reset_reason:
    name: ${entity_name} ESP Reset Reason
    icon: mdi:anchor
    disabled_by_default: True
  • platform: template
    name: ${entity_name} Zone1 Info
    id: tips_zone1_conf
    icon: mdi:information-outline
    entity_category: config
    lambda: |-
    return {"Configure below" };
    update_interval: 1000s
  • platform: template
    name: ${entity_name} Zone2 Info
    id: tips_zone2_conf
    icon: mdi:information-outline
    entity_category: config
    lambda: |-
    return {"Configure below" };
    update_interval: 1000s
  • platform: template
    name: ${entity_name} Zone3 Info
    id: tips_zone3_conf
    icon: mdi:information-outline
    entity_category: config
    lambda: |-
    return {"Configure below" };
    update_interval: 1000s
  • platform: template
    name: ${entity_name} Zout1 Info
    id: tips_zone_ex1_conf
    icon: mdi:information-outline
    entity_category: config
    lambda: |-
    return {"Zone Exclusion 1" };
    update_interval: 1000s
  • platform: template
    name: ${entity_name} Zout2 Info
    id: tips_zone_ex2_conf
    icon: mdi:information-outline
    entity_category: config
    lambda: |-
    return {"Zone Exclusion 2" };
    update_interval: 1000s
  • platform: template
    name: ${entity_name} Zout3 Info
    id: tips_zone_ex3_conf
    icon: mdi:information-outline
    entity_category: config
    lambda: |-
    return {"Zone Exclusion 3" };
    update_interval: 1000s
  • platform: template
    name: ${entity_name} Any-Presence Info
    id: tips_any_presence_conf
    icon: mdi:information-outline
    entity_category: config
    lambda: |-
    return {"Any Presence Config" };
    update_interval: 1000s
  • platform: template
    name: ${entity_name} Target1 Direction
    id: target1_direction
    icon: mdi:directions
  • platform: template
    name: ${entity_name} Target2 Direction
    id: target2_direction
    icon: mdi:directions
  • platform: template
    name: ${entity_name} Target3 Direction
    id: target3_direction
    icon: mdi:directions
  • platform: template
    name: ${entity_name} Target1 Position
    id: target1_position
    icon: mdi:directions
  • platform: template
    name: ${entity_name} Target2 Position
    id: target2_position
    icon: mdi:directions
  • platform: template
    name: ${entity_name} Target3 Position
    id: target3_position
    icon: mdi:directions

number:

  • platform: template
    name: ${entity_name} Angle
    id: wall_angle
    min_value: 0
    max_value: 90
    mode: box
    device_class: duration
    entity_category: config
    unit_of_measurement: °
    icon: mdi:angle-acute
    step: 1
    optimistic: True
    initial_value: 0
    restore_value: True
  • platform: template
    name: ${entity_name} Any Presence Timeout
    id: any_presence_timeout
    min_value: 0
    max_value: 600
    mode: box
    device_class: duration
    entity_category: config
    unit_of_measurement: s
    icon: mdi:timer-off
    step: 1
    optimistic: True
    initial_value: 0
    restore_value: True
  • platform: template
    name: ${entity_name} Zone1 Timeout
    id: zone1_timeout
    min_value: 0
    max_value: 600
    mode: box
    device_class: duration
    entity_category: config
    unit_of_measurement: s
    icon: mdi:timer-off
    step: 1
    optimistic: True
    initial_value: 0
    restore_value: True
  • platform: template
    name: ${entity_name} Zone2 Timeout
    id: zone2_timeout
    min_value: 0
    max_value: 600
    mode: box
    device_class: duration
    entity_category: config
    unit_of_measurement: s
    icon: mdi:timer-off
    step: 1
    optimistic: True
    initial_value: 0
    restore_value: True
  • platform: template
    name: ${entity_name} Zone3 Timeout
    id: zone3_timeout
    min_value: 0
    max_value: 600
    mode: box
    device_class: duration
    entity_category: config
    unit_of_measurement: s
    icon: mdi:timer-off
    step: 1
    optimistic: True
    initial_value: 0
    restore_value: True

Zone 1

  • platform: template
    name: ${entity_name} Zone1 X
    id: zone1_x
    min_value: -4000
    max_value: 4000
    mode: box
    device_class: distance
    entity_category: config
    unit_of_measurement: mm
    icon: mdi:arrow-left-bold
    step: 10
    optimistic: True
    initial_value: 0
    restore_value: True
    on_value:
    then:
    - lambda: check_zone_valid(id(zone1_x).state, id(zone1_y).state, id(zone1_width).state, id(zone1_height).state, tips_zone1_conf);
  • platform: template
    name: ${entity_name} Zone1 Y
    id: zone1_y
    mode: box
    min_value: -500
    max_value: 8000
    device_class: distance
    entity_category: config
    icon: mdi:arrow-up-bold
    unit_of_measurement: mm
    step: 10
    initial_value: 0
    optimistic: True
    restore_value: True
    on_value:
    then:
    - lambda: check_zone_valid(id(zone1_x).state, id(zone1_y).state, id(zone1_width).state, id(zone1_height).state, tips_zone1_conf);
  • platform: template
    name: ${entity_name} Zone1 Height
    id: zone1_height
    icon: mdi:arrow-down-bold
    mode: box
    min_value: 0
    max_value: 8000
    initial_value: 0
    entity_category: config
    device_class: distance
    unit_of_measurement: mm
    step: 10
    optimistic: True
    restore_value: True
    on_value:
    then:
    - lambda: check_zone_valid(id(zone1_x).state, id(zone1_y).state, id(zone1_width).state, id(zone1_height).state, tips_zone1_conf);
  • platform: template
    name: ${entity_name} Zone1 Width
    id: zone1_width
    mode: box
    min_value: 0
    max_value: 8000
    device_class: distance
    unit_of_measurement: mm
    entity_category: config
    icon: mdi:arrow-right-bold
    step: 10
    initial_value: 0
    optimistic: True
    restore_value: True
    on_value:
    then:
    - lambda: check_zone_valid(id(zone1_x).state, id(zone1_y).state, id(zone1_width).state, id(zone1_height).state, tips_zone1_conf);

Zone 2

  • platform: template
    name: ${entity_name} Zone2 X
    id: zone2_x
    min_value: -4000
    max_value: 4000
    mode: box
    device_class: distance
    entity_category: config
    unit_of_measurement: mm
    icon: mdi:arrow-left-bold
    step: 10
    optimistic: True
    initial_value: 0
    restore_value: True
    on_value:
    then:
    - lambda: check_zone_valid(id(zone2_x).state, id(zone2_y).state, id(zone2_width).state, id(zone2_height).state, tips_zone2_conf);
  • platform: template
    name: ${entity_name} Zone2 Y
    id: zone2_y
    mode: box
    min_value: -500
    max_value: 8000
    device_class: distance
    entity_category: config
    icon: mdi:arrow-up-bold
    unit_of_measurement: mm
    step: 10
    initial_value: 0
    optimistic: True
    restore_value: True
    on_value:
    then:
    - lambda: check_zone_valid(id(zone2_x).state, id(zone2_y).state, id(zone2_width).state, id(zone2_height).state, tips_zone2_conf);
  • platform: template
    name: ${entity_name} Zone2 Height
    id: zone2_height
    icon: mdi:arrow-down-bold
    mode: box
    min_value: 0
    max_value: 8000
    initial_value: 0
    entity_category: config
    device_class: distance
    unit_of_measurement: mm
    step: 10
    optimistic: True
    restore_value: True
    on_value:
    then:
    - lambda: check_zone_valid(id(zone2_x).state, id(zone2_y).state, id(zone2_width).state, id(zone2_height).state, tips_zone2_conf);
  • platform: template
    name: ${entity_name} Zone2 Width
    id: zone2_width
    mode: box
    min_value: 0
    max_value: 8000
    device_class: distance
    unit_of_measurement: mm
    entity_category: config
    icon: mdi:arrow-right-bold
    step: 10
    initial_value: 0
    optimistic: True
    restore_value: True
    on_value:
    then:
    - lambda: check_zone_valid(id(zone2_x).state, id(zone2_y).state, id(zone2_width).state, id(zone2_height).state, tips_zone2_conf);

Zone 3

  • platform: template
    name: ${entity_name} Zone3 X
    id: zone3_x
    min_value: -4000
    max_value: 4000
    mode: box
    device_class: distance
    entity_category: config
    unit_of_measurement: mm
    icon: mdi:arrow-left-bold
    step: 10
    optimistic: True
    initial_value: 0
    restore_value: True
    on_value:
    then:
    - lambda: check_zone_valid(id(zone3_x).state, id(zone3_y).state, id(zone3_width).state, id(zone3_height).state, tips_zone3_conf);
  • platform: template
    name: ${entity_name} Zone3 Y
    id: zone3_y
    mode: box
    min_value: -500
    max_value: 8000
    device_class: distance
    entity_category: config
    icon: mdi:arrow-up-bold
    unit_of_measurement: mm
    step: 10
    initial_value: 0
    optimistic: True
    restore_value: True
    on_value:
    then:
    - lambda: check_zone_valid(id(zone3_x).state, id(zone3_y).state, id(zone3_width).state, id(zone3_height).state, tips_zone3_conf);
  • platform: template
    name: ${entity_name} Zone3 Height
    id: zone3_height
    icon: mdi:arrow-down-bold
    mode: box
    min_value: 0
    max_value: 8000
    initial_value: 0
    entity_category: config
    device_class: distance
    unit_of_measurement: mm
    step: 10
    optimistic: True
    restore_value: True
    on_value:
    then:
    - lambda: check_zone_valid(id(zone3_x).state, id(zone3_y).state, id(zone3_width).state, id(zone3_height).state, tips_zone3_conf);
  • platform: template
    name: ${entity_name} Zone3 Width
    id: zone3_width
    mode: box
    min_value: 0
    max_value: 8000
    device_class: distance
    unit_of_measurement: mm
    entity_category: config
    icon: mdi:arrow-right-bold
    step: 10
    initial_value: 0
    optimistic: True
    restore_value: True
    on_value:
    then:
    - lambda: check_zone_valid(id(zone3_x).state, id(zone3_y).state, id(zone3_width).state, id(zone3_height).state, tips_zone3_conf);

Zout1

  • platform: template
    name: ${entity_name} Zout1 X
    id: zone_ex1_x
    min_value: -4000
    max_value: 4000
    mode: box
    device_class: distance
    entity_category: config
    unit_of_measurement: mm
    icon: mdi:arrow-left-bold
    step: 10
    optimistic: True
    initial_value: 0
    restore_value: True
    on_value:
    then:
    - lambda: check_zout_valid(1, tips_zone_ex1_conf);
  • platform: template
    name: ${entity_name} Zout1 Y
    id: zone_ex1_y
    mode: box
    min_value: -500
    max_value: 8000
    device_class: distance
    entity_category: config
    icon: mdi:arrow-up-bold
    unit_of_measurement: mm
    step: 10
    initial_value: 0
    optimistic: True
    restore_value: True
    on_value:
    then:
    - lambda: check_zout_valid(1, tips_zone_ex1_conf);
  • platform: template
    name: ${entity_name} Zout1 Height
    id: zone_ex1_height
    icon: mdi:arrow-down-bold
    mode: box
    min_value: 0
    max_value: 8000
    initial_value: 0
    entity_category: config
    device_class: distance
    unit_of_measurement: mm
    step: 10
    optimistic: True
    restore_value: True
    on_value:
    then:
    - lambda: check_zout_valid(1, tips_zone_ex1_conf);
  • platform: template
    name: ${entity_name} Zout1 Width
    id: zone_ex1_width
    mode: box
    min_value: 0
    max_value: 8000
    device_class: distance
    unit_of_measurement: mm
    entity_category: config
    icon: mdi:arrow-right-bold
    step: 10
    initial_value: 0
    optimistic: True
    restore_value: True
    on_value:
    then:
    - lambda: check_zout_valid(1, tips_zone_ex1_conf);

Zout2

  • platform: template
    name: ${entity_name} Zout2 X
    id: zone_ex2_x
    min_value: -4000
    max_value: 4000
    mode: box
    device_class: distance
    entity_category: config
    unit_of_measurement: mm
    icon: mdi:arrow-left-bold
    step: 10
    optimistic: True
    initial_value: 0
    restore_value: True
    on_value:
    then:
    - lambda: check_zout_valid(2, tips_zone_ex2_conf);
  • platform: template
    name: ${entity_name} Zout2 Y
    id: zone_ex2_y
    mode: box
    min_value: -500
    max_value: 8000
    device_class: distance
    entity_category: config
    icon: mdi:arrow-up-bold
    unit_of_measurement: mm
    step: 10
    initial_value: 0
    optimistic: True
    restore_value: True
    on_value:
    then:
    - lambda: check_zout_valid(2, tips_zone_ex2_conf);
  • platform: template
    name: ${entity_name} Zout2 Height
    id: zone_ex2_height
    icon: mdi:arrow-down-bold
    mode: box
    min_value: 0
    max_value: 8000
    initial_value: 0
    entity_category: config
    device_class: distance
    unit_of_measurement: mm
    step: 10
    optimistic: True
    restore_value: True
    on_value:
    then:
    - lambda: check_zout_valid(2, tips_zone_ex2_conf);
  • platform: template
    name: ${entity_name} Zout2 Width
    id: zone_ex2_width
    mode: box
    min_value: 0
    max_value: 8000
    device_class: distance
    unit_of_measurement: mm
    entity_category: config
    icon: mdi:arrow-right-bold
    step: 10
    initial_value: 0
    optimistic: True
    restore_value: True
    on_value:
    then:
    - lambda: check_zout_valid(2, tips_zone_ex2_conf);

Zout3

  • platform: template
    name: ${entity_name} Zout3 X
    id: zone_ex3_x
    min_value: -4000
    max_value: 4000
    mode: box
    device_class: distance
    entity_category: config
    unit_of_measurement: mm
    icon: mdi:arrow-left-bold
    step: 10
    optimistic: True
    initial_value: 0
    restore_value: True
    on_value:
    then:
    - lambda: check_zout_valid(3, tips_zone_ex3_conf);
  • platform: template
    name: ${entity_name} Zout3 Y
    id: zone_ex3_y
    mode: box
    min_value: -500
    max_value: 8000
    device_class: distance
    entity_category: config
    icon: mdi:arrow-up-bold
    unit_of_measurement: mm
    step: 10
    initial_value: 0
    optimistic: True
    restore_value: True
    on_value:
    then:
    - lambda: check_zout_valid(3, tips_zone_ex3_conf);
  • platform: template
    name: ${entity_name} Zout3 Height
    id: zone_ex3_height
    icon: mdi:arrow-down-bold
    mode: box
    min_value: 0
    max_value: 8000
    initial_value: 0
    entity_category: config
    device_class: distance
    unit_of_measurement: mm
    step: 10
    optimistic: True
    restore_value: True
    on_value:
    then:
    - lambda: check_zout_valid(3, tips_zone_ex3_conf);
  • platform: template
    name: ${entity_name} Zout3 Width
    id: zone_ex3_width
    mode: box
    min_value: 0
    max_value: 8000
    device_class: distance
    unit_of_measurement: mm
    entity_category: config
    icon: mdi:arrow-right-bold
    step: 10
    initial_value: 0
    optimistic: True
    restore_value: True
    on_value:
    then:
    - lambda: check_zout_valid(3, tips_zone_ex3_conf);

binary_sensor:

  • platform: status
    name: ${entity_name} Online
    id: ink_ha_connected
  • platform: template
    name: ${entity_name} Any Presence
    id: any_target_exist
    device_class: occupancy
    filters:
    • delayed_off: !lambda |-
      if (!id(init_zone_publish) || !id(zone_fn_enable).state) {
      return 0;
      };
      return id(any_presence_timeout).state * 1000.0;
  • platform: template
    name: ${entity_name} Zone1 Presence
    id: zone1_target_exist
    device_class: occupancy
    filters:
    • delayed_off: !lambda |-
      if (!id(init_zone_publish) || !id(zone_fn_enable).state) {
      return 0;
      }
      return id(zone1_timeout).state * 1000.0;
  • platform: template
    name: ${entity_name} Zone2 Presence
    id: zone2_target_exist
    device_class: occupancy
    filters:
    • delayed_off: !lambda |-
      if (!id(init_zone_publish) || !id(zone_fn_enable).state) {
      return 0;
      }
      return id(zone2_timeout).state * 1000.0;
  • platform: template
    name: ${entity_name} Zone3 Presence
    id: zone3_target_exist
    device_class: occupancy
    filters:
    • delayed_off: !lambda |-
      if (!id(init_zone_publish) || !id(zone_fn_enable).state) {
      return 0;
      }
      return id(zone3_timeout).state * 1000.0;
  • platform: template
    name: ${entity_name} Zout1 Presence
    id: zone_ex1_target_exist
    icon: mdi:account-multiple-remove
    device_class: occupancy
  • platform: template
    name: ${entity_name} Zout2 Presence
    id: zone_ex2_target_exist
    icon: mdi:account-multiple-remove
    device_class: occupancy
  • platform: template
    name: ${entity_name} Zout3 Presence
    id: zone_ex3_target_exist
    icon: mdi:account-multiple-remove
    device_class: occupancy

sensor:

  • platform: dallas_temp
    address: 0x803cc7f64998bb28
    name: "ceoroom Temp"
    id: ceoroom_Temp

  • platform: uptime
    name: ${entity_name} ESP Uptime
    id: sys_uptime
    update_interval: 60s
    disabled_by_default: True

#-------------------------------------#

Advanced radar data

  • platform: template
    name: ${entity_name} All Target Counts
    id: all_target_count
    accuracy_decimals: 0
    icon: "mdi:counter"
    unit_of_measurement: "targets"
  • platform: template
    name: ${entity_name} Zone1 Target Counts
    id: zone1_target_count
    accuracy_decimals: 0
    icon: "mdi:counter"
    unit_of_measurement: "targets"
  • platform: template
    name: ${entity_name} Zone2 Target Counts
    id: zone2_target_count
    accuracy_decimals: 0
    icon: "mdi:counter"
    unit_of_measurement: "targets"
  • platform: template
    name: ${entity_name} Zone3 Target Counts
    id: zone3_target_count
    accuracy_decimals: 0
    icon: "mdi:counter"
    unit_of_measurement: "targets"
  • platform: template
    name: ${entity_name} Zout1 Target Counts
    id: zone_ex1_target_count
    accuracy_decimals: 0
    icon: mdi:account-multiple-minus-outline
    unit_of_measurement: "targets"
  • platform: template
    name: ${entity_name} Zout2 Target Counts
    id: zone_ex2_target_count
    accuracy_decimals: 0
    icon: mdi:account-multiple-minus-outline
    unit_of_measurement: "targets"
  • platform: template
    name: ${entity_name} Zout3 Target Counts
    id: zone_ex3_target_count
    accuracy_decimals: 0
    icon: mdi:account-multiple-minus-outline
    unit_of_measurement: "targets"

Target 1

  • platform: template
    name: ${entity_name} Target1 X
    id: target1_x
    accuracy_decimals: 0
    unit_of_measurement: 'mm'
    state_class: measurement
    icon: mdi:focus-field-horizontal
    device_class: distance
  • platform: template
    name: ${entity_name} Target1 Y
    id: target1_y
    accuracy_decimals: 0
    unit_of_measurement: 'mm'
    state_class: measurement
    device_class: distance
    icon: mdi:focus-field-vertical
  • platform: template
    name: ${entity_name} Target1 Speed
    id: target1_speed
    accuracy_decimals: 2
    unit_of_measurement: 'm/s'
    state_class: measurement
    device_class: speed
  • platform: template
    name: ${entity_name} Target1 Resolution
    id: target1_resolution
    accuracy_decimals: 0
    unit_of_measurement: 'mm'
    state_class: measurement
    device_class: distance

Target 2

  • platform: template
    name: ${entity_name} Target2 X
    id: target2_x
    accuracy_decimals: 0
    unit_of_measurement: 'mm'
    state_class: measurement
    device_class: distance
    icon: mdi:focus-field-horizontal
  • platform: template
    name: ${entity_name} Target2 Y
    id: target2_y
    accuracy_decimals: 0
    unit_of_measurement: 'mm'
    state_class: measurement
    device_class: distance
    icon: mdi:focus-field-vertical
  • platform: template
    name: ${entity_name} Target2 Speed
    id: target2_speed
    accuracy_decimals: 0
    unit_of_measurement: 'm/s'
    state_class: measurement
    device_class: speed
  • platform: template
    name: ${entity_name} Target2 Resolution
    id: target2_resolution
    accuracy_decimals: 0
    unit_of_measurement: 'mm'
    state_class: measurement
    device_class: distance

Target 3

  • platform: template
    name: ${entity_name} Target3 X
    id: target3_x
    accuracy_decimals: 0
    unit_of_measurement: 'mm'
    state_class: measurement
    device_class: distance
    icon: mdi:focus-field-horizontal
  • platform: template
    name: ${entity_name} Target3 Y
    id: target3_y
    accuracy_decimals: 0
    unit_of_measurement: 'mm'
    state_class: measurement
    device_class: distance
    icon: mdi:focus-field-vertical
  • platform: template
    name: ${entity_name} Target3 Speed
    id: target3_speed
    accuracy_decimals: 0
    unit_of_measurement: 'm/s'
    state_class: measurement
    device_class: speed
  • platform: template
    name: ${entity_name} Target3 Resolution
    id: target3_resolution
    accuracy_decimals: 0
    unit_of_measurement: 'mm'
    state_class: measurement
    device_class: distance
  • platform: template
    name: ${entity_name} Target1 Angle
    id: target1_angle
    unit_of_measurement: 'º'
    accuracy_decimals: 1
    icon: mdi:angle-acute
  • platform: template
    name: ${entity_name} Target2 Angle
    id: target2_angle
    accuracy_decimals: 1
    unit_of_measurement: 'º'
    icon: mdi:angle-acute
  • platform: template
    name: ${entity_name} Target3 Angle
    id: target3_angle
    accuracy_decimals: 1
    unit_of_measurement: 'º'
    icon: mdi:angle-acute

light:

- platform: status_led

name: ${entity_name} sys_status

pin: GPIO13

internal: True

restore_mode: ALWAYS_OFF

- platform: binary

name: ${entity_name} Red Info Light

output: board_info_ed

entity_category: diagnostic

restore_mode: ALWAYS_OFF

disabled_by_default: True

time:

  • platform: sntp
    id: time_now

output:

- platform: gpio

id: board_info_ed

pin: GPIO12

switch:

- platform: factory_reset

name: ${entity_name} Factory Reset

disabled_by_default: True

icon: mdi:heart-broken

entity_category: diagnostic

  • platform: template
    name: ${entity_name} Target Enable
    id: target_fn_enable
    optimistic: True
    icon: mdi:target-variant
    entity_category: config
    restore_mode: RESTORE_DEFAULT_ON
  • platform: template
    name: ${entity_name} Zone Enable
    id: zone_fn_enable
    optimistic: True
    icon: mdi:target-variant
    entity_category: config
    restore_mode: RESTORE_DEFAULT_ON
  • platform: template
    name: ${entity_name} Target must leave Zone1
    id: zone1_must_leave_enable
    optimistic: True
    icon: mdi:account-cancel
    entity_category: config
    restore_mode: RESTORE_DEFAULT_OFF
  • platform: template
    name: ${entity_name} Zout1 Enable
    id: zone_ex1_enable
    optimistic: True
    icon: mdi:account-cancel
    entity_category: config
    restore_mode: RESTORE_DEFAULT_OFF
  • platform: template
    name: ${entity_name} Zout2 Enable
    id: zone_ex2_enable
    optimistic: True
    icon: mdi:account-cancel
    entity_category: config
    restore_mode: RESTORE_DEFAULT_OFF
  • platform: template
    name: ${entity_name} Zout3 Enable
    id: zone_ex3_enable
    optimistic: True
    icon: mdi:account-cancel
    entity_category: config
    restore_mode: RESTORE_DEFAULT_OFF
  • platform: template
    name: ${entity_name} Illuminance Fast-Update
    id: bh1750_fast_update
    optimistic: True
    entity_category: diagnostic
    restore_mode: RESTORE_DEFAULT_OFF
    icon: mdi:run-fast
    disabled_by_default: True

button:

  • platform: restart
    icon: mdi:power-cycle
    name: ${entity_name} ESP Reboot
    entity_category: diagnostic

climate:

  • platform: haier_acyrw02
    sensor_id: ceoroom_Temp # Sensor ID with the current temperature
    pin: 15
    name: "AC Haier"

uart:
id: uart_bus
tx_pin:
number: ${tx_pin_ld2450}
mode:
input: true
pullup: true
rx_pin:
number: ${rx_pin_ld2450}
mode:
input: true
pullup: true
baud_rate: 256000
parity: NONE
stop_bits: 1
data_bits: 8
debug:
direction: BOTH
dummy_receiver: True
after:
delimiter: [0X55, 0XCC]
sequence:
- lambda: |-

      // Tableaux pour stocker les noms des champs
      static template_::TemplateNumber* zone_x[] = {id(zone1_x),id(zone2_x),id(zone3_x)};
      static template_::TemplateNumber* zone_y[] = {id(zone1_y),id(zone2_y),id(zone3_y)};
      static template_::TemplateNumber* zone_height[] = {id(zone1_height),id(zone2_height),id(zone3_height)};
      static template_::TemplateNumber* zone_width[] = {id(zone1_width),id(zone2_width),id(zone3_width)};
      static template_::TemplateSensor* zone_target_count[] = {id(zone1_target_count),id(zone2_target_count),id(zone3_target_count)};
      static template_::TemplateBinarySensor* zone_target_exist[] = {id(zone1_target_exist),id(zone2_target_exist),id(zone3_target_exist)};
      const int NUM_ZONES = 3;
      static template_::TemplateSwitch* zone_must_leave_enable[] = {id(zone1_must_leave_enable)};
      const int NUM_ZONES_MUST_LEAVE = 1;
      static template_::TemplateSwitch* zone_ex_enable[] = {id(zone_ex1_enable),id(zone_ex2_enable),id(zone_ex3_enable)};
      static template_::TemplateNumber* zone_ex_x[] = {id(zone_ex1_x),id(zone_ex2_x),id(zone_ex3_x)};
      static template_::TemplateNumber* zone_ex_y[] = {id(zone_ex1_y),id(zone_ex2_y),id(zone_ex3_y)};
      static template_::TemplateNumber* zone_ex_height[] = {id(zone_ex1_height),id(zone_ex2_height),id(zone_ex3_height)};
      static template_::TemplateNumber* zone_ex_width[] = {id(zone_ex1_width),id(zone_ex2_width),id(zone_ex3_width)};
      static template_::TemplateSensor* zone_ex_target_count[] = {id(zone_ex1_target_count),id(zone_ex2_target_count),id(zone_ex3_target_count)};
      static template_::TemplateBinarySensor* zone_ex_target_exist[] = {id(zone_ex1_target_exist),id(zone_ex2_target_exist),id(zone_ex3_target_exist)};
      const int NUM_ZONES_EX = 3;
      static template_::TemplateSensor* target_angle[] = {id(target1_angle),id(target2_angle),id(target3_angle)};
      static template_::TemplateTextSensor* target_position[] = {id(target1_position),id(target2_position),id(target3_position)};
      static template_::TemplateTextSensor* target_direction[] = {id(target1_direction),id(target2_direction),id(target3_direction)};
      static template_::TemplateSensor* target_x[] = {id(target1_x),id(target2_x),id(target3_x)};
      static template_::TemplateSensor* target_y[] = {id(target1_y),id(target2_y),id(target3_y)};
      static template_::TemplateSensor* target_speed[] = {id(target1_speed),id(target2_speed),id(target3_speed)};
      static template_::TemplateSensor* target_resolution[] = {id(target1_resolution),id(target2_resolution),id(target3_resolution)};
      const int NUM_TARGETS = 3;
      float angle = id(wall_angle).state*1;
      
      struct Position  p[NUM_TARGETS];
      struct Zone zone_ex[NUM_ZONES_EX], zone[NUM_ZONES];
      
      if ((millis() - id(last_update_ld2450)) <= 500) { 
        return;
      };
      id(last_update_ld2450) = millis();

      //Targets' data
      int b = 0;
      for (int i = 0; i < NUM_TARGETS; i++) {
        p[i].x = (uint16_t((bytes[b+5] << 8) | bytes[b+4] ));
        if ((bytes[b+5] & 0x80) >> 7){
          p[i].x -= pow(2, 15); 
        }else{
          p[i].x = 0 - p[i].x;
        }
        p[i].x = p[i].x * -1;

        p[i].y = (uint16_t((bytes[b+7] << 8) | bytes[b+6] ));
        if ((bytes[b+7] & 0x80) >> 7){
          p[i].y -= pow(2, 15);
        }else{
          p[i].y = 0 - p[i].y;
        }

        p[i].speed = (bytes[b+9] << 8 | bytes[b+8] );
        if ((bytes[b+9] & 0x80) >> 7){
          p[i].speed -= pow(2, 15);
        }else{
          p[i].speed = 0 - p[i].speed;
        }
        p[i].distance_resolution = (uint16_t((bytes[b+11] << 8) | bytes[b+10] )); 
        p[i].valide = (p[i].x != 0 || p[i].y > 0);
        b += 8;
      }
      
      // Excluded zones 
      for (int i = 0; i < NUM_ZONES_EX; i++) {
        zone_ex[i].x = zone_ex_x[i]->state;
        zone_ex[i].y = zone_ex_y[i]->state;
        zone_ex[i].width = zone_ex_width[i]->state;
        zone_ex[i].height = zone_ex_height[i]->state;
        //zone_ex[i].tips_conf = tips_zone_ex_conf[i];
        //zone_ex[i].name += "_ex" + std::to_string(i+1);

        if (zone_ex_enable[i]->state){
          for (int j = 0; j < NUM_TARGETS; j++) {
            if (p[j].valide){
              if (check_targets_in_zone(zone_ex[i], p[j], angle)){
                zone_ex[i].target_count++;
                p[j].zone_ex_enter = true;
              } else { 
                zone_ex[i].outside_target_count++;
              }
            }
          }
        }
        zone_ex[i].has_target = (zone_ex[i].target_count > 0);
        zone_ex[i].has_target_outside = (zone_ex[i].outside_target_count > 0);
      }
      
      // all targets
      int16_t all_target_counts = 0;
      for (int i = 0; i < NUM_TARGETS; i++) {
        if (p[i].valide && !p[i].zone_ex_enter){
          all_target_counts ++;
        }
      }

      bool has_target_in_zone_all = (all_target_counts > 0);

      // zones check
      if (id(zone_fn_enable).state){
        for (int i = 0; i < NUM_ZONES; i++) {
          zone[i].x = zone_x[i]->state;
          zone[i].y = zone_y[i]->state;
          zone[i].width = zone_width[i]->state;
          zone[i].height = zone_height[i]->state;
          //zone[i].tips_conf = tips_zone_conf[i];
          //zone[i].name += std::to_string(i+1);
          
          for (int j = 0; j < NUM_TARGETS; j++) {
            if (p[j].valide && !p[j].zone_ex_enter){
              if(check_targets_in_zone(zone[i], p[j], angle)) {
                zone[i].target_count++;
              } else { 
                zone[i].outside_target_count++;
              }
            }
          }
          zone[i].has_target = (zone[i].target_count > 0);
          zone[i].has_target_outside = (zone[i].outside_target_count > 0);
        }
      }

      // Angle, Position and Direction, idea from walberjunior.
      for (int i = 0; i < NUM_TARGETS; i++) {
        if (p[i].valide){
          p[i].angle = ((float)p[i].x / (float)p[i].y) * 180 / M_PI;;
        }
        if (target_angle[i]->state != p[i].angle && id(target_fn_enable).state){
          target_angle[i]->publish_state(p[i].angle);
        }

        if (p[i].speed > 0) {
          p[i].position = "Moving away";
        } else if (p[i].speed < 0) {
          p[i].position = "Approaching";
        } 
        if (p[i].position != target_position[i]->state && id(target_fn_enable).state){
          target_position[i]->publish_state(p[i].position);
        }

        if (p[i].x > 0) {
          p[i].direction = "Right";
        } else if (p[i].x < 0) {
          p[i].direction = "Left";
        } else if (p[i].y > 0){
          p[i].direction = "Middle";
        }
        if (p[i].direction != target_direction[i]->state && id(target_fn_enable).state){
          target_direction[i]->publish_state(p[i].direction);
        }
      }

      // public all info
      for (int i = 0; i < NUM_TARGETS; i++) {
        if (target_x[i]->state != p[i].x && id(target_fn_enable).state){
          target_x[i]->publish_state(p[i].x);
        }
        if (target_y[i]->state != p[i].y && id(target_fn_enable).state){
          target_y[i]->publish_state(p[i].y);
        }

        p[i].speed = float(p[i].speed) / 100.0;
        if (target_speed[i]->state != p[i].speed && id(target_fn_enable).state){
          target_speed[i]->publish_state(p[i].speed);
        }
        if (target_resolution[i]->state != p[i].distance_resolution && id(target_fn_enable).state){
          target_resolution[i]->publish_state(p[i].distance_resolution);
        }
      }

      // publish target and zone info
      if (id(all_target_count).state != all_target_counts){
        id(all_target_count).publish_state(all_target_counts);
        id(any_target_exist).publish_state(has_target_in_zone_all);
      }else if (id(any_target_exist).state != has_target_in_zone_all){
        id(any_target_exist).publish_state(has_target_in_zone_all);
      }

      bool pub;
      for (int i = 0; i < NUM_ZONES; i++) {
        if (zone_target_count[i]->state != zone[i].target_count){
          pub = false;
          if (i >= NUM_ZONES_MUST_LEAVE)
            pub = true;
          else if ((!zone_must_leave_enable[i]->state) || (zone_must_leave_enable[i]->state && (zone[i].has_target || zone[i].has_target_outside))) {
            pub = true;
          }
          if (pub) {
            zone_target_count[i]->publish_state(zone[i].target_count);
            zone_target_exist[i]->publish_state(zone[i].has_target);
          }
        }
      }
      for (int i = 0; i < NUM_ZONES_EX; i++) {
        if (zone_ex_target_count[i]->state != zone_ex[i].target_count){
          zone_ex_target_count[i]->publish_state(zone_ex[i].target_count);
        }
        if (zone_ex_target_exist[i]->state != zone_ex[i].has_target){
          zone_ex_target_exist[i]->publish_state(zone_ex[i].has_target);
        }
      }

      if (!id(init_zone_publish)){
        id(init_zone_publish) = true;
      }
@53l3cu5
Copy link
Owner

53l3cu5 commented Nov 5, 2024

Have you tried with another code like screek's?
https://github.com/screekworkshop/screek-human-sensor/tree/main/2a/yaml
If you have the same problem with another code then chances are the problem is not with the code but with the sensor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants