mirror of
https://github.com/esphome/esphome.git
synced 2024-12-22 13:34:54 +01:00
Daly BMS improvements (#3388)
Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com> Co-authored-by: Samuel Sieb <samuel-github@sieb.net>
This commit is contained in:
parent
0ed0bdc655
commit
5b0b9da0b9
6 changed files with 217 additions and 180 deletions
|
@ -5,7 +5,6 @@ from esphome.const import CONF_ID, CONF_ADDRESS
|
||||||
|
|
||||||
CODEOWNERS = ["@s1lvi0"]
|
CODEOWNERS = ["@s1lvi0"]
|
||||||
DEPENDENCIES = ["uart"]
|
DEPENDENCIES = ["uart"]
|
||||||
AUTO_LOAD = ["sensor", "text_sensor", "binary_sensor"]
|
|
||||||
|
|
||||||
CONF_BMS_DALY_ID = "bms_daly_id"
|
CONF_BMS_DALY_ID = "bms_daly_id"
|
||||||
|
|
||||||
|
|
|
@ -27,9 +27,8 @@ CONFIG_SCHEMA = cv.All(
|
||||||
|
|
||||||
|
|
||||||
async def setup_conf(config, key, hub):
|
async def setup_conf(config, key, hub):
|
||||||
if key in config:
|
if sensor_config := config.get(key):
|
||||||
conf = config[key]
|
var = await binary_sensor.new_binary_sensor(sensor_config)
|
||||||
var = await binary_sensor.new_binary_sensor(conf)
|
|
||||||
cg.add(getattr(hub, f"set_{key}_binary_sensor")(var))
|
cg.add(getattr(hub, f"set_{key}_binary_sensor")(var))
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#include "daly_bms.h"
|
#include "daly_bms.h"
|
||||||
#include "esphome/core/log.h"
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include "esphome/core/log.h"
|
||||||
|
|
||||||
namespace esphome {
|
namespace esphome {
|
||||||
namespace daly_bms {
|
namespace daly_bms {
|
||||||
|
@ -19,7 +19,7 @@ static const uint8_t DALY_REQUEST_STATUS = 0x94;
|
||||||
static const uint8_t DALY_REQUEST_CELL_VOLTAGE = 0x95;
|
static const uint8_t DALY_REQUEST_CELL_VOLTAGE = 0x95;
|
||||||
static const uint8_t DALY_REQUEST_TEMPERATURE = 0x96;
|
static const uint8_t DALY_REQUEST_TEMPERATURE = 0x96;
|
||||||
|
|
||||||
void DalyBmsComponent::setup() {}
|
void DalyBmsComponent::setup() { this->next_request_ = 1; }
|
||||||
|
|
||||||
void DalyBmsComponent::dump_config() {
|
void DalyBmsComponent::dump_config() {
|
||||||
ESP_LOGCONFIG(TAG, "Daly BMS:");
|
ESP_LOGCONFIG(TAG, "Daly BMS:");
|
||||||
|
@ -27,20 +27,78 @@ void DalyBmsComponent::dump_config() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void DalyBmsComponent::update() {
|
void DalyBmsComponent::update() {
|
||||||
this->request_data_(DALY_REQUEST_BATTERY_LEVEL);
|
this->trigger_next_ = true;
|
||||||
this->request_data_(DALY_REQUEST_MIN_MAX_VOLTAGE);
|
this->next_request_ = 0;
|
||||||
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;
|
void DalyBmsComponent::loop() {
|
||||||
int available_data = this->available();
|
const uint32_t now = millis();
|
||||||
if (available_data >= DALY_FRAME_SIZE) {
|
if (this->receiving_ && (now - this->last_transmission_ >= 200)) {
|
||||||
get_battery_level_data.resize(available_data);
|
// last transmission too long ago. Reset RX index.
|
||||||
this->read_array(get_battery_level_data.data(), available_data);
|
ESP_LOGW(TAG, "Last transmission too long ago. Reset RX index.");
|
||||||
this->decode_data_(get_battery_level_data);
|
this->data_.clear();
|
||||||
|
this->receiving_ = false;
|
||||||
|
}
|
||||||
|
if ((now - this->last_transmission_ >= 250) && !this->trigger_next_) {
|
||||||
|
// last transmittion longer than 0.25s ago -> trigger next request
|
||||||
|
this->last_transmission_ = now;
|
||||||
|
this->trigger_next_ = true;
|
||||||
|
}
|
||||||
|
if (available())
|
||||||
|
this->last_transmission_ = now;
|
||||||
|
while (available()) {
|
||||||
|
uint8_t c;
|
||||||
|
read_byte(&c);
|
||||||
|
if (!this->receiving_) {
|
||||||
|
if (c != 0xa5)
|
||||||
|
continue;
|
||||||
|
this->receiving_ = true;
|
||||||
|
}
|
||||||
|
this->data_.push_back(c);
|
||||||
|
if (this->data_.size() == 4)
|
||||||
|
this->data_count_ = c;
|
||||||
|
if ((this->data_.size() > 4) and (data_.size() == this->data_count_ + 5)) {
|
||||||
|
this->decode_data_(this->data_);
|
||||||
|
this->data_.clear();
|
||||||
|
this->receiving_ = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this->trigger_next_) {
|
||||||
|
this->trigger_next_ = false;
|
||||||
|
switch (this->next_request_) {
|
||||||
|
case 0:
|
||||||
|
this->request_data_(DALY_REQUEST_BATTERY_LEVEL);
|
||||||
|
this->next_request_ = 1;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
this->request_data_(DALY_REQUEST_MIN_MAX_VOLTAGE);
|
||||||
|
this->next_request_ = 2;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
this->request_data_(DALY_REQUEST_MIN_MAX_TEMPERATURE);
|
||||||
|
this->next_request_ = 3;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
this->request_data_(DALY_REQUEST_MOS);
|
||||||
|
this->next_request_ = 4;
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
this->request_data_(DALY_REQUEST_STATUS);
|
||||||
|
this->next_request_ = 5;
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
this->request_data_(DALY_REQUEST_CELL_VOLTAGE);
|
||||||
|
this->next_request_ = 6;
|
||||||
|
break;
|
||||||
|
case 6:
|
||||||
|
this->request_data_(DALY_REQUEST_TEMPERATURE);
|
||||||
|
this->next_request_ = 7;
|
||||||
|
break;
|
||||||
|
case 7:
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,7 +108,7 @@ void DalyBmsComponent::request_data_(uint8_t data_id) {
|
||||||
uint8_t request_message[DALY_FRAME_SIZE];
|
uint8_t request_message[DALY_FRAME_SIZE];
|
||||||
|
|
||||||
request_message[0] = 0xA5; // Start Flag
|
request_message[0] = 0xA5; // Start Flag
|
||||||
request_message[1] = addr_; // Communication Module Address
|
request_message[1] = this->addr_; // Communication Module Address
|
||||||
request_message[2] = data_id; // Data ID
|
request_message[2] = data_id; // Data ID
|
||||||
request_message[3] = 0x08; // Data Length (Fixed)
|
request_message[3] = 0x08; // Data Length (Fixed)
|
||||||
request_message[4] = 0x00; // Empty Data
|
request_message[4] = 0x00; // Empty Data
|
||||||
|
@ -61,9 +119,11 @@ void DalyBmsComponent::request_data_(uint8_t data_id) {
|
||||||
request_message[9] = 0x00; // |
|
request_message[9] = 0x00; // |
|
||||||
request_message[10] = 0x00; // |
|
request_message[10] = 0x00; // |
|
||||||
request_message[11] = 0x00; // Empty Data
|
request_message[11] = 0x00; // Empty Data
|
||||||
|
|
||||||
request_message[12] = (uint8_t) (request_message[0] + request_message[1] + request_message[2] +
|
request_message[12] = (uint8_t) (request_message[0] + request_message[1] + request_message[2] +
|
||||||
request_message[3]); // Checksum (Lower byte of the other bytes sum)
|
request_message[3]); // Checksum (Lower byte of the other bytes sum)
|
||||||
|
|
||||||
|
ESP_LOGV(TAG, "Request datapacket Nr %x", data_id);
|
||||||
this->write_array(request_message, sizeof(request_message));
|
this->write_array(request_message, sizeof(request_message));
|
||||||
this->flush();
|
this->flush();
|
||||||
}
|
}
|
||||||
|
@ -82,6 +142,7 @@ void DalyBmsComponent::decode_data_(std::vector<uint8_t> data) {
|
||||||
|
|
||||||
if (checksum == it[12]) {
|
if (checksum == it[12]) {
|
||||||
switch (it[2]) {
|
switch (it[2]) {
|
||||||
|
#ifdef USE_SENSOR
|
||||||
case DALY_REQUEST_BATTERY_LEVEL:
|
case DALY_REQUEST_BATTERY_LEVEL:
|
||||||
if (this->voltage_sensor_) {
|
if (this->voltage_sensor_) {
|
||||||
this->voltage_sensor_->publish_state((float) encode_uint16(it[4], it[5]) / 10);
|
this->voltage_sensor_->publish_state((float) encode_uint16(it[4], it[5]) / 10);
|
||||||
|
@ -95,36 +156,37 @@ void DalyBmsComponent::decode_data_(std::vector<uint8_t> data) {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DALY_REQUEST_MIN_MAX_VOLTAGE:
|
case DALY_REQUEST_MIN_MAX_VOLTAGE:
|
||||||
if (this->max_cell_voltage_) {
|
if (this->max_cell_voltage_sensor_) {
|
||||||
this->max_cell_voltage_->publish_state((float) encode_uint16(it[4], it[5]) / 1000);
|
this->max_cell_voltage_sensor_->publish_state((float) encode_uint16(it[4], it[5]) / 1000);
|
||||||
}
|
}
|
||||||
if (this->max_cell_voltage_number_) {
|
if (this->max_cell_voltage_number_sensor_) {
|
||||||
this->max_cell_voltage_number_->publish_state(it[6]);
|
this->max_cell_voltage_number_sensor_->publish_state(it[6]);
|
||||||
}
|
}
|
||||||
if (this->min_cell_voltage_) {
|
if (this->min_cell_voltage_sensor_) {
|
||||||
this->min_cell_voltage_->publish_state((float) encode_uint16(it[7], it[8]) / 1000);
|
this->min_cell_voltage_sensor_->publish_state((float) encode_uint16(it[7], it[8]) / 1000);
|
||||||
}
|
}
|
||||||
if (this->min_cell_voltage_number_) {
|
if (this->min_cell_voltage_number_sensor_) {
|
||||||
this->min_cell_voltage_number_->publish_state(it[9]);
|
this->min_cell_voltage_number_sensor_->publish_state(it[9]);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DALY_REQUEST_MIN_MAX_TEMPERATURE:
|
case DALY_REQUEST_MIN_MAX_TEMPERATURE:
|
||||||
if (this->max_temperature_) {
|
if (this->max_temperature_sensor_) {
|
||||||
this->max_temperature_->publish_state(it[4] - DALY_TEMPERATURE_OFFSET);
|
this->max_temperature_sensor_->publish_state(it[4] - DALY_TEMPERATURE_OFFSET);
|
||||||
}
|
}
|
||||||
if (this->max_temperature_probe_number_) {
|
if (this->max_temperature_probe_number_sensor_) {
|
||||||
this->max_temperature_probe_number_->publish_state(it[5]);
|
this->max_temperature_probe_number_sensor_->publish_state(it[5]);
|
||||||
}
|
}
|
||||||
if (this->min_temperature_) {
|
if (this->min_temperature_sensor_) {
|
||||||
this->min_temperature_->publish_state(it[6] - DALY_TEMPERATURE_OFFSET);
|
this->min_temperature_sensor_->publish_state(it[6] - DALY_TEMPERATURE_OFFSET);
|
||||||
}
|
}
|
||||||
if (this->min_temperature_probe_number_) {
|
if (this->min_temperature_probe_number_sensor_) {
|
||||||
this->min_temperature_probe_number_->publish_state(it[7]);
|
this->min_temperature_probe_number_sensor_->publish_state(it[7]);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
case DALY_REQUEST_MOS:
|
case DALY_REQUEST_MOS:
|
||||||
|
#ifdef USE_TEXT_SENSOR
|
||||||
if (this->status_text_sensor_ != nullptr) {
|
if (this->status_text_sensor_ != nullptr) {
|
||||||
switch (it[4]) {
|
switch (it[4]) {
|
||||||
case 0:
|
case 0:
|
||||||
|
@ -140,20 +202,27 @@ void DalyBmsComponent::decode_data_(std::vector<uint8_t> data) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this->charging_mos_enabled_) {
|
#endif
|
||||||
this->charging_mos_enabled_->publish_state(it[5]);
|
#ifdef USE_BINARY_SENSOR
|
||||||
|
if (this->charging_mos_enabled_binary_sensor_) {
|
||||||
|
this->charging_mos_enabled_binary_sensor_->publish_state(it[5]);
|
||||||
}
|
}
|
||||||
if (this->discharging_mos_enabled_) {
|
if (this->discharging_mos_enabled_binary_sensor_) {
|
||||||
this->discharging_mos_enabled_->publish_state(it[6]);
|
this->discharging_mos_enabled_binary_sensor_->publish_state(it[6]);
|
||||||
}
|
}
|
||||||
if (this->remaining_capacity_) {
|
#endif
|
||||||
this->remaining_capacity_->publish_state((float) encode_uint32(it[8], it[9], it[10], it[11]) / 1000);
|
#ifdef USE_SENSOR
|
||||||
|
if (this->remaining_capacity_sensor_) {
|
||||||
|
this->remaining_capacity_sensor_->publish_state((float) encode_uint32(it[8], it[9], it[10], it[11]) /
|
||||||
|
1000);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
#ifdef USE_SENSOR
|
||||||
case DALY_REQUEST_STATUS:
|
case DALY_REQUEST_STATUS:
|
||||||
if (this->cells_number_) {
|
if (this->cells_number_sensor_) {
|
||||||
this->cells_number_->publish_state(it[4]);
|
this->cells_number_sensor_->publish_state(it[4]);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -171,71 +240,73 @@ void DalyBmsComponent::decode_data_(std::vector<uint8_t> data) {
|
||||||
case DALY_REQUEST_CELL_VOLTAGE:
|
case DALY_REQUEST_CELL_VOLTAGE:
|
||||||
switch (it[4]) {
|
switch (it[4]) {
|
||||||
case 1:
|
case 1:
|
||||||
if (this->cell_1_voltage_) {
|
if (this->cell_1_voltage_sensor_) {
|
||||||
this->cell_1_voltage_->publish_state((float) encode_uint16(it[5], it[6]) / 1000);
|
this->cell_1_voltage_sensor_->publish_state((float) encode_uint16(it[5], it[6]) / 1000);
|
||||||
}
|
}
|
||||||
if (this->cell_2_voltage_) {
|
if (this->cell_2_voltage_sensor_) {
|
||||||
this->cell_2_voltage_->publish_state((float) encode_uint16(it[7], it[8]) / 1000);
|
this->cell_2_voltage_sensor_->publish_state((float) encode_uint16(it[7], it[8]) / 1000);
|
||||||
}
|
}
|
||||||
if (this->cell_3_voltage_) {
|
if (this->cell_3_voltage_sensor_) {
|
||||||
this->cell_3_voltage_->publish_state((float) encode_uint16(it[9], it[10]) / 1000);
|
this->cell_3_voltage_sensor_->publish_state((float) encode_uint16(it[9], it[10]) / 1000);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
if (this->cell_4_voltage_) {
|
if (this->cell_4_voltage_sensor_) {
|
||||||
this->cell_4_voltage_->publish_state((float) encode_uint16(it[5], it[6]) / 1000);
|
this->cell_4_voltage_sensor_->publish_state((float) encode_uint16(it[5], it[6]) / 1000);
|
||||||
}
|
}
|
||||||
if (this->cell_5_voltage_) {
|
if (this->cell_5_voltage_sensor_) {
|
||||||
this->cell_5_voltage_->publish_state((float) encode_uint16(it[7], it[8]) / 1000);
|
this->cell_5_voltage_sensor_->publish_state((float) encode_uint16(it[7], it[8]) / 1000);
|
||||||
}
|
}
|
||||||
if (this->cell_6_voltage_) {
|
if (this->cell_6_voltage_sensor_) {
|
||||||
this->cell_6_voltage_->publish_state((float) encode_uint16(it[9], it[10]) / 1000);
|
this->cell_6_voltage_sensor_->publish_state((float) encode_uint16(it[9], it[10]) / 1000);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
if (this->cell_7_voltage_) {
|
if (this->cell_7_voltage_sensor_) {
|
||||||
this->cell_7_voltage_->publish_state((float) encode_uint16(it[5], it[6]) / 1000);
|
this->cell_7_voltage_sensor_->publish_state((float) encode_uint16(it[5], it[6]) / 1000);
|
||||||
}
|
}
|
||||||
if (this->cell_8_voltage_) {
|
if (this->cell_8_voltage_sensor_) {
|
||||||
this->cell_8_voltage_->publish_state((float) encode_uint16(it[7], it[8]) / 1000);
|
this->cell_8_voltage_sensor_->publish_state((float) encode_uint16(it[7], it[8]) / 1000);
|
||||||
}
|
}
|
||||||
if (this->cell_9_voltage_) {
|
if (this->cell_9_voltage_sensor_) {
|
||||||
this->cell_9_voltage_->publish_state((float) encode_uint16(it[9], it[10]) / 1000);
|
this->cell_9_voltage_sensor_->publish_state((float) encode_uint16(it[9], it[10]) / 1000);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
if (this->cell_10_voltage_) {
|
if (this->cell_10_voltage_sensor_) {
|
||||||
this->cell_10_voltage_->publish_state((float) encode_uint16(it[5], it[6]) / 1000);
|
this->cell_10_voltage_sensor_->publish_state((float) encode_uint16(it[5], it[6]) / 1000);
|
||||||
}
|
}
|
||||||
if (this->cell_11_voltage_) {
|
if (this->cell_11_voltage_sensor_) {
|
||||||
this->cell_11_voltage_->publish_state((float) encode_uint16(it[7], it[8]) / 1000);
|
this->cell_11_voltage_sensor_->publish_state((float) encode_uint16(it[7], it[8]) / 1000);
|
||||||
}
|
}
|
||||||
if (this->cell_12_voltage_) {
|
if (this->cell_12_voltage_sensor_) {
|
||||||
this->cell_12_voltage_->publish_state((float) encode_uint16(it[9], it[10]) / 1000);
|
this->cell_12_voltage_sensor_->publish_state((float) encode_uint16(it[9], it[10]) / 1000);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
if (this->cell_13_voltage_) {
|
if (this->cell_13_voltage_sensor_) {
|
||||||
this->cell_13_voltage_->publish_state((float) encode_uint16(it[5], it[6]) / 1000);
|
this->cell_13_voltage_sensor_->publish_state((float) encode_uint16(it[5], it[6]) / 1000);
|
||||||
}
|
}
|
||||||
if (this->cell_14_voltage_) {
|
if (this->cell_14_voltage_sensor_) {
|
||||||
this->cell_14_voltage_->publish_state((float) encode_uint16(it[7], it[8]) / 1000);
|
this->cell_14_voltage_sensor_->publish_state((float) encode_uint16(it[7], it[8]) / 1000);
|
||||||
}
|
}
|
||||||
if (this->cell_15_voltage_) {
|
if (this->cell_15_voltage_sensor_) {
|
||||||
this->cell_15_voltage_->publish_state((float) encode_uint16(it[9], it[10]) / 1000);
|
this->cell_15_voltage_sensor_->publish_state((float) encode_uint16(it[9], it[10]) / 1000);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 6:
|
case 6:
|
||||||
if (this->cell_16_voltage_) {
|
if (this->cell_16_voltage_sensor_) {
|
||||||
this->cell_16_voltage_->publish_state((float) encode_uint16(it[5], it[6]) / 1000);
|
this->cell_16_voltage_sensor_->publish_state((float) encode_uint16(it[5], it[6]) / 1000);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
ESP_LOGW(TAG, "Checksum-Error on Packet %x", it[4]);
|
||||||
}
|
}
|
||||||
std::advance(it, DALY_FRAME_SIZE);
|
std::advance(it, DALY_FRAME_SIZE);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1,9 +1,16 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "esphome/core/component.h"
|
#include "esphome/core/component.h"
|
||||||
|
#include "esphome/core/defines.h"
|
||||||
|
#ifdef USE_SENSOR
|
||||||
#include "esphome/components/sensor/sensor.h"
|
#include "esphome/components/sensor/sensor.h"
|
||||||
|
#endif
|
||||||
|
#ifdef USE_TEXT_SENSOR
|
||||||
#include "esphome/components/text_sensor/text_sensor.h"
|
#include "esphome/components/text_sensor/text_sensor.h"
|
||||||
|
#endif
|
||||||
|
#ifdef USE_BINARY_SENSOR
|
||||||
#include "esphome/components/binary_sensor/binary_sensor.h"
|
#include "esphome/components/binary_sensor/binary_sensor.h"
|
||||||
|
#endif
|
||||||
#include "esphome/components/uart/uart.h"
|
#include "esphome/components/uart/uart.h"
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
@ -15,60 +22,53 @@ class DalyBmsComponent : public PollingComponent, public uart::UARTDevice {
|
||||||
public:
|
public:
|
||||||
DalyBmsComponent() = default;
|
DalyBmsComponent() = default;
|
||||||
|
|
||||||
// SENSORS
|
#ifdef USE_SENSOR
|
||||||
void set_voltage_sensor(sensor::Sensor *voltage_sensor) { voltage_sensor_ = voltage_sensor; }
|
SUB_SENSOR(voltage)
|
||||||
void set_current_sensor(sensor::Sensor *current_sensor) { current_sensor_ = current_sensor; }
|
SUB_SENSOR(current)
|
||||||
void set_battery_level_sensor(sensor::Sensor *battery_level_sensor) { battery_level_sensor_ = battery_level_sensor; }
|
SUB_SENSOR(battery_level)
|
||||||
void set_max_cell_voltage_sensor(sensor::Sensor *max_cell_voltage) { max_cell_voltage_ = max_cell_voltage; }
|
SUB_SENSOR(max_cell_voltage)
|
||||||
void set_max_cell_voltage_number_sensor(sensor::Sensor *max_cell_voltage_number) {
|
SUB_SENSOR(max_cell_voltage_number)
|
||||||
max_cell_voltage_number_ = max_cell_voltage_number;
|
SUB_SENSOR(min_cell_voltage)
|
||||||
}
|
SUB_SENSOR(min_cell_voltage_number)
|
||||||
void set_min_cell_voltage_sensor(sensor::Sensor *min_cell_voltage) { min_cell_voltage_ = min_cell_voltage; }
|
SUB_SENSOR(max_temperature)
|
||||||
void set_min_cell_voltage_number_sensor(sensor::Sensor *min_cell_voltage_number) {
|
SUB_SENSOR(max_temperature_probe_number)
|
||||||
min_cell_voltage_number_ = min_cell_voltage_number;
|
SUB_SENSOR(min_temperature)
|
||||||
}
|
SUB_SENSOR(min_temperature_probe_number)
|
||||||
void set_max_temperature_sensor(sensor::Sensor *max_temperature) { max_temperature_ = max_temperature; }
|
SUB_SENSOR(remaining_capacity)
|
||||||
void set_max_temperature_probe_number_sensor(sensor::Sensor *max_temperature_probe_number) {
|
SUB_SENSOR(cells_number)
|
||||||
max_temperature_probe_number_ = max_temperature_probe_number;
|
SUB_SENSOR(temperature_1)
|
||||||
}
|
SUB_SENSOR(temperature_2)
|
||||||
void set_min_temperature_sensor(sensor::Sensor *min_temperature) { min_temperature_ = min_temperature; }
|
SUB_SENSOR(cell_1_voltage)
|
||||||
void set_min_temperature_probe_number_sensor(sensor::Sensor *min_temperature_probe_number) {
|
SUB_SENSOR(cell_2_voltage)
|
||||||
min_temperature_probe_number_ = min_temperature_probe_number;
|
SUB_SENSOR(cell_3_voltage)
|
||||||
}
|
SUB_SENSOR(cell_4_voltage)
|
||||||
void set_remaining_capacity_sensor(sensor::Sensor *remaining_capacity) { remaining_capacity_ = remaining_capacity; }
|
SUB_SENSOR(cell_5_voltage)
|
||||||
void set_cells_number_sensor(sensor::Sensor *cells_number) { cells_number_ = cells_number; }
|
SUB_SENSOR(cell_6_voltage)
|
||||||
void set_temperature_1_sensor(sensor::Sensor *temperature_1_sensor) { temperature_1_sensor_ = temperature_1_sensor; }
|
SUB_SENSOR(cell_7_voltage)
|
||||||
void set_temperature_2_sensor(sensor::Sensor *temperature_2_sensor) { temperature_2_sensor_ = temperature_2_sensor; }
|
SUB_SENSOR(cell_8_voltage)
|
||||||
void set_cell_1_voltage_sensor(sensor::Sensor *cell_1_voltage) { cell_1_voltage_ = cell_1_voltage; }
|
SUB_SENSOR(cell_9_voltage)
|
||||||
void set_cell_2_voltage_sensor(sensor::Sensor *cell_2_voltage) { cell_2_voltage_ = cell_2_voltage; }
|
SUB_SENSOR(cell_10_voltage)
|
||||||
void set_cell_3_voltage_sensor(sensor::Sensor *cell_3_voltage) { cell_3_voltage_ = cell_3_voltage; }
|
SUB_SENSOR(cell_11_voltage)
|
||||||
void set_cell_4_voltage_sensor(sensor::Sensor *cell_4_voltage) { cell_4_voltage_ = cell_4_voltage; }
|
SUB_SENSOR(cell_12_voltage)
|
||||||
void set_cell_5_voltage_sensor(sensor::Sensor *cell_5_voltage) { cell_5_voltage_ = cell_5_voltage; }
|
SUB_SENSOR(cell_13_voltage)
|
||||||
void set_cell_6_voltage_sensor(sensor::Sensor *cell_6_voltage) { cell_6_voltage_ = cell_6_voltage; }
|
SUB_SENSOR(cell_14_voltage)
|
||||||
void set_cell_7_voltage_sensor(sensor::Sensor *cell_7_voltage) { cell_7_voltage_ = cell_7_voltage; }
|
SUB_SENSOR(cell_15_voltage)
|
||||||
void set_cell_8_voltage_sensor(sensor::Sensor *cell_8_voltage) { cell_8_voltage_ = cell_8_voltage; }
|
SUB_SENSOR(cell_16_voltage)
|
||||||
void set_cell_9_voltage_sensor(sensor::Sensor *cell_9_voltage) { cell_9_voltage_ = cell_9_voltage; }
|
#endif
|
||||||
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
|
#ifdef USE_TEXT_SENSOR
|
||||||
void set_status_text_sensor(text_sensor::TextSensor *status_text_sensor) { status_text_sensor_ = status_text_sensor; }
|
SUB_TEXT_SENSOR(status)
|
||||||
// BINARY_SENSORS
|
#endif
|
||||||
void set_charging_mos_enabled_binary_sensor(binary_sensor::BinarySensor *charging_mos_enabled) {
|
|
||||||
charging_mos_enabled_ = charging_mos_enabled;
|
#ifdef USE_BINARY_SENSOR
|
||||||
}
|
SUB_BINARY_SENSOR(charging_mos_enabled)
|
||||||
void set_discharging_mos_enabled_binary_sensor(binary_sensor::BinarySensor *discharging_mos_enabled) {
|
SUB_BINARY_SENSOR(discharging_mos_enabled)
|
||||||
discharging_mos_enabled_ = discharging_mos_enabled;
|
#endif
|
||||||
}
|
|
||||||
|
|
||||||
void setup() override;
|
void setup() override;
|
||||||
void dump_config() override;
|
void dump_config() override;
|
||||||
void update() override;
|
void update() override;
|
||||||
|
void loop() override;
|
||||||
|
|
||||||
float get_setup_priority() const override;
|
float get_setup_priority() const override;
|
||||||
void set_address(uint8_t address) { this->addr_ = address; }
|
void set_address(uint8_t address) { this->addr_ = address; }
|
||||||
|
@ -79,42 +79,12 @@ class DalyBmsComponent : public PollingComponent, public uart::UARTDevice {
|
||||||
|
|
||||||
uint8_t addr_;
|
uint8_t addr_;
|
||||||
|
|
||||||
sensor::Sensor *voltage_sensor_{nullptr};
|
std::vector<uint8_t> data_;
|
||||||
sensor::Sensor *current_sensor_{nullptr};
|
bool receiving_{false};
|
||||||
sensor::Sensor *battery_level_sensor_{nullptr};
|
uint8_t data_count_;
|
||||||
sensor::Sensor *max_cell_voltage_{nullptr};
|
uint32_t last_transmission_{0};
|
||||||
sensor::Sensor *max_cell_voltage_number_{nullptr};
|
bool trigger_next_;
|
||||||
sensor::Sensor *min_cell_voltage_{nullptr};
|
uint8_t next_request_;
|
||||||
sensor::Sensor *min_cell_voltage_number_{nullptr};
|
|
||||||
sensor::Sensor *max_temperature_{nullptr};
|
|
||||||
sensor::Sensor *max_temperature_probe_number_{nullptr};
|
|
||||||
sensor::Sensor *min_temperature_{nullptr};
|
|
||||||
sensor::Sensor *min_temperature_probe_number_{nullptr};
|
|
||||||
sensor::Sensor *remaining_capacity_{nullptr};
|
|
||||||
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};
|
|
||||||
|
|
||||||
binary_sensor::BinarySensor *charging_mos_enabled_{nullptr};
|
|
||||||
binary_sensor::BinarySensor *discharging_mos_enabled_{nullptr};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace daly_bms
|
} // namespace daly_bms
|
||||||
|
|
|
@ -218,9 +218,8 @@ CONFIG_SCHEMA = cv.All(
|
||||||
|
|
||||||
|
|
||||||
async def setup_conf(config, key, hub):
|
async def setup_conf(config, key, hub):
|
||||||
if key in config:
|
if sensor_config := config.get(key):
|
||||||
conf = config[key]
|
sens = await sensor.new_sensor(sensor_config)
|
||||||
sens = await sensor.new_sensor(conf)
|
|
||||||
cg.add(getattr(hub, f"set_{key}_sensor")(sens))
|
cg.add(getattr(hub, f"set_{key}_sensor")(sens))
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -23,9 +23,8 @@ CONFIG_SCHEMA = cv.All(
|
||||||
|
|
||||||
|
|
||||||
async def setup_conf(config, key, hub):
|
async def setup_conf(config, key, hub):
|
||||||
if key in config:
|
if sensor_config := config.get(key):
|
||||||
conf = config[key]
|
sens = await text_sensor.new_text_sensor(sensor_config)
|
||||||
sens = await text_sensor.new_text_sensor(conf)
|
|
||||||
cg.add(getattr(hub, f"set_{key}_text_sensor")(sens))
|
cg.add(getattr(hub, f"set_{key}_text_sensor")(sens))
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue