PulseCounter binary_sensor

This commit is contained in:
dianlight 2024-01-03 12:23:10 +01:00
parent a2e152ad12
commit 7bbb9b820e
2 changed files with 9 additions and 0 deletions

View File

@ -180,6 +180,13 @@ void PulseCounterSensor::update() {
ESP_LOGD(TAG, "'%s': Total : %" PRIu32 " pulses", this->get_name().c_str(), current_total_);
this->total_sensor_->publish_state(current_total_);
}
if (this->binary_sensor_ != nullptr) {
bool level = this->storage_.pin->digital_read();
ESP_LOGD(TAG, "'%s': Sending state %s", this->get_name().c_str(), ONOFF(level));
this->binary_sensor_->publish_state(level);
}
this->last_time_ = now;
}

View File

@ -69,6 +69,7 @@ class PulseCounterSensor : public sensor::Sensor, public PollingComponent {
void set_falling_edge_mode(PulseCounterCountMode mode) { storage_.falling_edge_mode = mode; }
void set_filter_us(uint32_t filter) { storage_.filter_us = filter; }
void set_total_sensor(sensor::Sensor *total_sensor) { total_sensor_ = total_sensor; }
void set_binary_sensor(sensor::Sensor *binary_sensor) { binary_sensor_ = binary_sensor; }
void set_total_pulses(uint32_t pulses);
@ -84,6 +85,7 @@ class PulseCounterSensor : public sensor::Sensor, public PollingComponent {
uint32_t last_time_{0};
uint32_t current_total_{0};
sensor::Sensor *total_sensor_{nullptr};
sensor::Sensor *binary_sensor_{nullptr};
};
} // namespace pulse_counter