354 lines
8.4 KiB
YAML
354 lines
8.4 KiB
YAML
# This is a custom firmware for Human Presence Sensor 2A
|
|
# https://screek.io/2a
|
|
|
|
esphome:
|
|
name: screek-humen-sensor-2a
|
|
comment: Screek Human Sensor 2A
|
|
friendly_name: Human Sensor 2A
|
|
name_add_mac_suffix: True
|
|
platformio_options:
|
|
board_build.flash_mode: dio
|
|
project:
|
|
name: Screek.Human_Presence_Sensor
|
|
version: 2A
|
|
on_boot:
|
|
- priority: 900
|
|
then:
|
|
lambda: |-
|
|
id(cpu_speed) = ESP.getCpuFreqMHz();
|
|
|
|
external_components:
|
|
- source:
|
|
type: git
|
|
url: https://github.com/screekworkshop/custom_components_support_for_screek_2a
|
|
ref: main
|
|
components: [esp32, uart]
|
|
|
|
esp32:
|
|
board: lolin_c3_mini
|
|
framework:
|
|
type: arduino
|
|
version: 2.0.9
|
|
platform_version: 6.3.0
|
|
|
|
globals:
|
|
- id: cpu_speed
|
|
type: int
|
|
restore_value: no
|
|
initial_value: '0'
|
|
- id: last_update_ld2450
|
|
type: unsigned long
|
|
restore_value: no
|
|
initial_value: '0'
|
|
|
|
improv_serial:
|
|
|
|
# Enable logging
|
|
logger:
|
|
# level: VERY_VERBOSE
|
|
|
|
debug:
|
|
update_interval: 30s
|
|
|
|
text_sensor:
|
|
- platform: debug
|
|
reset_reason:
|
|
name: "Reset Reason"
|
|
disabled_by_default: True
|
|
- platform: wifi_info
|
|
mac_address:
|
|
name: ESP MAC
|
|
entity_category: "diagnostic"
|
|
disabled_by_default: True
|
|
|
|
api:
|
|
|
|
ota:
|
|
password: "all-things-in-their-being-are-good-for-something" # words by Socrates
|
|
safe_mode: False
|
|
|
|
wifi:
|
|
power_save_mode: NONE
|
|
reboot_timeout: 10min
|
|
ap:
|
|
ssid: "HUMAN-SENSOR 2A"
|
|
|
|
captive_portal:
|
|
|
|
web_server:
|
|
port: 80
|
|
|
|
binary_sensor:
|
|
- platform: status
|
|
name: Online
|
|
id: ink_ha_connected
|
|
|
|
i2c:
|
|
sda: GPIO7
|
|
scl: GPIO11
|
|
scan: true
|
|
id: bus_a
|
|
|
|
sensor:
|
|
- platform: template
|
|
name: "ESP CPU Speed"
|
|
accuracy_decimals: 0
|
|
unit_of_measurement: Mhz
|
|
lambda: |-
|
|
return (id(cpu_speed));
|
|
entity_category: "diagnostic"
|
|
update_interval: 600s
|
|
- platform: template
|
|
id: sys_esp_temperature
|
|
name: ESP Temperature
|
|
lambda: return temperatureRead();
|
|
unit_of_measurement: °C
|
|
device_class: TEMPERATURE
|
|
update_interval: 45s
|
|
entity_category: "diagnostic"
|
|
- platform: uptime
|
|
name: Uptime
|
|
id: sys_uptime
|
|
update_interval: 60s
|
|
- platform: wifi_signal
|
|
name: RSSI
|
|
id: wifi_signal_db
|
|
update_interval: 60s
|
|
entity_category: "diagnostic"
|
|
- platform: template
|
|
id: esp_memory
|
|
icon: mdi:memory
|
|
name: ESP Free Memory
|
|
lambda: return heap_caps_get_free_size(MALLOC_CAP_INTERNAL) / 1024;
|
|
unit_of_measurement: 'kB'
|
|
state_class: measurement
|
|
entity_category: "diagnostic"
|
|
update_interval: 60s
|
|
- platform: bh1750
|
|
name: "Illuminance"
|
|
update_interval: 1s
|
|
- platform: template
|
|
name: "Target1 X"
|
|
id: target1_x
|
|
accuracy_decimals: 0
|
|
unit_of_measurement: 'mm'
|
|
state_class: measurement
|
|
device_class: distance
|
|
- platform: template
|
|
name: "Target1 Y"
|
|
id: target1_y
|
|
accuracy_decimals: 0
|
|
unit_of_measurement: 'mm'
|
|
state_class: measurement
|
|
device_class: distance
|
|
- platform: template
|
|
name: "Target1 Speed"
|
|
id: target1_speed
|
|
accuracy_decimals: 0
|
|
unit_of_measurement: 'm/s'
|
|
state_class: measurement
|
|
device_class: speed
|
|
- platform: template
|
|
name: "Target1 Resolution"
|
|
id: target1_resolution
|
|
accuracy_decimals: 0
|
|
unit_of_measurement: 'mm'
|
|
state_class: measurement
|
|
device_class: distance
|
|
- platform: template
|
|
name: "Target2 X"
|
|
id: target2_x
|
|
accuracy_decimals: 0
|
|
unit_of_measurement: 'mm'
|
|
state_class: measurement
|
|
device_class: distance
|
|
- platform: template
|
|
name: "Target2 Y"
|
|
id: target2_y
|
|
accuracy_decimals: 0
|
|
unit_of_measurement: 'mm'
|
|
state_class: measurement
|
|
device_class: distance
|
|
- platform: template
|
|
name: "Target2 Speed"
|
|
id: target2_speed
|
|
accuracy_decimals: 0
|
|
unit_of_measurement: 'm/s'
|
|
state_class: measurement
|
|
device_class: speed
|
|
- platform: template
|
|
name: "Target2 Resolution"
|
|
id: target2_resolution
|
|
accuracy_decimals: 0
|
|
unit_of_measurement: 'mm'
|
|
state_class: measurement
|
|
device_class: distance
|
|
- platform: template
|
|
name: "Target3 X"
|
|
id: target3_x
|
|
accuracy_decimals: 0
|
|
unit_of_measurement: 'mm'
|
|
state_class: measurement
|
|
device_class: distance
|
|
- platform: template
|
|
name: "Target3 Y"
|
|
id: target3_y
|
|
accuracy_decimals: 0
|
|
unit_of_measurement: 'mm'
|
|
state_class: measurement
|
|
device_class: distance
|
|
- platform: template
|
|
name: "Target3 Speed"
|
|
id: target3_speed
|
|
accuracy_decimals: 0
|
|
unit_of_measurement: 'm/s'
|
|
state_class: measurement
|
|
device_class: speed
|
|
- platform: template
|
|
name: "Target3 Resolution"
|
|
id: target3_resolution
|
|
accuracy_decimals: 0
|
|
unit_of_measurement: 'mm'
|
|
state_class: measurement
|
|
device_class: distance
|
|
|
|
light:
|
|
- platform: status_led
|
|
name: sys_status
|
|
pin: GPIO13
|
|
internal: True
|
|
restore_mode: ALWAYS_OFF
|
|
- platform: binary
|
|
name: "Red Info Light"
|
|
output: board_info_ed
|
|
entity_category: "config"
|
|
restore_mode: ALWAYS_OFF
|
|
|
|
time:
|
|
- platform: sntp
|
|
id: time_now
|
|
|
|
output:
|
|
- platform: gpio
|
|
id: board_info_ed
|
|
pin: GPIO12
|
|
|
|
uart:
|
|
id: uart_bus
|
|
tx_pin:
|
|
number: GPIO5
|
|
mode:
|
|
input: true
|
|
pullup: true
|
|
rx_pin:
|
|
number: GPIO4
|
|
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: UARTDebug::log_hex(direction, bytes, ' ');
|
|
- lambda: |-
|
|
if ((millis() - id(last_update_ld2450)) <= 1000) {
|
|
return;
|
|
};
|
|
id(last_update_ld2450) = millis();
|
|
|
|
int16_t p1_x = (uint16_t((bytes[5] << 8) | bytes[4] ));
|
|
if ((bytes[5] & 0x80) >> 7){
|
|
p1_x -= pow(2, 15);
|
|
}else{
|
|
p1_x = 0 - p1_x;
|
|
}
|
|
|
|
int16_t p1_y = (uint16_t((bytes[7] << 8) | bytes[6] ));
|
|
if ((bytes[7] & 0x80) >> 7){
|
|
p1_y -= pow(2, 15);
|
|
}else{
|
|
p1_y = 0 - p1_y;
|
|
}
|
|
|
|
int p1_speed = (bytes[9] << 8 | bytes[8] );
|
|
if ((bytes[9] & 0x80) >> 7){
|
|
p1_speed -= pow(2, 15);
|
|
}else{
|
|
p1_speed = 0 - p1_speed;
|
|
}
|
|
int16_t p1_distance_resolution = (uint16_t((bytes[11] << 8) | bytes[10] ));
|
|
|
|
int16_t p2_x = (uint16_t((bytes[13] << 8) | bytes[12] ));
|
|
if ((bytes[13] & 0x80) >> 7){
|
|
p2_x -= pow(2, 15);
|
|
}else{
|
|
p2_x = 0 - p2_x;
|
|
}
|
|
|
|
int16_t p2_y = (uint16_t((bytes[15] << 8) | bytes[14] ));
|
|
if ((bytes[15] & 0x80) >> 7){
|
|
p2_y -= pow(2, 15);
|
|
}else{
|
|
p2_y = 0 - p2_y;
|
|
}
|
|
|
|
int p2_speed = (bytes[17] << 8 | bytes[16] );
|
|
if ((bytes[17] & 0x80) >> 7){
|
|
p2_speed -= pow(2, 15);
|
|
}else{
|
|
p2_speed = 0 - p2_speed;
|
|
}
|
|
int16_t p2_distance_resolution = (uint16_t((bytes[19] << 8) | bytes[18] ));
|
|
|
|
int16_t p3_x = (uint16_t((bytes[21] << 8) | bytes[20] ));
|
|
if ((bytes[21] & 0x80) >> 7){
|
|
p3_x -= pow(2, 15);
|
|
}else{
|
|
p3_x = 0 - p3_x;
|
|
}
|
|
|
|
int16_t p3_y = (uint16_t((bytes[23] << 8) | bytes[22] ));
|
|
if ((bytes[23] & 0x80) >> 7){
|
|
p3_y -= pow(2, 15);
|
|
}else{
|
|
p3_y = 0 - p3_y;
|
|
}
|
|
|
|
int p3_speed = (bytes[25] << 8 | bytes[24] );
|
|
if ((bytes[25] & 0x80) >> 7){
|
|
p3_speed -= pow(2, 15);
|
|
}else{
|
|
p3_speed = 0 - p3_speed;
|
|
}
|
|
int16_t p3_distance_resolution = (uint16_t((bytes[27] << 8) | bytes[26] ));
|
|
|
|
id(target1_x).publish_state(p1_x);
|
|
id(target1_y).publish_state(p1_y);
|
|
id(target1_speed).publish_state(p1_speed);
|
|
id(target1_resolution).publish_state(p1_distance_resolution);
|
|
|
|
id(target2_x).publish_state(p2_x);
|
|
id(target2_y).publish_state(p2_y);
|
|
id(target2_speed).publish_state(p2_speed);
|
|
id(target2_resolution).publish_state(p2_distance_resolution);
|
|
|
|
id(target3_x).publish_state(p3_x);
|
|
id(target3_y).publish_state(p3_y);
|
|
id(target3_speed).publish_state(p3_speed);
|
|
id(target3_resolution).publish_state(p3_distance_resolution);
|
|
|
|
button:
|
|
- platform: restart
|
|
icon: mdi:power-cycle
|
|
name: "ESP Reboot"
|
|
- platform: factory_reset
|
|
disabled_by_default: True
|
|
name: Factory Reset
|
|
id: factory_reset_all
|