ESPHome 2025.5.0
Loading...
Searching...
No Matches
bl0906.h
Go to the documentation of this file.
1#pragma once
8
9// https://www.belling.com.cn/media/file_object/bel_product/BL0906/datasheet/BL0906_V1.02_cn.pdf
10// https://www.belling.com.cn/media/file_object/bel_product/BL0906/guide/BL0906%20APP%20Note_V1.02.pdf
11
12namespace esphome {
13namespace bl0906 {
14
15struct DataPacket { // NOLINT(altera-struct-pack-align)
16 uint8_t l{0};
17 uint8_t m{0};
18 uint8_t h{0};
19 uint8_t checksum; // checksum
20 uint8_t address;
21} __attribute__((packed));
22
23struct ube24_t { // NOLINT(readability-identifier-naming,altera-struct-pack-align)
24 uint8_t l{0};
25 uint8_t m{0};
26 uint8_t h{0};
27} __attribute__((packed));
28
29struct sbe24_t { // NOLINT(readability-identifier-naming,altera-struct-pack-align)
30 uint8_t l{0};
31 uint8_t m{0};
32 int8_t h{0};
33} __attribute__((packed));
34
35template<typename... Ts> class ResetEnergyAction;
36
37class BL0906;
38
39using ActionCallbackFuncPtr = void (BL0906::*)();
40
42 SUB_SENSOR(voltage)
43 SUB_SENSOR(current_1)
44 SUB_SENSOR(current_2)
45 SUB_SENSOR(current_3)
46 SUB_SENSOR(current_4)
47 SUB_SENSOR(current_5)
48 SUB_SENSOR(current_6)
49 SUB_SENSOR(power_1)
50 SUB_SENSOR(power_2)
51 SUB_SENSOR(power_3)
52 SUB_SENSOR(power_4)
53 SUB_SENSOR(power_5)
54 SUB_SENSOR(power_6)
55 SUB_SENSOR(total_power)
56 SUB_SENSOR(energy_1)
57 SUB_SENSOR(energy_2)
58 SUB_SENSOR(energy_3)
59 SUB_SENSOR(energy_4)
60 SUB_SENSOR(energy_5)
61 SUB_SENSOR(energy_6)
62 SUB_SENSOR(total_energy)
63 SUB_SENSOR(frequency)
64 SUB_SENSOR(temperature)
65
66 public:
67 void loop() override;
68
69 void update() override;
70 void setup() override;
71 void dump_config() override;
72
73 protected:
74 template<typename... Ts> friend class ResetEnergyAction;
75
76 void reset_energy_();
77
78 void read_data_(uint8_t address, float reference, sensor::Sensor *sensor);
79
80 void bias_correction_(uint8_t address, float measurements, float correction);
81
82 uint8_t current_channel_{0};
84 void handle_actions_();
85
86 private:
87 std::vector<ActionCallbackFuncPtr> action_queue_{};
88};
89
90template<typename... Ts> class ResetEnergyAction : public Action<Ts...>, public Parented<BL0906> {
91 public:
92 void play(Ts... x) override { this->parent_->enqueue_action_(&BL0906::reset_energy_); }
93};
94
95} // namespace bl0906
96} // namespace esphome
uint8_t address
Definition bl0906.h:4
uint16_le_t frequency
Definition bl0942.h:6
virtual void loop()
This method will be called repeatedly.
Definition component.cpp:53
Helper class to easily give an object a parent of type T.
Definition helpers.h:538
This class simplifies creating components that periodically check a state.
Definition component.h:301
uint8_t current_channel_
Definition bl0906.h:82
void read_data_(uint8_t address, float reference, sensor::Sensor *sensor)
Definition bl0906.cpp:126
void bias_correction_(uint8_t address, float measurements, float correction)
Definition bl0906.cpp:185
size_t enqueue_action_(ActionCallbackFuncPtr function)
Definition bl0906.cpp:90
void play(Ts... x) override
Definition bl0906.h:92
Base-class for all sensors.
Definition sensor.h:57
void(BL0906::*)() ActionCallbackFuncPtr
Definition bl0906.h:39
esphome::bl0906::BL0906 __attribute__
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
uint16_t temperature
Definition sun_gtil2.cpp:12
uint16_t x
Definition tt21100.cpp:5