mirror of
https://github.com/esphome/esphome.git
synced 2024-11-30 10:44:13 +01:00
fix(mr60fda2): fall detected sensor
This commit is contained in:
parent
9ee0fabc99
commit
adb9207488
5 changed files with 13 additions and 40 deletions
|
@ -8,14 +8,14 @@ from . import CONF_MR60FDA2_ID, MR60FDA2Component
|
||||||
DEPENDENCIES = ["seeed_mr60fda2"]
|
DEPENDENCIES = ["seeed_mr60fda2"]
|
||||||
|
|
||||||
CONF_PEOPLE_EXIST = "people_exist"
|
CONF_PEOPLE_EXIST = "people_exist"
|
||||||
CONF_IS_FALL = "is_fall"
|
CONF_FALL_DETECTED = "fall_detected"
|
||||||
|
|
||||||
CONFIG_SCHEMA = {
|
CONFIG_SCHEMA = {
|
||||||
cv.GenerateID(CONF_MR60FDA2_ID): cv.use_id(MR60FDA2Component),
|
cv.GenerateID(CONF_MR60FDA2_ID): cv.use_id(MR60FDA2Component),
|
||||||
cv.Optional(CONF_PEOPLE_EXIST): binary_sensor.binary_sensor_schema(
|
cv.Optional(CONF_PEOPLE_EXIST): binary_sensor.binary_sensor_schema(
|
||||||
device_class=DEVICE_CLASS_OCCUPANCY, icon="mdi:motion-sensor"
|
device_class=DEVICE_CLASS_OCCUPANCY, icon="mdi:motion-sensor"
|
||||||
),
|
),
|
||||||
cv.Optional(CONF_IS_FALL): binary_sensor.binary_sensor_schema(
|
cv.Optional(CONF_FALL_DETECTED): binary_sensor.binary_sensor_schema(
|
||||||
device_class=DEVICE_CLASS_SAFETY, icon="mdi:emergency"
|
device_class=DEVICE_CLASS_SAFETY, icon="mdi:emergency"
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,6 @@ async def to_code(config):
|
||||||
sens = await binary_sensor.new_binary_sensor(people_exist_config)
|
sens = await binary_sensor.new_binary_sensor(people_exist_config)
|
||||||
cg.add(mr60fda2_component.set_people_exist_binary_sensor(sens))
|
cg.add(mr60fda2_component.set_people_exist_binary_sensor(sens))
|
||||||
|
|
||||||
if is_fall_config := config.get(CONF_IS_FALL):
|
if is_fall_config := config.get(CONF_FALL_DETECTED):
|
||||||
sens = await binary_sensor.new_binary_sensor(is_fall_config)
|
sens = await binary_sensor.new_binary_sensor(is_fall_config)
|
||||||
cg.add(mr60fda2_component.set_is_fall_binary_sensor(sens))
|
cg.add(mr60fda2_component.set_is_fall_binary_sensor(sens))
|
||||||
|
|
|
@ -14,7 +14,7 @@ void MR60FDA2Component::dump_config() {
|
||||||
ESP_LOGCONFIG(TAG, "MR60FDA2:");
|
ESP_LOGCONFIG(TAG, "MR60FDA2:");
|
||||||
#ifdef USE_BINARY_SENSOR
|
#ifdef USE_BINARY_SENSOR
|
||||||
LOG_BINARY_SENSOR(" ", "People Exist Binary Sensor", this->people_exist_binary_sensor_);
|
LOG_BINARY_SENSOR(" ", "People Exist Binary Sensor", this->people_exist_binary_sensor_);
|
||||||
LOG_BINARY_SENSOR(" ", "Is Fall Binary Sensor", this->is_fall_binary_sensor_);
|
LOG_BINARY_SENSOR(" ", "Is Fall Binary Sensor", this->fall_detected_binary_sensor_);
|
||||||
#endif
|
#endif
|
||||||
#ifdef USE_BUTTON
|
#ifdef USE_BUTTON
|
||||||
LOG_BUTTON(" ", "Get Radar Parameters Button", this->get_radar_parameters_button_);
|
LOG_BUTTON(" ", "Get Radar Parameters Button", this->get_radar_parameters_button_);
|
||||||
|
@ -225,8 +225,8 @@ void MR60FDA2Component::split_frame_(uint8_t buffer) {
|
||||||
void MR60FDA2Component::process_frame_() {
|
void MR60FDA2Component::process_frame_() {
|
||||||
switch (this->current_frame_type_) {
|
switch (this->current_frame_type_) {
|
||||||
case IS_FALL_TYPE_BUFFER:
|
case IS_FALL_TYPE_BUFFER:
|
||||||
if (this->is_fall_binary_sensor_ != nullptr) {
|
if (this->fall_detected_binary_sensor_ != nullptr) {
|
||||||
this->is_fall_binary_sensor_->publish_state(this->current_frame_buf_[LEN_TO_HEAD_CKSUM]);
|
this->fall_detected_binary_sensor_->publish_state(this->current_frame_buf_[LEN_TO_HEAD_CKSUM]);
|
||||||
}
|
}
|
||||||
this->current_frame_locate_ = LOCATE_FRAME_HEADER;
|
this->current_frame_locate_ = LOCATE_FRAME_HEADER;
|
||||||
break;
|
break;
|
||||||
|
@ -279,17 +279,17 @@ void MR60FDA2Component::process_frame_() {
|
||||||
float install_height_float;
|
float install_height_float;
|
||||||
memcpy(&install_height_float, ¤t_install_height_int_, sizeof(float));
|
memcpy(&install_height_float, ¤t_install_height_int_, sizeof(float));
|
||||||
select_index_ = find_nearest_index_(install_height_float, INSTALL_HEIGHT, 7);
|
select_index_ = find_nearest_index_(install_height_float, INSTALL_HEIGHT, 7);
|
||||||
this->install_height_select_->publish_state(this->install_height_select_.at(select_index_));
|
this->install_height_select_->publish_state(this->install_height_select_->at(select_index_).value());
|
||||||
this->current_height_threshold_int_ =
|
this->current_height_threshold_int_ =
|
||||||
encode_uint32(current_data_buf_[7], current_data_buf_[6], current_data_buf_[5], current_data_buf_[4]);
|
encode_uint32(current_data_buf_[7], current_data_buf_[6], current_data_buf_[5], current_data_buf_[4]);
|
||||||
float height_threshold_float;
|
float height_threshold_float;
|
||||||
memcpy(&height_threshold_float, ¤t_height_threshold_int_, sizeof(float));
|
memcpy(&height_threshold_float, ¤t_height_threshold_int_, sizeof(float));
|
||||||
select_index_ = find_nearest_index_(height_threshold_float, HEIGHT_THRESHOLD, 7);
|
select_index_ = find_nearest_index_(height_threshold_float, HEIGHT_THRESHOLD, 7);
|
||||||
this->height_threshold_select_->publish_state(this->height_threshold_select_.at(select_index_));
|
this->height_threshold_select_->publish_state(this->height_threshold_select_->at(select_index_).value());
|
||||||
this->current_sensitivity_ =
|
this->current_sensitivity_ =
|
||||||
encode_uint32(current_data_buf_[11], current_data_buf_[10], current_data_buf_[9], current_data_buf_[8]);
|
encode_uint32(current_data_buf_[11], current_data_buf_[10], current_data_buf_[9], current_data_buf_[8]);
|
||||||
select_index_ = find_nearest_index_(this->current_sensitivity_, SENSITIVITY, 3);
|
select_index_ = find_nearest_index_(this->current_sensitivity_, SENSITIVITY, 3);
|
||||||
this->sensitivity_select_->publish_state(this->sensitivity_select_.at(select_index_));
|
this->sensitivity_select_->publish_state(this->sensitivity_select_->at(select_index_).value());
|
||||||
ESP_LOGD(TAG, "Mounting height: %.2f, Height threshold: %.2f, Sensitivity: %u", install_height_float,
|
ESP_LOGD(TAG, "Mounting height: %.2f, Height threshold: %.2f, Sensitivity: %u", install_height_float,
|
||||||
height_threshold_float, this->current_sensitivity_);
|
height_threshold_float, this->current_sensitivity_);
|
||||||
this->current_frame_locate_ = LOCATE_FRAME_HEADER;
|
this->current_frame_locate_ = LOCATE_FRAME_HEADER;
|
||||||
|
|
|
@ -61,7 +61,7 @@ class MR60FDA2Component : public Component,
|
||||||
public uart::UARTDevice { // The class name must be the name defined by text_sensor.py
|
public uart::UARTDevice { // The class name must be the name defined by text_sensor.py
|
||||||
#ifdef USE_BINARY_SENSOR
|
#ifdef USE_BINARY_SENSOR
|
||||||
SUB_BINARY_SENSOR(people_exist)
|
SUB_BINARY_SENSOR(people_exist)
|
||||||
SUB_BINARY_SENSOR(is_fall)
|
SUB_BINARY_SENSOR(fall_detected)
|
||||||
#endif
|
#endif
|
||||||
#ifdef USE_BUTTON
|
#ifdef USE_BUTTON
|
||||||
SUB_BUTTON(get_radar_parameters)
|
SUB_BUTTON(get_radar_parameters)
|
||||||
|
|
|
@ -1,24 +0,0 @@
|
||||||
import esphome.codegen as cg
|
|
||||||
from esphome.components import text_sensor
|
|
||||||
import esphome.config_validation as cv
|
|
||||||
from esphome.const import ENTITY_CATEGORY_DIAGNOSTIC
|
|
||||||
|
|
||||||
from . import CONF_MR60FDA2_ID, MR60FDA2Component
|
|
||||||
|
|
||||||
DEPENDENCIES = ["seeed_mr60fda2"]
|
|
||||||
|
|
||||||
CONF_IS_FALL = "is_fall"
|
|
||||||
|
|
||||||
CONFIG_SCHEMA = {
|
|
||||||
cv.GenerateID(CONF_MR60FDA2_ID): cv.use_id(MR60FDA2Component),
|
|
||||||
cv.Optional(CONF_IS_FALL): text_sensor.text_sensor_schema(
|
|
||||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC, icon="mdi:walk"
|
|
||||||
),
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
async def to_code(config):
|
|
||||||
mr60fda2_component = await cg.get_variable(config[CONF_MR60FDA2_ID])
|
|
||||||
if is_fall_config := config.get(CONF_IS_FALL):
|
|
||||||
sens = await text_sensor.new_text_sensor(is_fall_config)
|
|
||||||
cg.add(mr60fda2_component.set_is_fall_text_sensor(sens))
|
|
|
@ -10,15 +10,12 @@ seeed_mr60fda2:
|
||||||
id: my_seeed_mr60fda2
|
id: my_seeed_mr60fda2
|
||||||
uart_id: seeed_mr60fda2_uart
|
uart_id: seeed_mr60fda2_uart
|
||||||
|
|
||||||
text_sensor:
|
|
||||||
- platform: seeed_mr60fda2
|
|
||||||
is_fall:
|
|
||||||
name: "Falling Information"
|
|
||||||
|
|
||||||
binary_sensor:
|
binary_sensor:
|
||||||
- platform: seeed_mr60fda2
|
- platform: seeed_mr60fda2
|
||||||
people_exist:
|
people_exist:
|
||||||
name: "Person Information"
|
name: "Person Information"
|
||||||
|
fall_detected:
|
||||||
|
name: "Falling Information"
|
||||||
|
|
||||||
button:
|
button:
|
||||||
- platform: seeed_mr60fda2
|
- platform: seeed_mr60fda2
|
||||||
|
|
Loading…
Reference in a new issue