mirror of
https://github.com/esphome/esphome.git
synced 2024-11-23 15:38:11 +01:00
PulseCounter binary_sensor
This commit is contained in:
parent
a2e152ad12
commit
7bbb9b820e
2 changed files with 9 additions and 0 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue