mirror of
https://github.com/esphome/esphome.git
synced 2026-10-02 14:22:58 +08:00
Add: Seeed Studio mr60fda2 mmwave sensor (#7576)
Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com> Co-authored-by: Spencer Yan <spencer@spenyan.com>
This commit is contained in:
co-authored by
Jesse Hills
Spencer Yan
parent
d9d368d38e
commit
c0dcecc465
@@ -354,6 +354,7 @@ esphome/components/sdl/* @clydebarrow
|
||||
esphome/components/sdm_meter/* @jesserockz @polyfaces
|
||||
esphome/components/sdp3x/* @Azimath
|
||||
esphome/components/seeed_mr24hpc1/* @limengdu
|
||||
esphome/components/seeed_mr60fda2/* @limengdu
|
||||
esphome/components/selec_meter/* @sourabhjaiswal
|
||||
esphome/components/select/* @esphome/core
|
||||
esphome/components/sen0321/* @notjj
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
import esphome.codegen as cg
|
||||
from esphome.components import uart
|
||||
import esphome.config_validation as cv
|
||||
from esphome.const import CONF_ID
|
||||
|
||||
CODEOWNERS = ["@limengdu"]
|
||||
DEPENDENCIES = ["uart"]
|
||||
MULTI_CONF = True
|
||||
|
||||
mr60fda2_ns = cg.esphome_ns.namespace("seeed_mr60fda2")
|
||||
|
||||
MR60FDA2Component = mr60fda2_ns.class_(
|
||||
"MR60FDA2Component", cg.Component, uart.UARTDevice
|
||||
)
|
||||
|
||||
CONF_MR60FDA2_ID = "mr60fda2_id"
|
||||
|
||||
CONFIG_SCHEMA = (
|
||||
cv.Schema(
|
||||
{
|
||||
cv.GenerateID(): cv.declare_id(MR60FDA2Component),
|
||||
}
|
||||
)
|
||||
.extend(uart.UART_DEVICE_SCHEMA)
|
||||
.extend(cv.COMPONENT_SCHEMA)
|
||||
)
|
||||
|
||||
FINAL_VALIDATE_SCHEMA = uart.final_validate_device_schema(
|
||||
"seeed_mr60fda2",
|
||||
require_tx=True,
|
||||
require_rx=True,
|
||||
baud_rate=115200,
|
||||
parity="NONE",
|
||||
stop_bits=1,
|
||||
)
|
||||
|
||||
|
||||
async def to_code(config):
|
||||
var = cg.new_Pvariable(config[CONF_ID])
|
||||
await cg.register_component(var, config)
|
||||
await uart.register_uart_device(var, config)
|
||||
@@ -0,0 +1,33 @@
|
||||
import esphome.codegen as cg
|
||||
from esphome.components import binary_sensor
|
||||
import esphome.config_validation as cv
|
||||
from esphome.const import DEVICE_CLASS_OCCUPANCY, DEVICE_CLASS_SAFETY
|
||||
|
||||
from . import CONF_MR60FDA2_ID, MR60FDA2Component
|
||||
|
||||
DEPENDENCIES = ["seeed_mr60fda2"]
|
||||
|
||||
CONF_PEOPLE_EXIST = "people_exist"
|
||||
CONF_FALL_DETECTED = "fall_detected"
|
||||
|
||||
CONFIG_SCHEMA = {
|
||||
cv.GenerateID(CONF_MR60FDA2_ID): cv.use_id(MR60FDA2Component),
|
||||
cv.Optional(CONF_PEOPLE_EXIST): binary_sensor.binary_sensor_schema(
|
||||
device_class=DEVICE_CLASS_OCCUPANCY, icon="mdi:motion-sensor"
|
||||
),
|
||||
cv.Optional(CONF_FALL_DETECTED): binary_sensor.binary_sensor_schema(
|
||||
device_class=DEVICE_CLASS_SAFETY, icon="mdi:emergency"
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
async def to_code(config):
|
||||
mr60fda2_component = await cg.get_variable(config[CONF_MR60FDA2_ID])
|
||||
|
||||
if people_exist_config := config.get(CONF_PEOPLE_EXIST):
|
||||
sens = await binary_sensor.new_binary_sensor(people_exist_config)
|
||||
cg.add(mr60fda2_component.set_people_exist_binary_sensor(sens))
|
||||
|
||||
if is_fall_config := config.get(CONF_FALL_DETECTED):
|
||||
sens = await binary_sensor.new_binary_sensor(is_fall_config)
|
||||
cg.add(mr60fda2_component.set_fall_detected_binary_sensor(sens))
|
||||
@@ -0,0 +1,45 @@
|
||||
import esphome.codegen as cg
|
||||
from esphome.components import button
|
||||
import esphome.config_validation as cv
|
||||
from esphome.const import (
|
||||
DEVICE_CLASS_RESTART,
|
||||
DEVICE_CLASS_UPDATE,
|
||||
ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
ENTITY_CATEGORY_NONE,
|
||||
CONF_FACTORY_RESET,
|
||||
)
|
||||
|
||||
from .. import CONF_MR60FDA2_ID, MR60FDA2Component, mr60fda2_ns
|
||||
|
||||
DEPENDENCIES = ["seeed_mr60fda2"]
|
||||
|
||||
GetRadarParametersButton = mr60fda2_ns.class_("GetRadarParametersButton", button.Button)
|
||||
ResetRadarButton = mr60fda2_ns.class_("ResetRadarButton", button.Button)
|
||||
|
||||
CONF_GET_RADAR_PARAMETERS = "get_radar_parameters"
|
||||
|
||||
CONFIG_SCHEMA = {
|
||||
cv.GenerateID(CONF_MR60FDA2_ID): cv.use_id(MR60FDA2Component),
|
||||
cv.Optional(CONF_GET_RADAR_PARAMETERS): button.button_schema(
|
||||
GetRadarParametersButton,
|
||||
device_class=DEVICE_CLASS_UPDATE,
|
||||
entity_category=ENTITY_CATEGORY_NONE,
|
||||
),
|
||||
cv.Optional(CONF_FACTORY_RESET): button.button_schema(
|
||||
ResetRadarButton,
|
||||
device_class=DEVICE_CLASS_RESTART,
|
||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
async def to_code(config):
|
||||
mr60fda2_component = await cg.get_variable(config[CONF_MR60FDA2_ID])
|
||||
if get_radar_parameters_config := config.get(CONF_GET_RADAR_PARAMETERS):
|
||||
b = await button.new_button(get_radar_parameters_config)
|
||||
await cg.register_parented(b, config[CONF_MR60FDA2_ID])
|
||||
cg.add(mr60fda2_component.set_get_radar_parameters_button(b))
|
||||
if factory_reset_config := config.get(CONF_FACTORY_RESET):
|
||||
b = await button.new_button(factory_reset_config)
|
||||
await cg.register_parented(b, config[CONF_MR60FDA2_ID])
|
||||
cg.add(mr60fda2_component.set_factory_reset_button(b))
|
||||
@@ -0,0 +1,9 @@
|
||||
#include "get_radar_parameters_button.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace seeed_mr60fda2 {
|
||||
|
||||
void GetRadarParametersButton::press_action() { this->parent_->get_radar_parameters(); }
|
||||
|
||||
} // namespace seeed_mr60fda2
|
||||
} // namespace esphome
|
||||
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/components/button/button.h"
|
||||
#include "../seeed_mr60fda2.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace seeed_mr60fda2 {
|
||||
|
||||
class GetRadarParametersButton : public button::Button, public Parented<MR60FDA2Component> {
|
||||
public:
|
||||
GetRadarParametersButton() = default;
|
||||
|
||||
protected:
|
||||
void press_action() override;
|
||||
};
|
||||
|
||||
} // namespace seeed_mr60fda2
|
||||
} // namespace esphome
|
||||
@@ -0,0 +1,9 @@
|
||||
#include "reset_radar_button.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace seeed_mr60fda2 {
|
||||
|
||||
void ResetRadarButton::press_action() { this->parent_->factory_reset(); }
|
||||
|
||||
} // namespace seeed_mr60fda2
|
||||
} // namespace esphome
|
||||
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/components/button/button.h"
|
||||
#include "../seeed_mr60fda2.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace seeed_mr60fda2 {
|
||||
|
||||
class ResetRadarButton : public button::Button, public Parented<MR60FDA2Component> {
|
||||
public:
|
||||
ResetRadarButton() = default;
|
||||
|
||||
protected:
|
||||
void press_action() override;
|
||||
};
|
||||
|
||||
} // namespace seeed_mr60fda2
|
||||
} // namespace esphome
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,101 @@
|
||||
#pragma once
|
||||
#include "esphome/core/component.h"
|
||||
#include "esphome/core/defines.h"
|
||||
#ifdef USE_BINARY_SENSOR
|
||||
#include "esphome/components/binary_sensor/binary_sensor.h"
|
||||
#endif
|
||||
#ifdef USE_BUTTON
|
||||
#include "esphome/components/button/button.h"
|
||||
#endif
|
||||
#ifdef USE_SELECT
|
||||
#include "esphome/components/select/select.h"
|
||||
#endif
|
||||
#ifdef USE_TEXT_SENSOR
|
||||
#include "esphome/components/text_sensor/text_sensor.h"
|
||||
#endif
|
||||
#include "esphome/components/uart/uart.h"
|
||||
#include "esphome/core/automation.h"
|
||||
#include "esphome/core/helpers.h"
|
||||
|
||||
#include <map>
|
||||
|
||||
namespace esphome {
|
||||
namespace seeed_mr60fda2 {
|
||||
|
||||
static const uint8_t DATA_BUF_MAX_SIZE = 28;
|
||||
static const uint8_t FRAME_BUF_MAX_SIZE = 37;
|
||||
static const uint8_t LEN_TO_HEAD_CKSUM = 8;
|
||||
static const uint8_t LEN_TO_DATA_FRAME = 9;
|
||||
|
||||
static const uint8_t FRAME_HEADER_BUFFER = 0x01;
|
||||
static const uint16_t IS_FALL_TYPE_BUFFER = 0x0E02;
|
||||
static const uint16_t PEOPLE_EXIST_TYPE_BUFFER = 0x0F09;
|
||||
static const uint16_t RESULT_INSTALL_HEIGHT = 0x0E04;
|
||||
static const uint16_t RESULT_PARAMETERS = 0x0E06;
|
||||
static const uint16_t RESULT_HEIGHT_THRESHOLD = 0x0E08;
|
||||
static const uint16_t RESULT_SENSITIVITY = 0x0E0A;
|
||||
|
||||
enum FrameLocation {
|
||||
LOCATE_FRAME_HEADER,
|
||||
LOCATE_ID_FRAME1,
|
||||
LOCATE_ID_FRAME2,
|
||||
LOCATE_LENGTH_FRAME_H,
|
||||
LOCATE_LENGTH_FRAME_L,
|
||||
LOCATE_TYPE_FRAME1,
|
||||
LOCATE_TYPE_FRAME2,
|
||||
LOCATE_HEAD_CKSUM_FRAME, // Header checksum: [from the first byte to the previous byte of the HEAD_CKSUM bit]
|
||||
LOCATE_DATA_FRAME,
|
||||
LOCATE_DATA_CKSUM_FRAME, // Data checksum: [from the first to the previous byte of the DATA_CKSUM bit]
|
||||
LOCATE_PROCESS_FRAME,
|
||||
};
|
||||
|
||||
static const float INSTALL_HEIGHT[7] = {2.4f, 2.5f, 2.6f, 2.7f, 2.8f, 2.9f, 3.0f};
|
||||
static const float HEIGHT_THRESHOLD[7] = {0.0f, 0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 0.6f};
|
||||
static const float SENSITIVITY[3] = {3, 15, 30};
|
||||
|
||||
static const char *const INSTALL_HEIGHT_STR[7] = {"2.4m", "2.5m", "2.6", "2.7m", "2.8", "2.9m", "3.0m"};
|
||||
static const char *const HEIGHT_THRESHOLD_STR[7] = {"0.0m", "0.1m", "0.2m", "0.3m", "0.4m", "0.5m", "0.6m"};
|
||||
static const char *const SENSITIVITY_STR[3] = {"1", "2", "3"};
|
||||
|
||||
class MR60FDA2Component : public Component,
|
||||
public uart::UARTDevice { // The class name must be the name defined by text_sensor.py
|
||||
#ifdef USE_BINARY_SENSOR
|
||||
SUB_BINARY_SENSOR(people_exist)
|
||||
SUB_BINARY_SENSOR(fall_detected)
|
||||
#endif
|
||||
#ifdef USE_BUTTON
|
||||
SUB_BUTTON(get_radar_parameters)
|
||||
SUB_BUTTON(factory_reset)
|
||||
#endif
|
||||
#ifdef USE_SELECT
|
||||
SUB_SELECT(install_height)
|
||||
SUB_SELECT(height_threshold)
|
||||
SUB_SELECT(sensitivity)
|
||||
#endif
|
||||
|
||||
protected:
|
||||
uint8_t current_frame_locate_;
|
||||
uint8_t current_frame_buf_[FRAME_BUF_MAX_SIZE];
|
||||
uint8_t current_data_buf_[DATA_BUF_MAX_SIZE];
|
||||
uint16_t current_frame_id_;
|
||||
size_t current_frame_len_;
|
||||
size_t current_data_frame_len_;
|
||||
uint16_t current_frame_type_;
|
||||
|
||||
void split_frame_(uint8_t buffer);
|
||||
void process_frame_();
|
||||
|
||||
public:
|
||||
float get_setup_priority() const override { return esphome::setup_priority::LATE; }
|
||||
void setup() override;
|
||||
void dump_config() override;
|
||||
void loop() override;
|
||||
void set_install_height(uint8_t index);
|
||||
void set_height_threshold(uint8_t index);
|
||||
void set_sensitivity(uint8_t index);
|
||||
void get_radar_parameters();
|
||||
void factory_reset();
|
||||
};
|
||||
|
||||
} // namespace seeed_mr60fda2
|
||||
} // namespace esphome
|
||||
@@ -0,0 +1,59 @@
|
||||
import esphome.codegen as cg
|
||||
from esphome.components import select
|
||||
import esphome.config_validation as cv
|
||||
from esphome.const import CONF_SENSITIVITY, ENTITY_CATEGORY_CONFIG, ICON_ACCELERATION_Z
|
||||
|
||||
from .. import CONF_MR60FDA2_ID, MR60FDA2Component, mr60fda2_ns
|
||||
|
||||
|
||||
DEPENDENCIES = ["seeed_mr60fda2"]
|
||||
|
||||
InstallHeightSelect = mr60fda2_ns.class_("InstallHeightSelect", select.Select)
|
||||
HeightThresholdSelect = mr60fda2_ns.class_("HeightThresholdSelect", select.Select)
|
||||
SensitivitySelect = mr60fda2_ns.class_("SensitivitySelect", select.Select)
|
||||
|
||||
CONF_INSTALL_HEIGHT = "install_height"
|
||||
CONF_HEIGHT_THRESHOLD = "height_threshold"
|
||||
|
||||
CONFIG_SCHEMA = {
|
||||
cv.GenerateID(CONF_MR60FDA2_ID): cv.use_id(MR60FDA2Component),
|
||||
cv.Optional(CONF_INSTALL_HEIGHT): select.select_schema(
|
||||
InstallHeightSelect,
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
icon=ICON_ACCELERATION_Z,
|
||||
),
|
||||
cv.Optional(CONF_HEIGHT_THRESHOLD): select.select_schema(
|
||||
HeightThresholdSelect,
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
icon=ICON_ACCELERATION_Z,
|
||||
),
|
||||
cv.Optional(CONF_SENSITIVITY): select.select_schema(
|
||||
SensitivitySelect,
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
async def to_code(config):
|
||||
mr60fda2_component = await cg.get_variable(config[CONF_MR60FDA2_ID])
|
||||
if install_height_config := config.get(CONF_INSTALL_HEIGHT):
|
||||
s = await select.new_select(
|
||||
install_height_config,
|
||||
options=["2.4m", "2.5m", "2.6m", "2.7m", "2.8m", "2.9m", "3.0m"],
|
||||
)
|
||||
await cg.register_parented(s, config[CONF_MR60FDA2_ID])
|
||||
cg.add(mr60fda2_component.set_install_height_select(s))
|
||||
if height_threshold_config := config.get(CONF_HEIGHT_THRESHOLD):
|
||||
s = await select.new_select(
|
||||
height_threshold_config,
|
||||
options=["0.0m", "0.1m", "0.2m", "0.3m", "0.4m", "0.5m", "0.6m"],
|
||||
)
|
||||
await cg.register_parented(s, config[CONF_MR60FDA2_ID])
|
||||
cg.add(mr60fda2_component.set_height_threshold_select(s))
|
||||
if sensitivity_config := config.get(CONF_SENSITIVITY):
|
||||
s = await select.new_select(
|
||||
sensitivity_config,
|
||||
options=["1", "2", "3"],
|
||||
)
|
||||
await cg.register_parented(s, config[CONF_MR60FDA2_ID])
|
||||
cg.add(mr60fda2_component.set_sensitivity_select(s))
|
||||
@@ -0,0 +1,15 @@
|
||||
#include "height_threshold_select.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace seeed_mr60fda2 {
|
||||
|
||||
void HeightThresholdSelect::control(const std::string &value) {
|
||||
this->publish_state(value);
|
||||
auto index = this->index_of(value);
|
||||
if (index.has_value()) {
|
||||
this->parent_->set_height_threshold(index.value());
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace seeed_mr60fda2
|
||||
} // namespace esphome
|
||||
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/components/select/select.h"
|
||||
#include "../seeed_mr60fda2.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace seeed_mr60fda2 {
|
||||
|
||||
class HeightThresholdSelect : public select::Select, public Parented<MR60FDA2Component> {
|
||||
public:
|
||||
HeightThresholdSelect() = default;
|
||||
|
||||
protected:
|
||||
void control(const std::string &value) override;
|
||||
};
|
||||
|
||||
} // namespace seeed_mr60fda2
|
||||
} // namespace esphome
|
||||
@@ -0,0 +1,15 @@
|
||||
#include "install_height_select.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace seeed_mr60fda2 {
|
||||
|
||||
void InstallHeightSelect::control(const std::string &value) {
|
||||
this->publish_state(value);
|
||||
auto index = this->index_of(value);
|
||||
if (index.has_value()) {
|
||||
this->parent_->set_install_height(index.value());
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace seeed_mr60fda2
|
||||
} // namespace esphome
|
||||
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/components/select/select.h"
|
||||
#include "../seeed_mr60fda2.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace seeed_mr60fda2 {
|
||||
|
||||
class InstallHeightSelect : public select::Select, public Parented<MR60FDA2Component> {
|
||||
public:
|
||||
InstallHeightSelect() = default;
|
||||
|
||||
protected:
|
||||
void control(const std::string &value) override;
|
||||
};
|
||||
|
||||
} // namespace seeed_mr60fda2
|
||||
} // namespace esphome
|
||||
@@ -0,0 +1,15 @@
|
||||
#include "sensitivity_select.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace seeed_mr60fda2 {
|
||||
|
||||
void SensitivitySelect::control(const std::string &value) {
|
||||
this->publish_state(value);
|
||||
auto index = this->index_of(value);
|
||||
if (index.has_value()) {
|
||||
this->parent_->set_sensitivity(index.value());
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace seeed_mr60fda2
|
||||
} // namespace esphome
|
||||
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/components/select/select.h"
|
||||
#include "../seeed_mr60fda2.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace seeed_mr60fda2 {
|
||||
|
||||
class SensitivitySelect : public select::Select, public Parented<MR60FDA2Component> {
|
||||
public:
|
||||
SensitivitySelect() = default;
|
||||
|
||||
protected:
|
||||
void control(const std::string &value) override;
|
||||
};
|
||||
|
||||
} // namespace seeed_mr60fda2
|
||||
} // namespace esphome
|
||||
@@ -0,0 +1,34 @@
|
||||
uart:
|
||||
- id: seeed_mr60fda2_uart
|
||||
tx_pin: ${uart_tx_pin}
|
||||
rx_pin: ${uart_rx_pin}
|
||||
baud_rate: 115200
|
||||
parity: NONE
|
||||
stop_bits: 1
|
||||
|
||||
seeed_mr60fda2:
|
||||
id: my_seeed_mr60fda2
|
||||
uart_id: seeed_mr60fda2_uart
|
||||
|
||||
binary_sensor:
|
||||
- platform: seeed_mr60fda2
|
||||
people_exist:
|
||||
name: "Person Information"
|
||||
fall_detected:
|
||||
name: "Falling Information"
|
||||
|
||||
button:
|
||||
- platform: seeed_mr60fda2
|
||||
get_radar_parameters:
|
||||
name: "Get Radar Parameters"
|
||||
factory_reset:
|
||||
name: "Reset"
|
||||
|
||||
select:
|
||||
- platform: seeed_mr60fda2
|
||||
install_height:
|
||||
name: "Set Install Height"
|
||||
height_threshold:
|
||||
name: "Set Height Threshold"
|
||||
sensitivity:
|
||||
name: "Set Sensitivity"
|
||||
@@ -0,0 +1,5 @@
|
||||
substitutions:
|
||||
uart_tx_pin: GPIO5
|
||||
uart_rx_pin: GPIO4
|
||||
|
||||
<<: !include common.yaml
|
||||
@@ -0,0 +1,5 @@
|
||||
substitutions:
|
||||
uart_tx_pin: GPIO5
|
||||
uart_rx_pin: GPIO4
|
||||
|
||||
<<: !include common.yaml
|
||||
Reference in New Issue
Block a user