mirror of
https://github.com/jdillenburg/esphome.git
synced 2026-01-08 22:40:39 -07:00
206 lines
7.0 KiB
YAML
206 lines
7.0 KiB
YAML
#
|
|
# ld1115h as a ESPHome package
|
|
#
|
|
# Parameters:
|
|
# uart_rx_pin - pin the receive line is connected to, e.g., GPIO1
|
|
# uart_tx_pin - pin the transmit line is connected to, e.g., GPIO3
|
|
#
|
|
# packages:
|
|
# ld1115h: !include { file: packages/ld1115h.yaml, vars: { uart_rx_pin: GPIO16, uart_tx_pin: GPIO17 }}
|
|
#
|
|
esphome:
|
|
on_boot: #LD1115H Initial Setting
|
|
priority: -200
|
|
then:
|
|
- uart.write:
|
|
id: LD1115H_UART_BUS
|
|
data: !lambda |-
|
|
std::string th1st = "th1=" + str_sprintf("%.0f",id(LD1115H_TH1).state) +" \n";
|
|
return std::vector<uint8_t>(th1st.begin(), th1st.end());
|
|
- uart.write:
|
|
id: LD1115H_UART_BUS
|
|
data: !lambda |-
|
|
std::string th2st = "th2=" + str_sprintf("%.0f",id(LD1115H_TH2).state) +" \n";
|
|
return std::vector<uint8_t>(th2st.begin(), th2st.end());
|
|
|
|
external_components:
|
|
- source:
|
|
type: git
|
|
url: https://github.com/ssieb/custom_components #Thanks for @ssieb components.
|
|
components: [ serial ]
|
|
|
|
uart:
|
|
id: LD1115H_UART_BUS
|
|
rx_pin: ${uart_rx_pin}
|
|
tx_pin: ${uart_tx_pin}
|
|
baud_rate: 115200
|
|
data_bits: 8
|
|
stop_bits: 1
|
|
parity: NONE
|
|
setup_priority: 200 #Set Priority To Prevent Boot Loop or Fail
|
|
|
|
globals:
|
|
- id: LD1115H_Last_Time
|
|
type: time_t
|
|
restore_value: no
|
|
initial_value: ::time(NULL)
|
|
- id: LD1115H_Last_Mov_Time
|
|
type: time_t
|
|
restore_value: no
|
|
initial_value: ::time(NULL)
|
|
- id: LD1115H_Clearence_Status
|
|
type: bool
|
|
restore_value: no
|
|
initial_value: "false"
|
|
|
|
interval:
|
|
- interval: 1s #Clearance Scan Time
|
|
setup_priority: -200
|
|
then:
|
|
lambda: |-
|
|
if ((::time(NULL)-id(LD1115H_Last_Time))>id(LD1115H_Clear_Time).state) {
|
|
if ((id(LD1115H_Clearence_Status) == false) || (id(LD1115H_Occupancy).state != "Clearance")) {
|
|
id(LD1115H_Occupancy).publish_state("Clearance");
|
|
id(LD1115H_Clearence_Status) = true;
|
|
}
|
|
if (id(LD1115H_MovOcc_Binary).state == true) {
|
|
id(LD1115H_MovOcc_Binary).publish_state(false);
|
|
}
|
|
if (id(LD1115H_Mov_Binary).state == true) {
|
|
id(LD1115H_Mov_Binary).publish_state(false);
|
|
}
|
|
}
|
|
number:
|
|
- platform: template
|
|
name: ${device_name} LD1115H TH1 #TH1 is Movement/Motion Sensitivity
|
|
id: LD1115H_TH1
|
|
icon: "mdi:cogs"
|
|
optimistic: true
|
|
restore_value: true #If you don't want to store the setting at ESP, set it to false.
|
|
initial_value: "120" #Default TH1 Setting
|
|
min_value: 20
|
|
max_value: 1200
|
|
step: 10
|
|
set_action:
|
|
then:
|
|
- uart.write:
|
|
id: LD1115H_UART_BUS
|
|
data: !lambda |-
|
|
std::string th1st = "th1=" + str_sprintf("%.0f",x) +" \n";
|
|
return std::vector<uint8_t>(th1st.begin(), th1st.end());
|
|
- platform: template
|
|
name: ${device_name} LD1115H TH2 #TH2 is Occupancy/Presence Sensitivity
|
|
id: LD1115H_TH2
|
|
icon: "mdi:cogs"
|
|
optimistic: true
|
|
restore_value: true #If you don't want to store the setting at ESP, set it to false.
|
|
initial_value: "250" #Default TH2 Setting
|
|
min_value: 50
|
|
max_value: 2500
|
|
step: 10
|
|
set_action:
|
|
then:
|
|
- uart.write:
|
|
id: LD1115H_UART_BUS
|
|
data: !lambda |-
|
|
std::string th2st = "th2=" + str_sprintf("%.0f",x) +" \n";
|
|
return std::vector<uint8_t>(th2st.begin(), th2st.end());
|
|
- platform: template
|
|
name: ${device_name} LD1115H Clearence Time
|
|
id: LD1115H_Clear_Time
|
|
icon: "mdi:cogs"
|
|
optimistic: true
|
|
restore_value: true #If you don't want to store the setting at ESP, set it to false.
|
|
initial_value: "5" #LD1115H Mov/Occ > Clearence Time Here
|
|
min_value: 0.5
|
|
max_value: 20
|
|
step: 0.5
|
|
- platform: template
|
|
name: ${device_name} LD1115H Movement Time
|
|
id: LD1115H_Mov_Time
|
|
icon: "mdi:cogs"
|
|
optimistic: true
|
|
restore_value: true #If you don't want to store the setting at ESP, set it to false.
|
|
initial_value: "1" #LD1115H Mov > Occ Time Here
|
|
min_value: 0.5
|
|
max_value: 10
|
|
step: 0.5
|
|
|
|
sensor:
|
|
- platform: template
|
|
name: ${device_name} LD1115H Spectral line
|
|
id: LD1115H_Spectral
|
|
icon: "mdi:radar"
|
|
unit_of_measurement: ""
|
|
accuracy_decimals: 0
|
|
- platform: template
|
|
name: ${device_name} LD1115H Signal Strength
|
|
id: LD1115H_Signal
|
|
icon: "mdi:signal-distance-variant"
|
|
unit_of_measurement: ""
|
|
accuracy_decimals: 0
|
|
filters: # Use Fliter To Debounce
|
|
- sliding_window_moving_average:
|
|
window_size: 8
|
|
send_every: 2
|
|
- heartbeat: 2.0s
|
|
|
|
text_sensor:
|
|
- platform: serial
|
|
uart_id: LD1115H_UART_BUS
|
|
name: ${device_name} LD1115H UART Text
|
|
id: LD1115H_UART_Text
|
|
icon: "mdi:format-text"
|
|
internal: True
|
|
on_value:
|
|
lambda: |-
|
|
if (id(LD1115H_UART_Text).state.substr(0,3) == "occ") {
|
|
id(LD1115H_Signal).publish_state(atof(id(LD1115H_UART_Text).state.substr(7).c_str()));
|
|
id(LD1115H_Spectral).publish_state(atof(id(LD1115H_UART_Text).state.substr(5,2).c_str()));
|
|
if ((::time(NULL)-id(LD1115H_Last_Mov_Time))>id(LD1115H_Mov_Time).state) {
|
|
id(LD1115H_Occupancy).publish_state("Occupancy");
|
|
if (id(LD1115H_MovOcc_Binary).state == false) {
|
|
id(LD1115H_MovOcc_Binary).publish_state(true);
|
|
}
|
|
if (id(LD1115H_Mov_Binary).state == true) {
|
|
id(LD1115H_Mov_Binary).publish_state(false);
|
|
}
|
|
}
|
|
if (id(LD1115H_MovOcc_Binary).state == false) {
|
|
id(LD1115H_MovOcc_Binary).publish_state(true);
|
|
}
|
|
id(LD1115H_Last_Time) = ::time(NULL);
|
|
if (id(LD1115H_Clearence_Status) == true) {
|
|
id(LD1115H_Clearence_Status) = false;
|
|
}
|
|
}
|
|
else if (id(LD1115H_UART_Text).state.substr(0,3) == "mov") {
|
|
id(LD1115H_Signal).publish_state(atof(id(LD1115H_UART_Text).state.substr(7).c_str()));
|
|
id(LD1115H_Spectral).publish_state(atof(id(LD1115H_UART_Text).state.substr(5,2).c_str()));
|
|
id(LD1115H_Occupancy).publish_state("Movement");
|
|
if (id(LD1115H_MovOcc_Binary).state == false) {
|
|
id(LD1115H_MovOcc_Binary).publish_state(true);
|
|
}
|
|
if (id(LD1115H_Mov_Binary).state == false) {
|
|
id(LD1115H_Mov_Binary).publish_state(true);
|
|
}
|
|
id(LD1115H_Last_Mov_Time) = ::time(NULL);
|
|
id(LD1115H_Last_Time) = ::time(NULL);
|
|
if (id(LD1115H_Clearence_Status) == true) {
|
|
id(LD1115H_Clearence_Status) = false;
|
|
}
|
|
}
|
|
- platform: template
|
|
name: ${device_name} LD1115H Occupancy Status
|
|
id: LD1115H_Occupancy
|
|
icon: "mdi:motion-sensor"
|
|
|
|
binary_sensor:
|
|
- platform: template
|
|
name: ${device_name} LD1115H Occupancy or Movement
|
|
id: LD1115H_MovOcc_Binary
|
|
device_class: occupancy
|
|
- platform: template
|
|
name: ${device_name} LD1115H Movement
|
|
id: LD1115H_Mov_Binary
|
|
device_class: motion |