9void PulseMeterSensor::set_total_pulses(
uint32_t pulses) {
14void PulseMeterSensor::setup() {
35void PulseMeterSensor::loop() {
72 if (!this->
peeked_edge_ && state.last_rising_edge_us_ !=
state.last_detected_edge_us_ &&
73 now -
state.last_rising_edge_us_ >= this->filter_us_) {
75 state.last_detected_edge_us_ =
state.last_rising_edge_us_;
80 if (
state.count_ > 0) {
82 if (this->total_sensor_ !=
nullptr) {
85 this->total_sensor_->publish_state(total);
96 float pulse_width_us = delta_us /
float(
state.count_);
97 ESP_LOGV(TAG,
"New pulse, delta: %" PRIu32
" µs, count: %" PRIu32
", width: %.5f µs", delta_us,
state.count_,
113 if (time_since_valid_edge_us > this->
timeout_us_) {
115 ESP_LOGD(TAG,
"No pulse detected for %" PRIu32
"s, assuming 0 pulses/min",
116 time_since_valid_edge_us / 1000000);
126void PulseMeterSensor::dump_config() {
127 LOG_SENSOR(
"",
"Pulse Meter",
this);
128 LOG_PIN(
" Pin: ", this->
pin_);
130 ESP_LOGCONFIG(TAG,
" Filtering rising edges less than %" PRIu32
" µs apart", this->
filter_us_);
132 ESP_LOGCONFIG(TAG,
" Filtering pulses shorter than %" PRIu32
" µs", this->
filter_us_);
134 ESP_LOGCONFIG(TAG,
" Assuming 0 pulses/min after not receiving a pulse for %" PRIu32
"s",
145 if ((now - edge_state.last_sent_edge_us_) >= sensor->
filter_us_) {
146 edge_state.last_sent_edge_us_ = now;
147 state.last_detected_edge_us_ = now;
148 state.last_rising_edge_us_ = now;
168 pulse_state.latched_ =
false;
170 pulse_state.latched_ =
true;
171 state.last_detected_edge_us_ = pulse_state.last_intr_;
178 state.last_rising_edge_us_ = !pulse_state.latched_ && pin_val ? now :
state.last_detected_edge_us_;
180 pulse_state.last_intr_ = now;