mirror of
https://github.com/esphome/esphome.git
synced 2024-11-25 16:38:16 +01:00
Read all cell voltages from DalyBMS (#3203)
Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
This commit is contained in:
parent
7a242bb4ed
commit
1a8f8adc2a
3 changed files with 154 additions and 0 deletions
|
@ -16,6 +16,7 @@ static const uint8_t DALY_REQUEST_MIN_MAX_VOLTAGE = 0x91;
|
|||
static const uint8_t DALY_REQUEST_MIN_MAX_TEMPERATURE = 0x92;
|
||||
static const uint8_t DALY_REQUEST_MOS = 0x93;
|
||||
static const uint8_t DALY_REQUEST_STATUS = 0x94;
|
||||
static const uint8_t DALY_REQUEST_CELL_VOLTAGE = 0x95;
|
||||
static const uint8_t DALY_REQUEST_TEMPERATURE = 0x96;
|
||||
|
||||
void DalyBmsComponent::setup() {}
|
||||
|
@ -31,6 +32,7 @@ void DalyBmsComponent::update() {
|
|||
this->request_data_(DALY_REQUEST_MIN_MAX_TEMPERATURE);
|
||||
this->request_data_(DALY_REQUEST_MOS);
|
||||
this->request_data_(DALY_REQUEST_STATUS);
|
||||
this->request_data_(DALY_REQUEST_CELL_VOLTAGE);
|
||||
this->request_data_(DALY_REQUEST_TEMPERATURE);
|
||||
|
||||
std::vector<uint8_t> get_battery_level_data;
|
||||
|
@ -166,6 +168,71 @@ void DalyBmsComponent::decode_data_(std::vector<uint8_t> data) {
|
|||
}
|
||||
break;
|
||||
|
||||
case DALY_REQUEST_CELL_VOLTAGE:
|
||||
switch (it[4]) {
|
||||
case 1:
|
||||
if (this->cell_1_voltage_) {
|
||||
this->cell_1_voltage_->publish_state((float) encode_uint16(it[5], it[6]) / 1000);
|
||||
}
|
||||
if (this->cell_2_voltage_) {
|
||||
this->cell_2_voltage_->publish_state((float) encode_uint16(it[7], it[8]) / 1000);
|
||||
}
|
||||
if (this->cell_3_voltage_) {
|
||||
this->cell_3_voltage_->publish_state((float) encode_uint16(it[9], it[10]) / 1000);
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if (this->cell_4_voltage_) {
|
||||
this->cell_4_voltage_->publish_state((float) encode_uint16(it[5], it[6]) / 1000);
|
||||
}
|
||||
if (this->cell_5_voltage_) {
|
||||
this->cell_5_voltage_->publish_state((float) encode_uint16(it[7], it[8]) / 1000);
|
||||
}
|
||||
if (this->cell_6_voltage_) {
|
||||
this->cell_6_voltage_->publish_state((float) encode_uint16(it[9], it[10]) / 1000);
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
if (this->cell_7_voltage_) {
|
||||
this->cell_7_voltage_->publish_state((float) encode_uint16(it[5], it[6]) / 1000);
|
||||
}
|
||||
if (this->cell_8_voltage_) {
|
||||
this->cell_8_voltage_->publish_state((float) encode_uint16(it[7], it[8]) / 1000);
|
||||
}
|
||||
if (this->cell_9_voltage_) {
|
||||
this->cell_9_voltage_->publish_state((float) encode_uint16(it[9], it[10]) / 1000);
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
if (this->cell_10_voltage_) {
|
||||
this->cell_10_voltage_->publish_state((float) encode_uint16(it[5], it[6]) / 1000);
|
||||
}
|
||||
if (this->cell_11_voltage_) {
|
||||
this->cell_11_voltage_->publish_state((float) encode_uint16(it[7], it[8]) / 1000);
|
||||
}
|
||||
if (this->cell_12_voltage_) {
|
||||
this->cell_12_voltage_->publish_state((float) encode_uint16(it[9], it[10]) / 1000);
|
||||
}
|
||||
break;
|
||||
case 5:
|
||||
if (this->cell_13_voltage_) {
|
||||
this->cell_13_voltage_->publish_state((float) encode_uint16(it[5], it[6]) / 1000);
|
||||
}
|
||||
if (this->cell_14_voltage_) {
|
||||
this->cell_14_voltage_->publish_state((float) encode_uint16(it[7], it[8]) / 1000);
|
||||
}
|
||||
if (this->cell_15_voltage_) {
|
||||
this->cell_15_voltage_->publish_state((float) encode_uint16(it[9], it[10]) / 1000);
|
||||
}
|
||||
break;
|
||||
case 6:
|
||||
if (this->cell_16_voltage_) {
|
||||
this->cell_16_voltage_->publish_state((float) encode_uint16(it[5], it[6]) / 1000);
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -37,6 +37,23 @@ class DalyBmsComponent : public PollingComponent, public uart::UARTDevice {
|
|||
void set_cells_number_sensor(sensor::Sensor *cells_number) { cells_number_ = cells_number; }
|
||||
void set_temperature_1_sensor(sensor::Sensor *temperature_1_sensor) { temperature_1_sensor_ = temperature_1_sensor; }
|
||||
void set_temperature_2_sensor(sensor::Sensor *temperature_2_sensor) { temperature_2_sensor_ = temperature_2_sensor; }
|
||||
void set_cell_1_voltage_sensor(sensor::Sensor *cell_1_voltage) { cell_1_voltage_ = cell_1_voltage; }
|
||||
void set_cell_2_voltage_sensor(sensor::Sensor *cell_2_voltage) { cell_2_voltage_ = cell_2_voltage; }
|
||||
void set_cell_3_voltage_sensor(sensor::Sensor *cell_3_voltage) { cell_3_voltage_ = cell_3_voltage; }
|
||||
void set_cell_4_voltage_sensor(sensor::Sensor *cell_4_voltage) { cell_4_voltage_ = cell_4_voltage; }
|
||||
void set_cell_5_voltage_sensor(sensor::Sensor *cell_5_voltage) { cell_5_voltage_ = cell_5_voltage; }
|
||||
void set_cell_6_voltage_sensor(sensor::Sensor *cell_6_voltage) { cell_6_voltage_ = cell_6_voltage; }
|
||||
void set_cell_7_voltage_sensor(sensor::Sensor *cell_7_voltage) { cell_7_voltage_ = cell_7_voltage; }
|
||||
void set_cell_8_voltage_sensor(sensor::Sensor *cell_8_voltage) { cell_8_voltage_ = cell_8_voltage; }
|
||||
void set_cell_9_voltage_sensor(sensor::Sensor *cell_9_voltage) { cell_9_voltage_ = cell_9_voltage; }
|
||||
void set_cell_10_voltage_sensor(sensor::Sensor *cell_10_voltage) { cell_10_voltage_ = cell_10_voltage; }
|
||||
void set_cell_11_voltage_sensor(sensor::Sensor *cell_11_voltage) { cell_11_voltage_ = cell_11_voltage; }
|
||||
void set_cell_12_voltage_sensor(sensor::Sensor *cell_12_voltage) { cell_12_voltage_ = cell_12_voltage; }
|
||||
void set_cell_13_voltage_sensor(sensor::Sensor *cell_13_voltage) { cell_13_voltage_ = cell_13_voltage; }
|
||||
void set_cell_14_voltage_sensor(sensor::Sensor *cell_14_voltage) { cell_14_voltage_ = cell_14_voltage; }
|
||||
void set_cell_15_voltage_sensor(sensor::Sensor *cell_15_voltage) { cell_15_voltage_ = cell_15_voltage; }
|
||||
void set_cell_16_voltage_sensor(sensor::Sensor *cell_16_voltage) { cell_16_voltage_ = cell_16_voltage; }
|
||||
|
||||
// TEXT_SENSORS
|
||||
void set_status_text_sensor(text_sensor::TextSensor *status_text_sensor) { status_text_sensor_ = status_text_sensor; }
|
||||
// BINARY_SENSORS
|
||||
|
@ -72,6 +89,22 @@ class DalyBmsComponent : public PollingComponent, public uart::UARTDevice {
|
|||
sensor::Sensor *cells_number_{nullptr};
|
||||
sensor::Sensor *temperature_1_sensor_{nullptr};
|
||||
sensor::Sensor *temperature_2_sensor_{nullptr};
|
||||
sensor::Sensor *cell_1_voltage_{nullptr};
|
||||
sensor::Sensor *cell_2_voltage_{nullptr};
|
||||
sensor::Sensor *cell_3_voltage_{nullptr};
|
||||
sensor::Sensor *cell_4_voltage_{nullptr};
|
||||
sensor::Sensor *cell_5_voltage_{nullptr};
|
||||
sensor::Sensor *cell_6_voltage_{nullptr};
|
||||
sensor::Sensor *cell_7_voltage_{nullptr};
|
||||
sensor::Sensor *cell_8_voltage_{nullptr};
|
||||
sensor::Sensor *cell_9_voltage_{nullptr};
|
||||
sensor::Sensor *cell_10_voltage_{nullptr};
|
||||
sensor::Sensor *cell_11_voltage_{nullptr};
|
||||
sensor::Sensor *cell_12_voltage_{nullptr};
|
||||
sensor::Sensor *cell_13_voltage_{nullptr};
|
||||
sensor::Sensor *cell_14_voltage_{nullptr};
|
||||
sensor::Sensor *cell_15_voltage_{nullptr};
|
||||
sensor::Sensor *cell_16_voltage_{nullptr};
|
||||
|
||||
text_sensor::TextSensor *status_text_sensor_{nullptr};
|
||||
|
||||
|
|
|
@ -36,6 +36,22 @@ CONF_REMAINING_CAPACITY = "remaining_capacity"
|
|||
CONF_TEMPERATURE_1 = "temperature_1"
|
||||
CONF_TEMPERATURE_2 = "temperature_2"
|
||||
|
||||
CONF_CELL_1_VOLTAGE = "cell_1_voltage"
|
||||
CONF_CELL_2_VOLTAGE = "cell_2_voltage"
|
||||
CONF_CELL_3_VOLTAGE = "cell_3_voltage"
|
||||
CONF_CELL_4_VOLTAGE = "cell_4_voltage"
|
||||
CONF_CELL_5_VOLTAGE = "cell_5_voltage"
|
||||
CONF_CELL_6_VOLTAGE = "cell_6_voltage"
|
||||
CONF_CELL_7_VOLTAGE = "cell_7_voltage"
|
||||
CONF_CELL_8_VOLTAGE = "cell_8_voltage"
|
||||
CONF_CELL_9_VOLTAGE = "cell_9_voltage"
|
||||
CONF_CELL_10_VOLTAGE = "cell_10_voltage"
|
||||
CONF_CELL_11_VOLTAGE = "cell_11_voltage"
|
||||
CONF_CELL_12_VOLTAGE = "cell_12_voltage"
|
||||
CONF_CELL_13_VOLTAGE = "cell_13_voltage"
|
||||
CONF_CELL_14_VOLTAGE = "cell_14_voltage"
|
||||
CONF_CELL_15_VOLTAGE = "cell_15_voltage"
|
||||
CONF_CELL_16_VOLTAGE = "cell_16_voltage"
|
||||
ICON_CURRENT_DC = "mdi:current-dc"
|
||||
ICON_BATTERY_OUTLINE = "mdi:battery-outline"
|
||||
ICON_THERMOMETER_CHEVRON_UP = "mdi:thermometer-chevron-up"
|
||||
|
@ -60,8 +76,30 @@ TYPES = [
|
|||
CONF_REMAINING_CAPACITY,
|
||||
CONF_TEMPERATURE_1,
|
||||
CONF_TEMPERATURE_2,
|
||||
CONF_CELL_1_VOLTAGE,
|
||||
CONF_CELL_2_VOLTAGE,
|
||||
CONF_CELL_3_VOLTAGE,
|
||||
CONF_CELL_4_VOLTAGE,
|
||||
CONF_CELL_5_VOLTAGE,
|
||||
CONF_CELL_6_VOLTAGE,
|
||||
CONF_CELL_7_VOLTAGE,
|
||||
CONF_CELL_8_VOLTAGE,
|
||||
CONF_CELL_9_VOLTAGE,
|
||||
CONF_CELL_10_VOLTAGE,
|
||||
CONF_CELL_11_VOLTAGE,
|
||||
CONF_CELL_12_VOLTAGE,
|
||||
CONF_CELL_13_VOLTAGE,
|
||||
CONF_CELL_14_VOLTAGE,
|
||||
CONF_CELL_15_VOLTAGE,
|
||||
CONF_CELL_16_VOLTAGE,
|
||||
]
|
||||
|
||||
CELL_VOLTAGE_SCHEMA = sensor.sensor_schema(
|
||||
unit_of_measurement=UNIT_VOLT,
|
||||
device_class=DEVICE_CLASS_VOLTAGE,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
)
|
||||
|
||||
CONFIG_SCHEMA = cv.All(
|
||||
cv.Schema(
|
||||
{
|
||||
|
@ -156,6 +194,22 @@ CONFIG_SCHEMA = cv.All(
|
|||
device_class=DEVICE_CLASS_TEMPERATURE,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
cv.Optional(CONF_CELL_1_VOLTAGE): CELL_VOLTAGE_SCHEMA,
|
||||
cv.Optional(CONF_CELL_2_VOLTAGE): CELL_VOLTAGE_SCHEMA,
|
||||
cv.Optional(CONF_CELL_3_VOLTAGE): CELL_VOLTAGE_SCHEMA,
|
||||
cv.Optional(CONF_CELL_4_VOLTAGE): CELL_VOLTAGE_SCHEMA,
|
||||
cv.Optional(CONF_CELL_5_VOLTAGE): CELL_VOLTAGE_SCHEMA,
|
||||
cv.Optional(CONF_CELL_6_VOLTAGE): CELL_VOLTAGE_SCHEMA,
|
||||
cv.Optional(CONF_CELL_7_VOLTAGE): CELL_VOLTAGE_SCHEMA,
|
||||
cv.Optional(CONF_CELL_8_VOLTAGE): CELL_VOLTAGE_SCHEMA,
|
||||
cv.Optional(CONF_CELL_9_VOLTAGE): CELL_VOLTAGE_SCHEMA,
|
||||
cv.Optional(CONF_CELL_10_VOLTAGE): CELL_VOLTAGE_SCHEMA,
|
||||
cv.Optional(CONF_CELL_11_VOLTAGE): CELL_VOLTAGE_SCHEMA,
|
||||
cv.Optional(CONF_CELL_12_VOLTAGE): CELL_VOLTAGE_SCHEMA,
|
||||
cv.Optional(CONF_CELL_13_VOLTAGE): CELL_VOLTAGE_SCHEMA,
|
||||
cv.Optional(CONF_CELL_14_VOLTAGE): CELL_VOLTAGE_SCHEMA,
|
||||
cv.Optional(CONF_CELL_15_VOLTAGE): CELL_VOLTAGE_SCHEMA,
|
||||
cv.Optional(CONF_CELL_16_VOLTAGE): CELL_VOLTAGE_SCHEMA,
|
||||
}
|
||||
).extend(cv.COMPONENT_SCHEMA)
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue