ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
ina3221.h
Go to the documentation of this file.
1#pragma once
2
6
7namespace esphome::ina3221 {
8
9class INA3221Component final : public PollingComponent, public i2c::I2CDevice {
10#ifdef USE_INA3221_SUMMATION
11 SUB_SENSOR(sum_shunt_voltage)
12 SUB_SENSOR(sum_current)
13 SUB_SENSOR(sum_power)
14#endif
15
16 public:
17 void setup() override;
18 void dump_config() override;
19 void update() override;
20 void on_powerdown() override;
21
22 void set_bus_voltage_sensor(int channel, sensor::Sensor *obj) { this->channels_[channel].bus_voltage_sensor_ = obj; }
23 void set_shunt_voltage_sensor(int channel, sensor::Sensor *obj) {
24 this->channels_[channel].shunt_voltage_sensor_ = obj;
25 }
26 void set_current_sensor(int channel, sensor::Sensor *obj) { this->channels_[channel].current_sensor_ = obj; }
27 void set_power_sensor(int channel, sensor::Sensor *obj) { this->channels_[channel].power_sensor_ = obj; }
28 void set_shunt_resistance(int channel, float resistance_ohm);
30 void set_config_register(uint16_t config) { this->config_ = config; }
32 void set_single_shot_wait_ms(uint16_t wait_ms) { this->single_shot_wait_ms_ = wait_ms; }
33#ifdef USE_INA3221_ALERT_LIMITS
34 void set_warning_limit(int channel, uint16_t reg) { this->channels_[channel].warning_limit_ = reg; }
35 void set_critical_limit(int channel, uint16_t reg) { this->channels_[channel].critical_limit_ = reg; }
36#endif
37
38 protected:
39 void read_data_();
40
42 float shunt_resistance_{0.1f};
47#ifdef USE_INA3221_ALERT_LIMITS
48 // Alert limit register values; zero keeps the chip default, which never trips
49 uint16_t warning_limit_{0};
50 uint16_t critical_limit_{0};
51#endif
52
56 uint16_t config_{0};
58};
59
60} // namespace esphome::ina3221
virtual void setup()
Where the component's initialization should happen.
Definition component.cpp:84
This class simplifies creating components that periodically check a state.
Definition component.h:519
This Class provides the methods to read/write bytes from/to an i2c device.
Definition i2c.h:144
I2CRegister reg(uint8_t a_register)
calls the I2CRegister constructor
Definition i2c.h:164
struct esphome::ina3221::INA3221Component::INA3221Channel channels_[3]
Base-class for all sensors.
Definition sensor.h:47