From 8677d477773a428f6ae2e37a46132c30d4d9a361 Mon Sep 17 00:00:00 2001 From: Otto Winter Date: Tue, 12 Nov 2019 21:44:20 +0100 Subject: [PATCH] Fix PZEM004T v2 (#846) Fixes https://github.com/esphome/issues/issues/817 --- esphome/components/pzem004t/pzem004t.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/esphome/components/pzem004t/pzem004t.cpp b/esphome/components/pzem004t/pzem004t.cpp index cbdc14f0d0..e2d832b019 100644 --- a/esphome/components/pzem004t/pzem004t.cpp +++ b/esphome/components/pzem004t/pzem004t.cpp @@ -8,7 +8,7 @@ static const char *TAG = "pzem004t"; void PZEM004T::loop() { const uint32_t now = millis(); - if (now - this->last_read_ > 500 && this->available()) { + if (now - this->last_read_ > 500 && this->available() < 7) { while (this->available()) this->read(); this->last_read_ = now; @@ -78,7 +78,7 @@ void PZEM004T::loop() { this->last_read_ = now; } } -void PZEM004T::update() { this->write_state_(SET_ADDRESS); } +void PZEM004T::update() { this->write_state_(READ_VOLTAGE); } void PZEM004T::write_state_(PZEM004T::PZEM004TReadState state) { if (state == DONE) { this->read_state_ = state;