7static const char *
const TAG =
"ina3221";
9static const uint8_t INA3221_REGISTER_CONFIG = 0x00;
10static const uint8_t INA3221_REGISTER_CHANNEL1_SHUNT_VOLTAGE = 0x01;
11static const uint8_t INA3221_REGISTER_CHANNEL1_BUS_VOLTAGE = 0x02;
12static const uint8_t INA3221_REGISTER_CHANNEL2_SHUNT_VOLTAGE = 0x03;
13static const uint8_t INA3221_REGISTER_CHANNEL2_BUS_VOLTAGE = 0x04;
14static const uint8_t INA3221_REGISTER_CHANNEL3_SHUNT_VOLTAGE = 0x05;
15static const uint8_t INA3221_REGISTER_CHANNEL3_BUS_VOLTAGE = 0x06;
35 config |= 0b0100000000000000;
38 config |= 0b0010000000000000;
41 config |= 0b0001000000000000;
44 config |= 0b0000000000000000;
46 config |= 0b0000000111000000;
48 config |= 0b0000000000111000;
50 config |= 0b0000000000000111;
58 ESP_LOGCONFIG(TAG,
"INA3221:");
61 ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
63 LOG_UPDATE_INTERVAL(
this);
65 LOG_SENSOR(
" ",
"Bus Voltage #1", this->
channels_[0].bus_voltage_sensor_);
66 LOG_SENSOR(
" ",
"Shunt Voltage #1", this->
channels_[0].shunt_voltage_sensor_);
67 LOG_SENSOR(
" ",
"Current #1", this->
channels_[0].current_sensor_);
68 LOG_SENSOR(
" ",
"Power #1", this->
channels_[0].power_sensor_);
69 LOG_SENSOR(
" ",
"Bus Voltage #2", this->
channels_[1].bus_voltage_sensor_);
70 LOG_SENSOR(
" ",
"Shunt Voltage #2", this->
channels_[1].shunt_voltage_sensor_);
71 LOG_SENSOR(
" ",
"Current #2", this->
channels_[1].current_sensor_);
72 LOG_SENSOR(
" ",
"Power #2", this->
channels_[1].power_sensor_);
73 LOG_SENSOR(
" ",
"Bus Voltage #3", this->
channels_[2].bus_voltage_sensor_);
74 LOG_SENSOR(
" ",
"Shunt Voltage #3", this->
channels_[2].shunt_voltage_sensor_);
75 LOG_SENSOR(
" ",
"Current #3", this->
channels_[2].current_sensor_);
76 LOG_SENSOR(
" ",
"Power #3", this->
channels_[2].power_sensor_);
84 for (
int i = 0; i < 3; i++) {
86 float bus_voltage_v = NAN, current_a = NAN;
93 bus_voltage_v = int16_t(
raw) / 1000.0f;
102 const float shunt_voltage_v = int16_t(
raw) * 40.0f / 8.0f / 1000000.0f;
124 return this->shunt_voltage_sensor_ !=
nullptr || this->current_sensor_ !=
nullptr || this->power_sensor_ !=
nullptr;
127 return this->bus_voltage_sensor_ !=
nullptr || this->power_sensor_ !=
nullptr;
void mark_failed()
Mark this component as failed.
void status_set_warning()
bool read_byte_16(uint8_t a_register, uint16_t *data)
bool write_byte_16(uint8_t a_register, uint16_t data) const
struct esphome::ina3221::INA3221Component::INA3221Channel channels_[3]
void set_shunt_resistance(int channel, float resistance_ohm)
void dump_config() override
void publish_state(float state)
Publish a new state to the front-end.
uint8_t ina3221_shunt_voltage_register(int channel)
uint8_t ina3221_bus_voltage_register(int channel)
void HOT delay(uint32_t ms)
sensor::Sensor * shunt_voltage_sensor_
bool should_measure_shunt_voltage()
sensor::Sensor * bus_voltage_sensor_
bool should_measure_bus_voltage()
sensor::Sensor * power_sensor_
sensor::Sensor * current_sensor_