diff --git a/esphome/components/pulse_counter_ulp/pulse_counter_ulp_sensor.cpp b/esphome/components/pulse_counter_ulp/pulse_counter_ulp_sensor.cpp index c21f66b0f8..1919a5d0ce 100644 --- a/esphome/components/pulse_counter_ulp/pulse_counter_ulp_sensor.cpp +++ b/esphome/components/pulse_counter_ulp/pulse_counter_ulp_sensor.cpp @@ -135,12 +135,10 @@ void PulseCounterUlpSensor::dump_config() { void PulseCounterUlpSensor::update() { UlpProgram::state raw = this->storage_.pop_state(); - clock::time_point now; - std::chrono::duration> minutes; - now = clock::now(); - minutes = now - this->last_time_; + clock::time_point now = clock::now(); + auto interval = now - this->last_time_; if (this->last_time_ != clock::time_point{}) { - float value = raw.edge_count / minutes.count(); // pulses per minute + float value = std::chrono::minutes{1} * static_cast(raw.edge_count) / interval; // pulses per minute ESP_LOGD(TAG, "'%s': Retrieved counter: %0.2f pulses/min", this->get_name().c_str(), value); this->publish_state(value); }