9static const char *
const TAG =
"pzem004t";
36 for (
int i = 0; i < 6; i++)
40 ESP_LOGV(TAG,
"PZEM004T invalid checksum! 0x%02X != 0x%02X", sum, resp[6]);
50 uint16_t int_voltage = (uint16_t(resp[1]) << 8) | (uint16_t(resp[2]) << 0);
51 float voltage = int_voltage + (resp[3] / 10.0f);
54 ESP_LOGD(TAG,
"Got Voltage %.1f V", voltage);
59 uint16_t int_current = (uint16_t(resp[1]) << 8) | (uint16_t(resp[2]) << 0);
60 float current = int_current + (resp[3] / 100.0f);
63 ESP_LOGD(TAG,
"Got Current %.2f A", current);
68 uint16_t power = (uint16_t(resp[1]) << 8) | (uint16_t(resp[2]) << 0);
71 ESP_LOGD(TAG,
"Got Power %u W", power);
77 uint32_t energy = (uint32_t(resp[1]) << 16) | (uint32_t(resp[2]) << 8) | (uint32_t(resp[3]));
80 ESP_LOGD(TAG,
"Got Energy %" PRIu32
" Wh", energy);
102 this->read_state_ =
state;
105 std::array<uint8_t, 7> data{};
113 for (
int i = 0; i < 6; i++)
117 this->read_state_ =
state;
120 ESP_LOGCONFIG(TAG,
"PZEM004T:");
uint32_t IRAM_ATTR HOT get_loop_component_start_time() const
Get the cached time in milliseconds from when the current component started its loop execution.
void dump_config() override
enum esphome::pzem004t::PZEM004T::PZEM004TReadState DONE
sensor::Sensor * energy_sensor_
sensor::Sensor * current_sensor_
sensor::Sensor * power_sensor_
void write_state_(PZEM004TReadState state)
sensor::Sensor * voltage_sensor_
void publish_state(float state)
Publish a new state to the front-end.
optional< std::array< uint8_t, N > > read_array()
void write_array(const uint8_t *data, size_t len)
Providing packet encoding functions for exchanging data with a remote host.
Application App
Global storage of Application pointer - only one Application can exist.