mirror of
https://github.com/esphome/esphome.git
synced 2024-11-10 01:07:45 +01:00
Co-authored-by: Jerome <jerome992@internet.lu>
This commit is contained in:
parent
d98d6ff45f
commit
cd57469e06
1 changed files with 4 additions and 1 deletions
|
@ -33,7 +33,10 @@ void CTClampSensor::update() {
|
|||
|
||||
const float rms_ac_dc_squared = this->sample_squared_sum_ / this->num_samples_;
|
||||
const float rms_dc = this->sample_sum_ / this->num_samples_;
|
||||
const float rms_ac = std::sqrt(rms_ac_dc_squared - rms_dc * rms_dc);
|
||||
const float rms_ac_squared = rms_ac_dc_squared - rms_dc * rms_dc;
|
||||
float rms_ac = 0;
|
||||
if (rms_ac_squared > 0)
|
||||
rms_ac = std::sqrt(rms_ac_squared);
|
||||
ESP_LOGD(TAG, "'%s' - Raw AC Value: %.3fA after %d different samples (%d SPS)", this->name_.c_str(), rms_ac,
|
||||
this->num_samples_, 1000 * this->num_samples_ / this->sample_duration_);
|
||||
this->publish_state(rms_ac);
|
||||
|
|
Loading…
Reference in a new issue