9static const char *
const TAG =
"pzem004t";
30 if (!resp_opt.has_value())
32 auto resp = *resp_opt;
39 for (
int i = 0; i < 6; i++)
43 ESP_LOGV(TAG,
"PZEM004T invalid checksum! 0x%02X != 0x%02X", sum, resp[6]);
53 uint16_t int_voltage = (uint16_t(resp[1]) << 8) | (uint16_t(resp[2]) << 0);
54 float voltage = int_voltage + (resp[3] / 10.0f);
57 ESP_LOGD(TAG,
"Got Voltage %.1f V", voltage);
62 uint16_t int_current = (uint16_t(resp[1]) << 8) | (uint16_t(resp[2]) << 0);
63 float current = int_current + (resp[3] / 100.0f);
66 ESP_LOGD(TAG,
"Got Current %.2f A", current);
71 uint16_t power = (uint16_t(resp[1]) << 8) | (uint16_t(resp[2]) << 0);
74 ESP_LOGD(TAG,
"Got Power %u W", power);
83 ESP_LOGD(TAG,
"Got Energy %" PRIu32
" Wh", energy);
105 this->read_state_ =
state;
108 std::array<uint8_t, 7> data{};
116 for (
int i = 0; i < 6; i++)
120 this->read_state_ =
state;
123 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.