ESPHome  2024.11.0
daly_bms.h
Go to the documentation of this file.
1 #pragma once
2 
4 #include "esphome/core/defines.h"
5 #ifdef USE_SENSOR
7 #endif
8 #ifdef USE_TEXT_SENSOR
10 #endif
11 #ifdef USE_BINARY_SENSOR
13 #endif
15 
16 #include <vector>
17 
18 namespace esphome {
19 namespace daly_bms {
20 
22  public:
23  DalyBmsComponent() = default;
24 
25 #ifdef USE_SENSOR
26  SUB_SENSOR(voltage)
27  SUB_SENSOR(current)
28  SUB_SENSOR(battery_level)
29  SUB_SENSOR(max_cell_voltage)
30  SUB_SENSOR(max_cell_voltage_number)
31  SUB_SENSOR(min_cell_voltage)
32  SUB_SENSOR(min_cell_voltage_number)
33  SUB_SENSOR(max_temperature)
34  SUB_SENSOR(max_temperature_probe_number)
35  SUB_SENSOR(min_temperature)
36  SUB_SENSOR(min_temperature_probe_number)
37  SUB_SENSOR(remaining_capacity)
38  SUB_SENSOR(cells_number)
39  SUB_SENSOR(temperature_1)
40  SUB_SENSOR(temperature_2)
41  SUB_SENSOR(cell_1_voltage)
42  SUB_SENSOR(cell_2_voltage)
43  SUB_SENSOR(cell_3_voltage)
44  SUB_SENSOR(cell_4_voltage)
45  SUB_SENSOR(cell_5_voltage)
46  SUB_SENSOR(cell_6_voltage)
47  SUB_SENSOR(cell_7_voltage)
48  SUB_SENSOR(cell_8_voltage)
49  SUB_SENSOR(cell_9_voltage)
50  SUB_SENSOR(cell_10_voltage)
51  SUB_SENSOR(cell_11_voltage)
52  SUB_SENSOR(cell_12_voltage)
53  SUB_SENSOR(cell_13_voltage)
54  SUB_SENSOR(cell_14_voltage)
55  SUB_SENSOR(cell_15_voltage)
56  SUB_SENSOR(cell_16_voltage)
57 #endif
58 
59 #ifdef USE_TEXT_SENSOR
60  SUB_TEXT_SENSOR(status)
61 #endif
62 
63 #ifdef USE_BINARY_SENSOR
64  SUB_BINARY_SENSOR(charging_mos_enabled)
65  SUB_BINARY_SENSOR(discharging_mos_enabled)
66 #endif
67 
68  void setup() override;
69  void dump_config() override;
70  void update() override;
71  void loop() 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 
82  std::vector<uint8_t> data_;
83  bool receiving_{false};
84  uint8_t data_count_;
85  uint32_t last_transmission_{0};
87  uint8_t next_request_;
88 };
89 
90 } // namespace daly_bms
91 } // namespace esphome
void set_address(uint8_t address)
Definition: daly_bms.h:74
This class simplifies creating components that periodically check a state.
Definition: component.h:283
void request_data_(uint8_t data_id)
Definition: daly_bms.cpp:107
virtual void setup()
Where the component&#39;s initialization should happen.
Definition: component.cpp:48
void decode_data_(std::vector< uint8_t > data)
Definition: daly_bms.cpp:131
std::vector< uint8_t > data_
Definition: daly_bms.h:82
uint8_t status
Definition: bl0942.h:74
float get_setup_priority() const override
Definition: daly_bms.cpp:105
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
uint8_t address
Definition: bl0906.h:211
SUB_SENSOR(voltage) SUB_SENSOR(current) SUB_SENSOR(battery_level) SUB_SENSOR(max_cell_voltage) SUB_SENSOR(max_cell_voltage_number) SUB_SENSOR(min_cell_voltage) SUB_SENSOR(min_cell_voltage_number) SUB_SENSOR(max_temperature) SUB_SENSOR(max_temperature_probe_number) SUB_SENSOR(min_temperature) SUB_SENSOR(min_temperature_probe_number) SUB_SENSOR(remaining_capacity) SUB_SENSOR(cells_number) SUB_SENSOR(temperature_1) SUB_SENSOR(temperature_2) SUB_SENSOR(cell_1_voltage) SUB_SENSOR(cell_2_voltage) SUB_SENSOR(cell_3_voltage) SUB_SENSOR(cell_4_voltage) SUB_SENSOR(cell_5_voltage) SUB_SENSOR(cell_6_voltage) SUB_SENSOR(cell_7_voltage) SUB_SENSOR(cell_8_voltage) SUB_SENSOR(cell_9_voltage) SUB_SENSOR(cell_10_voltage) SUB_SENSOR(cell_11_voltage) SUB_SENSOR(cell_12_voltage) SUB_SENSOR(cell_13_voltage) SUB_SENSOR(cell_14_voltage) SUB_SENSOR(cell_15_voltage) SUB_SENSOR(cell_16_voltage) SUB_TEXT_SENSOR(status) SUB_BINARY_SENSOR(charging_mos_enabled) SUB_BINARY_SENSOR(discharging_mos_enabled) void setup() override