ESPHome  2022.12.8
daly_bms.h
Go to the documentation of this file.
1 #pragma once
2 
8 
9 #include <vector>
10 
11 namespace esphome {
12 namespace daly_bms {
13 
15  public:
16  DalyBmsComponent() = default;
17 
18  // SENSORS
19  void set_voltage_sensor(sensor::Sensor *voltage_sensor) { voltage_sensor_ = voltage_sensor; }
20  void set_current_sensor(sensor::Sensor *current_sensor) { current_sensor_ = current_sensor; }
21  void set_battery_level_sensor(sensor::Sensor *battery_level_sensor) { battery_level_sensor_ = battery_level_sensor; }
22  void set_max_cell_voltage_sensor(sensor::Sensor *max_cell_voltage) { max_cell_voltage_ = max_cell_voltage; }
23  void set_max_cell_voltage_number_sensor(sensor::Sensor *max_cell_voltage_number) {
24  max_cell_voltage_number_ = max_cell_voltage_number;
25  }
26  void set_min_cell_voltage_sensor(sensor::Sensor *min_cell_voltage) { min_cell_voltage_ = min_cell_voltage; }
27  void set_min_cell_voltage_number_sensor(sensor::Sensor *min_cell_voltage_number) {
28  min_cell_voltage_number_ = min_cell_voltage_number;
29  }
30  void set_max_temperature_sensor(sensor::Sensor *max_temperature) { max_temperature_ = max_temperature; }
31  void set_max_temperature_probe_number_sensor(sensor::Sensor *max_temperature_probe_number) {
32  max_temperature_probe_number_ = max_temperature_probe_number;
33  }
34  void set_min_temperature_sensor(sensor::Sensor *min_temperature) { min_temperature_ = min_temperature; }
35  void set_min_temperature_probe_number_sensor(sensor::Sensor *min_temperature_probe_number) {
36  min_temperature_probe_number_ = min_temperature_probe_number;
37  }
38  void set_remaining_capacity_sensor(sensor::Sensor *remaining_capacity) { remaining_capacity_ = remaining_capacity; }
39  void set_cells_number_sensor(sensor::Sensor *cells_number) { cells_number_ = cells_number; }
40  void set_temperature_1_sensor(sensor::Sensor *temperature_1_sensor) { temperature_1_sensor_ = temperature_1_sensor; }
41  void set_temperature_2_sensor(sensor::Sensor *temperature_2_sensor) { temperature_2_sensor_ = temperature_2_sensor; }
42  void set_cell_1_voltage_sensor(sensor::Sensor *cell_1_voltage) { cell_1_voltage_ = cell_1_voltage; }
43  void set_cell_2_voltage_sensor(sensor::Sensor *cell_2_voltage) { cell_2_voltage_ = cell_2_voltage; }
44  void set_cell_3_voltage_sensor(sensor::Sensor *cell_3_voltage) { cell_3_voltage_ = cell_3_voltage; }
45  void set_cell_4_voltage_sensor(sensor::Sensor *cell_4_voltage) { cell_4_voltage_ = cell_4_voltage; }
46  void set_cell_5_voltage_sensor(sensor::Sensor *cell_5_voltage) { cell_5_voltage_ = cell_5_voltage; }
47  void set_cell_6_voltage_sensor(sensor::Sensor *cell_6_voltage) { cell_6_voltage_ = cell_6_voltage; }
48  void set_cell_7_voltage_sensor(sensor::Sensor *cell_7_voltage) { cell_7_voltage_ = cell_7_voltage; }
49  void set_cell_8_voltage_sensor(sensor::Sensor *cell_8_voltage) { cell_8_voltage_ = cell_8_voltage; }
50  void set_cell_9_voltage_sensor(sensor::Sensor *cell_9_voltage) { cell_9_voltage_ = cell_9_voltage; }
51  void set_cell_10_voltage_sensor(sensor::Sensor *cell_10_voltage) { cell_10_voltage_ = cell_10_voltage; }
52  void set_cell_11_voltage_sensor(sensor::Sensor *cell_11_voltage) { cell_11_voltage_ = cell_11_voltage; }
53  void set_cell_12_voltage_sensor(sensor::Sensor *cell_12_voltage) { cell_12_voltage_ = cell_12_voltage; }
54  void set_cell_13_voltage_sensor(sensor::Sensor *cell_13_voltage) { cell_13_voltage_ = cell_13_voltage; }
55  void set_cell_14_voltage_sensor(sensor::Sensor *cell_14_voltage) { cell_14_voltage_ = cell_14_voltage; }
56  void set_cell_15_voltage_sensor(sensor::Sensor *cell_15_voltage) { cell_15_voltage_ = cell_15_voltage; }
57  void set_cell_16_voltage_sensor(sensor::Sensor *cell_16_voltage) { cell_16_voltage_ = cell_16_voltage; }
58 
59  // TEXT_SENSORS
60  void set_status_text_sensor(text_sensor::TextSensor *status_text_sensor) { status_text_sensor_ = status_text_sensor; }
61  // BINARY_SENSORS
63  charging_mos_enabled_ = charging_mos_enabled;
64  }
66  discharging_mos_enabled_ = discharging_mos_enabled;
67  }
68 
69  void setup() override;
70  void dump_config() override;
71  void update() override;
72 
73  float get_setup_priority() const override;
74  void set_address(uint8_t address) { this->addr_ = address; }
75 
76  protected:
77  void request_data_(uint8_t data_id);
78  void decode_data_(std::vector<uint8_t> data);
79 
80  uint8_t addr_;
81 
113 
115 
118 };
119 
120 } // namespace daly_bms
121 } // namespace esphome
sensor::Sensor * cell_15_voltage_
Definition: daly_bms.h:111
void set_cell_3_voltage_sensor(sensor::Sensor *cell_3_voltage)
Definition: daly_bms.h:44
sensor::Sensor * min_temperature_probe_number_
Definition: daly_bms.h:92
void set_cell_16_voltage_sensor(sensor::Sensor *cell_16_voltage)
Definition: daly_bms.h:57
void set_max_cell_voltage_sensor(sensor::Sensor *max_cell_voltage)
Definition: daly_bms.h:22
sensor::Sensor * max_cell_voltage_number_
Definition: daly_bms.h:86
sensor::Sensor * remaining_capacity_
Definition: daly_bms.h:93
sensor::Sensor * temperature_2_sensor_
Definition: daly_bms.h:96
void set_cell_10_voltage_sensor(sensor::Sensor *cell_10_voltage)
Definition: daly_bms.h:51
sensor::Sensor * temperature_1_sensor_
Definition: daly_bms.h:95
sensor::Sensor * current_sensor_
Definition: daly_bms.h:83
void set_charging_mos_enabled_binary_sensor(binary_sensor::BinarySensor *charging_mos_enabled)
Definition: daly_bms.h:62
void set_cell_12_voltage_sensor(sensor::Sensor *cell_12_voltage)
Definition: daly_bms.h:53
sensor::Sensor * min_cell_voltage_
Definition: daly_bms.h:87
void set_address(uint8_t address)
Definition: daly_bms.h:74
void set_cell_4_voltage_sensor(sensor::Sensor *cell_4_voltage)
Definition: daly_bms.h:45
This class simplifies creating components that periodically check a state.
Definition: component.h:267
binary_sensor::BinarySensor * discharging_mos_enabled_
Definition: daly_bms.h:117
sensor::Sensor * cell_5_voltage_
Definition: daly_bms.h:101
sensor::Sensor * min_cell_voltage_number_
Definition: daly_bms.h:88
void set_temperature_1_sensor(sensor::Sensor *temperature_1_sensor)
Definition: daly_bms.h:40
void set_cell_1_voltage_sensor(sensor::Sensor *cell_1_voltage)
Definition: daly_bms.h:42
void set_voltage_sensor(sensor::Sensor *voltage_sensor)
Definition: daly_bms.h:19
sensor::Sensor * cell_6_voltage_
Definition: daly_bms.h:102
sensor::Sensor * cell_8_voltage_
Definition: daly_bms.h:104
sensor::Sensor * cell_11_voltage_
Definition: daly_bms.h:107
void set_cell_9_voltage_sensor(sensor::Sensor *cell_9_voltage)
Definition: daly_bms.h:50
void set_discharging_mos_enabled_binary_sensor(binary_sensor::BinarySensor *discharging_mos_enabled)
Definition: daly_bms.h:65
void set_max_temperature_probe_number_sensor(sensor::Sensor *max_temperature_probe_number)
Definition: daly_bms.h:31
void set_max_temperature_sensor(sensor::Sensor *max_temperature)
Definition: daly_bms.h:30
void request_data_(uint8_t data_id)
Definition: daly_bms.cpp:49
void set_cell_6_voltage_sensor(sensor::Sensor *cell_6_voltage)
Definition: daly_bms.h:47
sensor::Sensor * cell_10_voltage_
Definition: daly_bms.h:106
void set_cell_5_voltage_sensor(sensor::Sensor *cell_5_voltage)
Definition: daly_bms.h:46
sensor::Sensor * cell_16_voltage_
Definition: daly_bms.h:112
text_sensor::TextSensor * status_text_sensor_
Definition: daly_bms.h:114
void set_cell_7_voltage_sensor(sensor::Sensor *cell_7_voltage)
Definition: daly_bms.h:48
void decode_data_(std::vector< uint8_t > data)
Definition: daly_bms.cpp:71
sensor::Sensor * voltage_sensor_
Definition: daly_bms.h:82
sensor::Sensor * cell_4_voltage_
Definition: daly_bms.h:100
sensor::Sensor * min_temperature_
Definition: daly_bms.h:91
void set_min_temperature_probe_number_sensor(sensor::Sensor *min_temperature_probe_number)
Definition: daly_bms.h:35
sensor::Sensor * max_temperature_probe_number_
Definition: daly_bms.h:90
sensor::Sensor * cell_3_voltage_
Definition: daly_bms.h:99
sensor::Sensor * max_cell_voltage_
Definition: daly_bms.h:85
void set_min_cell_voltage_number_sensor(sensor::Sensor *min_cell_voltage_number)
Definition: daly_bms.h:27
sensor::Sensor * battery_level_sensor_
Definition: daly_bms.h:84
binary_sensor::BinarySensor * charging_mos_enabled_
Definition: daly_bms.h:116
void set_cell_8_voltage_sensor(sensor::Sensor *cell_8_voltage)
Definition: daly_bms.h:49
void set_min_temperature_sensor(sensor::Sensor *min_temperature)
Definition: daly_bms.h:34
sensor::Sensor * cell_9_voltage_
Definition: daly_bms.h:105
void set_cell_2_voltage_sensor(sensor::Sensor *cell_2_voltage)
Definition: daly_bms.h:43
sensor::Sensor * cell_2_voltage_
Definition: daly_bms.h:98
sensor::Sensor * cell_13_voltage_
Definition: daly_bms.h:109
void set_max_cell_voltage_number_sensor(sensor::Sensor *max_cell_voltage_number)
Definition: daly_bms.h:23
sensor::Sensor * cell_14_voltage_
Definition: daly_bms.h:110
void set_cells_number_sensor(sensor::Sensor *cells_number)
Definition: daly_bms.h:39
void set_cell_11_voltage_sensor(sensor::Sensor *cell_11_voltage)
Definition: daly_bms.h:52
sensor::Sensor * cells_number_
Definition: daly_bms.h:94
float get_setup_priority() const override
Definition: daly_bms.cpp:47
Definition: a4988.cpp:4
void set_current_sensor(sensor::Sensor *current_sensor)
Definition: daly_bms.h:20
Base class for all binary_sensor-type classes.
Definition: binary_sensor.h:28
void set_temperature_2_sensor(sensor::Sensor *temperature_2_sensor)
Definition: daly_bms.h:41
sensor::Sensor * cell_12_voltage_
Definition: daly_bms.h:108
Base-class for all sensors.
Definition: sensor.h:50
void set_cell_14_voltage_sensor(sensor::Sensor *cell_14_voltage)
Definition: daly_bms.h:55
void set_status_text_sensor(text_sensor::TextSensor *status_text_sensor)
Definition: daly_bms.h:60
void set_remaining_capacity_sensor(sensor::Sensor *remaining_capacity)
Definition: daly_bms.h:38
void set_min_cell_voltage_sensor(sensor::Sensor *min_cell_voltage)
Definition: daly_bms.h:26
sensor::Sensor * max_temperature_
Definition: daly_bms.h:89
void set_cell_15_voltage_sensor(sensor::Sensor *cell_15_voltage)
Definition: daly_bms.h:56
sensor::Sensor * cell_7_voltage_
Definition: daly_bms.h:103
sensor::Sensor * cell_1_voltage_
Definition: daly_bms.h:97
void set_battery_level_sensor(sensor::Sensor *battery_level_sensor)
Definition: daly_bms.h:21
void set_cell_13_voltage_sensor(sensor::Sensor *cell_13_voltage)
Definition: daly_bms.h:54