Pulse Counter Sensor

Example Usage

// Basic
App.make_pulse_counter_sensor("Pulse Counter", 13);
// Unit conversion
auto pcnt_1 = App.make_pulse_counter_sensor("Pulse Counter 2", 13);
pcnt_1.pcnt->set_unit_of_measurement("kW");
pcnt_1.pcnt->clear_filters();
pcnt_1.pcnt->add_multiply_filter(0.06f); // convert from Wh pulse to kW

See Application::make_pulse_counter_sensor().

API Reference

class PulseCounterSensorComponent : public sensor::PollingSensorComponent, public sensor::PulseCounterBase

Pulse Counter - This is the sensor component for the ESP32 integrated pulse counter peripheral.

It offers 8 pulse counter units that can be setup in several ways to count pulses on a pin. Also allows for some simple filtering of short pulses using set_filter(), any pulse shorter than the value provided to that function will be discarded. The time is given in APB clock cycles, which usually amount to 12.5 ns per clock. Defaults to the max possible (about 13 ms). See https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/peripherals/pcnt.html for more information.

The pulse counter defaults to reporting a value of the measurement unit “pulses/min”. To modify this behavior, use filters in MQTTSensor.

Public Functions

PulseCounterSensorComponent(const std::string &name, GPIOPin *pin, uint32_t update_interval = 15000)

Construct the Pulse Counter instance with the provided pin and update interval.

The pulse counter unit will automatically be set and the pulse counter is set up to increment the counter on rising edges by default.

Parameters
  • pin: The pin.
  • update_interval: The update interval in ms.

void set_edge_mode(PulseCounterCountMode rising_edge_mode, PulseCounterCountMode falling_edge_mode)

Set the PulseCounterCountMode for the rising and falling edges. can be disable, increment and decrement.

void set_filter_us(uint32_t filter_us)
std::string unit_of_measurement()

Unit of measurement is “pulses/min”.

std::string icon()

Override this to set the Home Assistant icon for this sensor.

Return “” to disable this feature.

Return
The icon of this sensor, for example “mdi:battery”.

int8_t accuracy_decimals()

Return the accuracy in decimals for this sensor.

void setup()

Where the component’s initialization should happen.

Analogous to Arduino’s setup(). This method is guaranteed to only be called once. Defaults to doing nothing.

void update()
float get_setup_priority() const

priority of setup().

higher -> executed earlier

Defaults to 0.

Return
The setup priority of this component

void dump_config()