Skip to content

Instantly share code, notes, and snippets.

@malinovsku
Created February 2, 2023 21:56
Show Gist options
  • Save malinovsku/9900ddd3634990364c0835dfa3c84564 to your computer and use it in GitHub Desktop.
Save malinovsku/9900ddd3634990364c0835dfa3c84564 to your computer and use it in GitHub Desktop.
substitutions:
device_name: kyxna-occupancy
device_name2: kyxna_occupancy
device_name_wifi: kyxncupancy
esphome:
name: ${device_name}
platform: ESP8266
board: d1_mini
includes:
- ld2410_uart.h
on_boot:
priority: 600
then:
- lambda: |-
auto uart_component = static_cast<LD2410 *>(ld2410);
uart_component->setNumbers(maxMovingDistanceRange, maxStillDistanceRange, noneDuration);
packages:
# device_base: !include config-base.yaml
ota_api_st: !include config-ota-api-new.yaml
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
wifi:
ssid: !secret wiwi_ssid
password: !secret wiwi_pass
fast_connect: on
reboot_timeout: 50min
ap:
ssid: ${device_name_wifi}
password: !secret wiwi_ap_pass
captive_portal:
text_sensor:
- platform: template
name: ${device_name2} uptime esp
id: uptime_esp
icon: mdi:clock-start
entity_category: diagnostic
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
logger:
baud_rate: 0
logs:
sensor: INFO # DEBUG level with uart_target_output = overload!
binary_sensor: INFO
text_sensor: INFO
uart_debug: INFO
web_server:
port: 80
version: 2
include_internal: true
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: status
name: ${device_name2} status esp
entity_category: diagnostic
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 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: wifi_signal
name: ${device_name2} wifi signal esp
update_interval: 60s
entity_category: diagnostic
- platform: uptime
id: uptime_sensor
update_interval: 60s
on_raw_value:
then:
- text_sensor.template.publish:
id: uptime_esp
state: !lambda |-
int seconds = round(id(uptime_sensor).raw_state);
int days = seconds / (24 * 3600);
seconds = seconds % (24 * 3600);
int hours = seconds / 3600;
seconds = seconds % 3600;
int minutes = seconds / 60;
seconds = seconds % 60;
return (
(days ? String(days) + "d " : "") +
(hours ? String(hours) + "h " : "") +
(String(minutes) + "m")
).c_str();
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 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: restart
name: ${device_name2} restart esp
entity_category: diagnostic
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 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);'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment